问题描述
需要设置一个自有服务能以服务的方式启动,例如一个名称为mertrics-server的服务能通过命令service metrics-server start的方式启动,对配置过程进行简单记录。并且设置开机自启动
步骤
① 首先明确metrics-server服务为于/opt目录下,其中启动脚本位置为
/opt/metrics-server/bin/start.sh
② metrics-server服务停止脚本位置为
/opt/metrics-server/bin/stop.sh
③ 在/etc/init.d/中创建一个metrics-server,并添加内容
cat > /etc/init.d/metrics-server << EOF
#!/bin/bash
# chkconfig: - 85 15
#description: agent is the itsm base thing
case "\$1" in
start)
echo -n "starting metrics-server"
nohup /opt/metrics-server/bin/start.sh &
echo " OK "
;;
stop)
echo -n "shutdown metrics-server:"
nohup /opt/metrics-server/bin/stop.sh &
echo "OK"
;;
restart)
\$0 stop
\$0 start
;;
*)
echo "Usage: start|stop|restart"
exit 1
esac
exit 0
EOF
④ 赋予权限
chmod +x /etc/init.d/metrics-server
⑤ 设置开机启动
chkconfig --add metrics-server
chkconfig --level 23456 metrics-server on