Ubuntu 下使 supervisord 随系统启动

https://github.com/Supervisor/initscripts 下载 initscript,注意根据当前机器 supervisor 的安装情况和 supervisor.conf 的配置情况调整 ubuntu initscript。

例如,我的 supervisord 和 supervisorctrl 分别为,

$ which supervisord 
/usr/local/bin/supervisord
$ which supervisorctl 
/usr/local/bin/supervisorctl

则调整 initscript 如下,

...
. /lib/lsb/init-functions PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/local/bin/supervisord SUPERVISORCTL=/usr/local/bin/supervisorctl NAME=supervisord DESC=supervisor test -x $DAEMON || exit 0
...

我的 supervisord.conf 在 /etc 目录下,并且其中配置的 logfile 和 pid 都在 /tmp 下,所以调整 initscript 如下,

...
test -x $DAEMON || exit 0 LOGDIR=/tmp PIDFILE=/tmp/$NAME.pid DODTIME=5 # Time to wait for the server to die, in seconds # If this value is set too low you might not # let some servers to die gracefully and # restart will not work # Include supervisor defaults if available if [ -f /etc/default/supervisor ] ; then . /etc/default/supervisor fi DAEMON_OPTS="-c /etc/supervisord.conf $DAEMON_OPTS" set -e running_pid()
...

 

然后将调整后的 initscript 文件拷贝到 /etc/init.d 目录下,并重命名为 supervisord

$ sudo cp ubuntu /etc/init.d/supervisord

然后,为其增加可执行权限,

$ sudo chmod a+x /etc/init.d/supervisord

 然后,schedule it,

$ sudo update-rc.d supervisord defaults

然后,重新启动服务,

$ sudo service supervisord stop
$ sudo service supervisord start

 

当 /etc/init.d/supervisord 配置有改变时,需要首先,

$ sudo systemctl daemon-reload

然后再重启服务,

$ sudo service supervisord stop
$ sudo service supervisord start

 

注:当随系统启动 superisord 后,supervisorctl 必须 sudo 执行,

$ supervisorctl status
error: <class PermissionError>, [Errno 13] Permission denied: file: /usr/local/lib/python3.6/site-packages/supervisor/xmlrpc.py line: 560
rescure@ThinkCentre:~$ sudo supervisorctl status
[sudo] password for rescure: 
wk_1                             RUNNING   pid 1373, uptime 0:24:49
wk_chamber_1                     RUNNING   pid 1374, uptime 0:24:49
wk_chamber_2                     RUNNING   pid 1376, uptime 0:24:49

 

(完)

 

Ubuntu 下使 supervisord 随系统启动

上一篇:linux shell命令之getopts


下一篇:Linux系统编程13_CoreDump