centos7设置开机自启动supervisor程序

vps · 2016-09-25 · 35 人浏览

centos7是打算放弃/etc/rc.local了。

本来想开机启动一个脚本,命令写入了rc.local,也给了权限,但就是不起作用。
于是决定安装supervisor来守护进程并实现开机启动,简单记录下操作步骤。

一、安装supervisor

安装 pip 包管理器(如果没安装的话):
$  yum install python-pip
安装 supervisor :
$ pip install supervisor
创建 supervisor 配置文件
# 输出至 supervisor 的默认配置路径
$ echo_supervisord_conf > /etc/supervisord.conf
运行 supervisor 服务
$ supervisord
配置 supervisor 守护进程
$ vim /etc/supervisord.conf
在文件尾部添加如下内容并酌情修改:
[program:ssrun]
command = /root/scripts/run.sh
user = root
autostart = true
autorestart = true
重启 supervisor 服务以加载配置
$ killall -HUP supervisord

二、设置开机启动supervisor

新建开机启动服务
$ vim  /lib/systemd/system/supervisord.service
在supervisord.service中添加以下内容:
# supervisord service for systemd (CentOS 7.0+) # by ET-CS (https://github.com/ET-CS) [Unit] Description=Supervisor daemon[Service] Type=forking ExecStart=/usr/bin/supervisord ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown ExecReload=/usr/bin/supervisorctl $OPTIONS reload KillMode=process Restart=on-failure RestartSec=42s[Install] WantedBy=multi-user.target
修改/etc/supervisord.conf配置文件:
#vim /etc/supervisrod.conf nodaemon=false 改成true
将服务脚本添加到systemctl自启动服务:
$  systemctl enable supervisord.service
重启系统测试开机启动。
vps
  1. 神父 2016-09-26

    看不懂看不懂看不懂不开心

    1. wonse (作者)  2016-09-26
      @神父

      看不懂不要紧,能用就行了。。。

Theme Jasmine by Kent Liao