配置metersphere开机自启
目的:由于在实际测试中,可能经常会出现断电等原因导致服务器异常,那么当服务器恢复时,我们希望第一时间恢复测试环境,而有时可能维护人员并不在公司或者正在处理其他事时,开机自动启动服务就显得非常重要。
1.设置开机自启动docker服务
systemctl enable docker
![](https://img-blog.csdnimg.cn/3a31ee54e96b479f90cc1f1dcb84ccf4.png#pic_center)
2.进入路径/etc/init.d/ ,创建文件metersphere(赋予权限777,很重要,如果没有执行权限,开机不会执行)
cd /etc/init.d
vi metersphere
![](https://img-blog.csdnimg.cn/c0314afcfd054604acce57e8c478b77b.png#pic_center)
编辑文件内容:
注意脚本的第二行与第三行是需要加上的
其中第二行 chkconfig: 2345 10 90 的含义为:
2345是默认启动级别 , 10是启动优先级,90是停止优先级,优先级范围是0-100,数字越大,优先级越低
#!/bin/bash
# chkconfig: 2345 10 90
# description: MeterSphere service auto start
function startMeterSphere
{
msctl reload
}
function stopMeterSphere
{
msctl stop
}
function restartMeterSphere
{
stopMeterSphere
startMeterSphere
}
function statusMeterSphere
{
msctl status
}
export HOSTNAME=$HOSTNAME
case "$1" in
start)
startMeterSphere
;;
stop)
stopMeterSphere
;;
restart)
restartMeterSphere
;;
status)
statusMeterSphere
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
;;
esac
3.将服务添加至自启动列表
将metersphere服务加到chkconifg列表:
#自启动打开
chkconfig metersphere on
#自启动关闭
# chkconfig metersphere off
执行成功后,查看metersphere服务是否加入自启动列表
chkconifg --list
![](https://img-blog.csdnimg.cn/a7b4815c8d9b4a5ea0218d1dec9355e7.png#pic_center)
如果metersphere出现在列表中说明添加成功
4.验证
执行reboot重启服务器,等待一分钟,发现metersphere自启动已经生效