conf files in /etc/supervisor/conf.d/
Version
Supervisor is installed by apt, and it's version is:
sudo supervisord --version
4.1.0
Conf files
There are Django projects, FastAPI projects, Celery beat and worker in the cloud server
- Django Project
- /etc/supervisor/conf.d/myproject.conf
[program:myproject]
environment =
APP_SECRET=asdf234asdf234dafasdf2342adsf,
SECRET_KEY="4+k*s7#1w3d#l2rg@5lajy4*asf(sasdf]sf}"
command=/home/ubuntu/coding/myproject/gunicorn_start.sh --reload
stdout_logfile=/home/ubuntu/coding/myproject/supervisor.log
directory=/home/ubuntu/coding/myproject
user=ubuntu
numprocs=1
autostart=true
startsecs=10
autorestart=true
startretried=3
redirect_stderr=true
stdout_logfile_backups=20
stdout_logfile_maxbytes=20MB
- /home/ubuntu/myproject/gunicorn_start.sh
#! /bin/bash
PORT=5920
BASE="/home/"
FULL_PATH=`realpath .`
PROJECT=${FULL_PATH##*/}
HOME_PATH=`realpath ../..`
USER=${HOME_PATH#$BASE}
DIR=/home/$USER/coding/$PROJECT
WORKERS=2
BIND=127.0.0.1:$PORT
DJANGO_SETTINGS_MODULE=$PROJECT.settings
DJANGO_WSGI_MODULE=$PROJECT.wsgi
LOG_LEVEL=info
cd $DIR
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
exec poetry run gunicorn ${DJANGO_WSGI_MODULE} \
--workers $WORKERS \
--user=$USER \
--bind=$BIND \
--log-level $LOG_LEVEL\
--access-logfile '-'\
--access-logformat '[%(h)s] "%(r)s" %(s)s %(L)s "%(f)s"' \
$*
注:使用gunicorn_start.sh可以简化supervisor中的command配置
- poetry
pip install pipx --user
pipx install poetry
export PATH=$PATH:$HOME/.local/bin
sudo ln -s /usr/bin/poetry `which poetry`
- FastAPI Project
[program:myapi]
command=poetry run gunicorn main:app --workers 1 --worker-class uvicorn.workers.UvicornWorker --bind 127.0.0.1:9817 --reload
directory=/home/ubuntu/coding/myapi
stdout_logfile=/home/ubuntu/coding/myapi/supervisor.log
user=ubuntu
numprocs=1
autostart=true
startsecs=10
autorestart=true
startretried=3
redirect_stderr=true
stdout_logfile_maxbytes=20MB
stdout_logfile_backups=20
注:uvicorn要用gunicorn来挂载,否则有可能导致CPU和内存占用过多
- Celery worker
[program:myprojectcelery]
command=/usr/bin/poetry run celery -A myproject worker -l info --concurrency=8
directory=/home/ubuntu/coding/myproject
stdout_logfile=/home/ubuntu/coding/myproject/celery.log
numprocs=1
autostart=true
startsecs=10
autorestart=true
startretried=3
user=ubuntu
redirect_stderr=true
stdout_logfile_maxbytes=20MB
stdout_logfile_backups=20
- Celery beat
[program:myprojectbeat]
command=/usr/bin/poetry run celery -A myproject beat
directory=/home/ubuntu/coding/myproject
numprocs=1
autostart=true
startsecs=10
autorestart=true
startretried=3
user=ubuntu
redirect_stderr=true
stdout_logfile=/home/ubuntu/coding/myproject/celerybeat.log
stdout_logfile_maxbytes=20MB
stdout_logfile_backups=20
标签:supervisor,--,Some,myproject,demos,ubuntu,home,logfile,true
From: https://www.cnblogs.com/waketzheng/p/17466669.html