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
minfds=65535
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, 就容易产生迷惑行为
使用supervisor启动的程序莫名其妙有了打开文件数限制 #
起了一个go程序结果http请求给限制到了4096, 根本不够用哈 设置如下参数可以设置新值(需要设置在supervisor配置中,而非supervisor守护的app中)
[supervisord]
minfds=8192
问题链接: Github
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
。
工作路径 #
[Service]
WorkingDirectory=/path/to/your/working/directory # 工作目录