Supervisor requires Python 2.4 or later but does not work on any version of Python 3 不支持python 3
pip2 install supervisor #pip 安装包
mkdir -p /etc/supervisor/conf.d
echo_supervisord_conf >/etc/supervisor/supervisord.conf
#创建配置文件
sed -i 's/;.*//;/^$/ d' /etc/supervisor/supervisord.conf
#去多余配置...
grep include /etc/supervisor/supervisord.conf || cat >> /etc/supervisor/supervisord.conf <<EOF
[include]
files = /etc/supervisor/conf.d/*.conf
EOF
supervisord -c /etc/supervisor/supervisord.conf
#启动
pkill supervisord
#关闭服务
vi /etc/supervisor/supervisord.conf
[inet_http_server]
port=0.0.0.0:9000
username=admin ; 用户名
password=super ; 密码
vi /etc/supervisor/conf.d/all.conf
[program:test]
command=python /tmp/test.py
autostart=true
autorestart=true
redirect_stderr=true
;如果为true,则stderr的日志会被写入stdout日志文件中
stdout_logfile= /tmp/supervisorall.log
cat /tmp/test.py
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import time
while(True):
# 3秒
time.sleep(1)
# 打开文件
f = open("/tmp/test.txt", "a")
print ("文件名为: ", f.name)
str = time.ctime() + "\n"
f.write( str )
# 关闭文件
f.close()
被守护的程序需要运行在前台
yum install gunicorn
[program:wsgi]
directory = /django/blog
command = gunicorn --worker-class=gevent mysite.wsgi:application --bind 127.0.0.1:9001 --log-level info --access-logfile /tmp/wsgi.log
autorestart = true
autostart = true
startsecs = 5 ; consider success if not fail in 5 sec
startretries = 3
redirect_stderr = true ; 如果为true,则stderr的日志会被写入stdout日志文件中
stdout_logfile_maxbytes = 20MB
stdout_logfile_backups = 20
stdout_logfile = /tmp/supervisor-wsgi.log