我能够使用 Python 3.8 进行设置。不要使用ubuntu提供的supervisor
我正在为我的项目使用 virtualenv,并添加了 require.txt
supervisor==4.2.0
检查目录 /var/log/supervisord 是否存在。如果没有,则创建此目录。它将用于主管 sock 文件和日志
检查 /etc/supervisor/supervisord.conf 文件是否存在。如果没有,则创建具有以下内容的文件
[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 中创建文件
例如我有 celery-worker.conf
[program:celeryworkerdemo]
command=/home/ubuntu/venv/bin/celery -A celeryworkerdemo worker -l debug
directory=/home/ubuntu/celeryworkerdemo/
user=ubuntu
numprocs=1
stdout_logfile=/home/ubuntu/logs/celerylogs/celeryworkerdemo_worker.log
stderr_logfile=/home/ubuntu/logs/celerylogs/celeryworkerdemo_worker_err.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 600
killasgroup=true
priority=998
完成后,运行以下命令
sudo systemctl daemon-reload
sudo systemctl enable supervisord && sudo systemctl start supervisors
运行以下命令查看状态
sudo systemctl status supervisord