【Linux】Supervisor—开机自启服务

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: 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

八个大柚子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值