安装命令:
apt-get install supervisor
安装成功后,会在/etc/supervisor目录下,生成supervisord.conf配置文件。
supervisord.conf示例配置:
; supervisor config file
[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod=0700 ; sockef file mode (default 0700)
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)
; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves.
[include]
files = /etc/supervisor/conf.d/*.conf
进程配置会读取/etc/supervisor/conf.d目录下的*.conf配置文件,我们在此目录下创建一个goyoubbs.conf进程配置文件:
[program:goyoubbs]
directory=/www/wwwroot/iduyao.cn
command=/www/wwwroot/iduyao.cn/goyoubbs ;建议使用前面的绝对路径。使用./goyoubbs 好像提示错误
autostart=true
autorestart=true
startretries=10
redirect_stderr=true
stdout_logfile=/www/wwwroot/iduyao.cn/iduyao.cn.log
需要注意的是,如果不是root账号,需要对这些目录进行权限设置,要不然会报一些错误(一定要在 root 账号下进行配置,要不然一系列权限引起的问题)。
$ sudo chmod 777 /var/run
$ sudo chmod 777 /etc/supervisor
接着就可以启动 Supervisord 了;
重启supervisor,让配置文件生效,然后启动goyoubbs进程:
supervisorctl reload
supervisorctl start goyoubbs
附:supervisorctl 常用命令和说明
1、supervisorctl stop program_name 停止某个进程
2、supervisorctl start program_name 启动某个进程
3、supervisorctl restart program_name 重启某个进程
4、supervisorctl stop all 停止全部进程
5、supervisorctl reload 载入最新的配置文件,停止原有进程并按新的配置启动、管理所有进程
6、supervisorctl update 根据最新的配置文件,启动新配置或有改动的进程,配置没有改动的进程不会受影响而重启