1.下载
1 |
wget https://pypi.python.org/packages/44/80/d28047d120bfcc8158b4e41127706731ee6a3419c661e0a858fb0e7c4b2d/supervisor-3.3.0.tar.gz |
2.解压
1 |
tar zxf supervisor-3.3.0.tar.gz |
3.进入目录
1 |
cd supervisor-3.3.0 |
4.安装
1 |
python setup.py install |
5.检查是否安装成功
登陆python控制台输入import supervisor 查看是否能成功加载
6.生成配置文件(supervisord.conf):
我的是安在了/usr/local/python27/bin/下,进入该目录,可以执行以下命令
1 |
./echo_supervisord_conf > /etc/supervisord.conf |
启动supervisor
1 |
./supervisord -c /etc/supervisord.conf |
查看状态
1 |
./supervisorctl status |
启动全部./supervisorctl start all
停止全部./supervisorctl stop all
以下是样例配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
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/supervisord.log ; (main log file;default $CWD/supervisord.log) pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid) childlogdir=/var/log/ ; ('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 |
1 2 3 4 5 6 7 8 9 |
server.conf [program:server] command=python /opt/archive_server/server.py autorstart=true redirect_stderr=true stdout_logfile=/mnt/log/supervisord_server.log directory=/tmp user=root priority=1 |
其中,进程server定义在[program:server]中,command是命令,directory是进程的当前目录,user是进程运行的用户身份。
重启supervisor,让配置文件生效,然后运行命令supervisorctl启动进程:
1 |
# supervisorctl start app |
停止进程:
1 |
# supervisorctl stop app |
如果要在命令行中使用变量,就需要自己先编写一个shell脚本:
1 2 |
#!/bin/sh /usr/bin/gunicorn -w `grep -c ^processor /proc/cpuinfo` wsgiapp:application |
然后,加上x权限,再把command指向该shell脚本即可。
supervisor还有许多选项,默认的autorestart为unexpected(异常退出),具体请参考supervisor文档。