supervisor安装请参考flask应用部署——安装环境
生成配置文件
# cd /etc # mkdir -p supervisord/conf.d # echo_supervisord_conf > /etc/supervisord/supervisord.conf
修改supervisord.conf
# vim supervisord.conf # G直接跳到最后一行
取消下面注释并修改
[include] files = /etc/supervisord/conf.d/*.ini
ok,现在可以在/etc/supervisord/conf.d/目录下创建配置文件了
# vim honmaple.com.ini
输入以下内容
# 进程的名字 [program:website] # 命令 command=/home/www/honmaple.com/venv/bin/gunicorn run:app -c /home/www/honmaple.com/gunicorn.conf # 网站目录 directory=/home/www/honmaple.com # 进程所属用户 user=www # 自动重启设置。 autostart=true autorestart=true # 日志存放位置。 stdout_logfile=/home/www/honmaple.com/logs/gunicorn_supervisor.log
上面有几处需要注意的地方
创建新用户www
# useradd www # passwd www #设置密码 # su - www $ cd $ mkdir -p honmaple.com/logs
建立虚拟环境(honmaple.com/目录下)
$ virtualenv-3.4 venv $ . venv/bin/activate
gunicorn配置
# gunicorn.conf workers = 4 bind = '127.0.0.1:8000'
简单的web应用
#run.py from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello World!' if __name__ == '__main__': app.run()
加载supervisor配置
# supervisord -c /etc/supervisord/supervisord.conf # supervisorctl -c /etc/supervisord/supervisord.conf reload
supervisor遇到的问题
提示
Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting supervisord. For help, use /usr/bin/supervisord -h ...fail!
解决办法
# unlink /tmp/supervisor.sock
提示
error: <class 'socket.error'>, [Errno 111] Connection refused: file: /usr/lib64/python2.6/socket.py line: 567
解决办法
# supervisord -c /etc/supervisord/supervisord.conf # supervisorctl -c /etc/supervisord/supervisord.conf reload
提示
ERROR (no such process),请仔细查看配置文件是否有误