Supervisor守护进程虚拟环境部署Django

1.安装supervisor

# 如果提示没有可用软件包就执行 sudo yum -y install epel-release
sudo yum install supervisor

2.编辑配置文件

# 先备份
cp /etc/supervisord.conf /etc/supervisord.conf_bak
# 编辑
vim /etc/supervisord.conf
# command 是执行的命令,由于python环境在虚拟环境中,需要指定完全路径
# directory 项目目录
# 下面是停止命令时杀死进程.如果不填写,可能会导致手动停止后,启动program错误
# stopasgroup=true
# stopsignal=QUIT
[program:django]
command=/home/faster/.virtualenvs/fasterenv/bin/python manage.py runserver 0.0.0.0:8000
directory=/home/faster/FasterRunner
stopasgroup=true
stopsignal=QUIT
user=faster
autostart=true
autorestart=true
stderr_logfile=/home/faster/err.log
stdout_logfile=/home/faster/out.log

3.启动 supervisord

sudo supervisord -c  /etc/supervisord.conf

4.常用命令

# 注意非root用户,需要加上sudo
# 重启supervisor
supervisorctl reload
# 启动名字为django的program 
supervisorctl start django
# 停止名字为django的program 
supervisorctl stop django
# 查看名字为django的program 状态
supervisorctl status django
# 查看所有program的状态
supervisorctl status all
# 停止所有program
supervisorctl stop all

5.错误排查

解决unix:///tmp/supervisor.sock no such file的问题1
解决unix:///tmp/supervisor.sock no such file的问题2
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

解决方法:
find / -name supervisor.sock
unlink /name/supervisor.sock
unix:///var/run/supervisor.sock no such file
sudo touch /var/run/supervisor.sock
sudo chmod 777 /var/run/supervisor.sock
sudo service supervisor restart

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.
unlink /var/run/supervisor/supervisor.sock

6.开机启动

  • 检查是否开机启动systemctl is-enabled supervisord
  • 开机启动设置systemctl enabled supervisord
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容