supervisor

supervisord #

安装 #

pip install supervisor
echo_supervisord_conf
echo_supervisord_conf > /etc/supervisord.conf 
echo -e "[include]\nfiles = /etc/supervisor/conf.d/*.conf" >> /etc/supervisord.conf

mkdir -p /var/log/test
mkdir -p /etc/supervisor/conf.d/
echo -e "[program:test]
command=/data/apps/test/.venv/bin/python test.py
directory=/data/apps/test/src/
user=root
autostart=true
autorestart=true
stopasgroup=true
stderr_logfile=/var/log/test/test.err.log
stderr_logfile_maxbytes=1000MB
stderr_logfile_backups=10
stdout_logfile=/var/log/test/test.out.log
stdout_logfile_maxbytes=1000MB
stdout_logfile_backups=10" > /etc/supervisor/conf.d/test.conf

supervisord
supervisorctl update

问题 #

supervisorctl status http://localhost:9001 refused connection 问题 #

  • 首次安装, 只pip install后直接使用很可能是没有配置文件… 写入配置后启动supervisord就好了

多安装问题 #

使用pip安装和apt安装的 supervisor 使用的不同路径的配置文件, 然后系统里就会跑两个supervisor, 就容易产生迷惑行为

systemd #

文件路径: /etc/systemd/system/{service_name}.service

frpc示例 #

[Unit]
Description=Frp Client Service
After=sshd.service

[Service]
Type=simple
User={用户}
Restart=on-failure
RestartSec=200s
ExecStart=/{path}/frp/frpc -c /{path}/frp/frpc.ini
ExecReload=/{path}/frp/frpc reload -c /{path}/frp/frpc.ini
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target

生效命令 #

systemctl daemon-reload
systemctl enable frpc.service
systemctl start frpc.service
systemctl status frpc.service

服务日志查看 #

journalctl -u {server_name}.service

手动指定 #

[Service]
StandardOutput=file:/var/log/my-service.log
StandardError=file:/var/log/my-service.err

这种情况下,服务的输出将存储在指定的文件中,而不是 journal