Supervisor使用文档
目录
文章目录
一些命令解释
supervisor:要安装的软件的名称。
supervisord:装好supervisor软件后,supervisord用于启动supervisor服务。
supervisorctl:用于管理supervisor配置文件中program。
一、安装Supervisor
yum install epel-release
yum install supervisor #推荐使用yum安装(pip安装需要自行建立文件夹)
二、配置 Supervisor
Supervisor 的配置文件为:/etc/supervisord.conf
Supervisor 所管理的应用的配置文件放在 /etc/supervisord.d/ 目录中,这个目录可以在 supervisord.conf 中配置。
启动 Supervisor
安装 Supervisor 后,在 /usr/lib/systemd/system/ 目录中会有一个 supervisord.service 文件,内容如下:
[Unit]
Description=Process Monitoring and Control Daemon
After=rc-local.service nss-user-lookup.target
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
PIDFile=/var/run/supervisord.pid #新增项
ExecStop=/bin/supervisorctl shutdown #新增项 关闭所有程序命令
ExecReload=/bin/supervisorctl reload #新增项 重启所有程序命令
KillMode=process #新增项 未知
Restart=on-failure #新增项
RestartSec=42s #新增项
[Install]
WantedBy=multi-user.target
启动服务
systemctl enable supervisord
查看是否启动
systemctl is-enabled supervisord
enabled
相关管理supervisor服务
systemctl stop supervisord#停止supervisor服务
systemctl start supervisord#启动supervisor服务
systemctl status supervisord#查看supervisor服务状态
systemctl reload supervisord#刷新supervisor服务配置文件
systemctl restart supervisord#重启supervisor服务
supervisor服务无法启动时
unlink /var/run/supervisor/supervisor.sock
三、. 应用配置
Supervisor 管理应用的进程,需要对每个应用进行配置。在 /etc/supervisor.d 中创建 helloworld.ini,每个应用对应一个配置文件即可。
单个程序配置文件示例
[program:helloworld] ;程序的名称
command = dotnet HelloWorld.dll ;执行的命令
directory = /root/www/ ;命令执行的目录
environment = ASPNETCORE__ENVIRONMENT=Production ;环境变量
user = root ;执行进程的用户
stopsignal = INT
autostart = true ;是否自动启动
autorestart = true ;是否自动重启
startsecs = 1 ;自动重启间隔
stderr_logfile = /var/log/helloworld.err.log ;标准错误日志
stdout_logfile = /var/log/helloworld.out.log ;标准输出日志