Supervisor—开机自启服务
首先感谢阅读,作者是在工作中学习与积累,每一个笔记都是心得和积累,希望可以和大家一起交流学习。
大家有需要也可查看我的另一篇关于Linux自启动的文章,也是我之前使用的Systemd服务,仅供大家参考这两种自启动方式的优缺点
链接: 【Linux】 Systemd—开机自启服务
要解决的问题
在机器上部署自己编写的服务时候,我们可以使用Supervisor作为进程检活工具,用来自动重启服务。 但是当机器重启后,Supervisor却不能自动重启,那么谁来解决这个问题呢?
答案就是linux的service。
总体思路
编写一个脚本,然后把它放在/etc/init.d这个目录下,再用service + 脚本名字 运行即可。如果是要开机自动启动那就得用chkconfig命令了。
话不多说,上手做吧!
安装过程
增加service配置
[root@j7-evm init.d]# vim /etc/init.d/supervisor
#内容:
#!/bin/bash
#
# supervisord This scripts turns supervisord on
#
# Author: Mike McGrath <mmcgrath@redhat.com> (based off yumupdatesd)
#
# chkconfig: - 95 04
#
# description: supervisor is a process control utility. It has a web based
# xmlrpc interface as well as a few other nifty features.
# processname: supervisord
# config: /etc/supervisor/supervisord.conf
# pidfile: /var/run/supervisord.pid
#
# source function library
. /etc/rc.d/init.d/functions
RETVAL=0
start() {
echo -n $"Starting supervisord: "
daemon "/usr/bin/supervisord -c /etc/supervisord.conf"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/supervisord
}
stop() {
echo -n $"Stopping supervisord: "
killproc supervisord
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/supervisord
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|force-reload|reload)
restart
;;
condrestart)
[ -f /var/lock/subsys/supervisord ] && restart
;;
status)
status supervisord
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
exit 1
esac
exit $RETVAL
设置为可执行
[root@j7-evm init.d]# chmod +x /etc/init.d/supervisor
设置开机启动
- service这个命令往往是即时生效,不用开关机,但是重启后服务会回到默认状态。
- chkconfig是用于把服务加到开机自动启动列表里,只要启动它,就能自动启动,重启后永久生效即:
[root@j7-evm init.d]# chkconfig supervisor on
启停命令
[root@j7-evm init.d]# service supervisor start
Starting Supervisor: Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting supervisord.
For help, use /usr/bin/supervisord -h
[root@j7-evm init.d]# service supervisor stop
Stopping Supervisor: Shut down
[root@j7-evm init.d]# service supervisor start
Starting Supervisor: