使用supervisor守护进程部署服务
2024-01-29 本文已影响0人
barriers
1 supervisor部署项目
1安装supervisor
sudo apt install python3-pip
sudo apt install supervisor
2初始化配置文件
echo_supervisord_conf | sudo tee /etc//supervisord.conf
1.1修改supervisor.conf配置文件
修改/etc/supervisor/supervisor.conf文件
; supervisor config file
[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)
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[inet_http_server] ; inet (TCP) server disabled by default
port=0.0.0.0:9001 ; (ip_address:port specifier, *:port for all iface)
username=admin ; (default is no username (open server))
password=123456 ; (default is no password (open server))
[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
; 将自定义的文件夹添加到下面一行
files = /etc/supervisor/config.d/*.ini
修改log权限
sudo chmod -R 777 /var/log/supervisor/supervisord.log
sudo supervisord
1.2编写配置文件
vim supervisor_task.ini
chmod -x supervisor_task.ini
[program:traffic-performance-http]
user=main
environment=
pgDB="traffic",
pgHost="127.0.0.1",
pgPort=5432,
pgPwd="**",
pgUser="traffic"
command=/bin/bash -c "cd ~/Desktop/traffic&&~/env/traffic/bin/gunicorn -c gun.py traffic_per_http:app"
directory=~/Desktop/traffic/
autorestart=true
startsecs=10
stderr_logfile=~/Desktop/traffic/log/traffic-performance-http.log
stdout_logfile=~/Desktop/traffic/log/traffic-performance-http.log
daemon=true
startretries=100
stopasgroup=true
killasgroup=true
自动重启
[program:word2pdf-tusd]
user=huyifei
environment=
host="0.0.0.0",
port=8080,
uploadDir="./data"
command=/bin/bash -c "cd /home/huyifei/plugin/tusd_linux_amd64&&./tusd"
directory=/home/huyifei/plugin/tusd_linux_amd64/
autorestart=true
autostart=true
startsecs=10
stderr_logfile=/home/huyifei/plugin/tusd_linux_amd64/tusd-err.log
stdout_logfile=/home/huyifei/plugin/tusd_linux_amd64/tusd-out.log
daemon=true
startretries=100
stopasgroup=true
killasgroup=true
一些常用命令
sudo chmod -x /etc/supervisor/config.d/traffic.ini
sudo supervisord -c /etc/supervisor/supervisord.conf
sudo supervisorctl stop traffic-performance-http
sudo supervisorctl start traffic-performance-http
sudo supervisorctl status
sudo supervisorctl stop all
sudo supervisorctl