系统环境: CentOS7
supervisor版本:supervisor-3.1.4-1.el7.noarch
安装:
1
|
yum -y
install
supervisor
|
启动服务:
1
|
supervisord -c
/etc/supervisord
.conf
|
用systemctl管理supervisord服务
进入目录 /usr/lib/systemd/system/,增加文件 supervisord.service,来使得机器启动的时候启动supervisor,文件内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
# supervisord service for systemd (CentOS 7.0+)
# by ET-CS (https://github.com/ET-CS)
[Unit]
Description=Supervisor daemon
[Service]
Type=forking
ExecStart=
/usr/bin/supervisord
-c
/etc/supervisord
.conf
ExecStop=
/usr/bin/supervisorctl
$OPTIONS
shutdown
ExecReload=
/usr/bin/supervisorctl
$OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
|
激活开机启动命令
1
|
systemctl
enable
supervisord.service
|
启动supervisor进程
1
|
systemctl start supervisord.service
|
关闭supervisor进程
1
|
systemctl stop supervisord.service
|
如果修改了supervisor.service文件,可以通过reload命令来重新加载配置文件
1
|
systemctl reload supervisord.service
|
使用superviosr管理其他服务
下面是以supervisor管理.Net Core程序为例写的一个配置文件
进入/etc/supervisord.d/创建一个以.ini结尾的文件,内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[program:Fastel.InvoiceService]
##Fastel.InvoiceService是服务名称
command
=dotnet Fastel.InvoiceService.dll --ENVIRONMENT Release
##启动服务需要执行的命令
directory=
/opt/Apps/Fastel
.InvoiceService
/latest/packages
##在哪个目录下执行启动服务的命令
user=user1
##以user1用户启动Fastel.InvoiceService服务
stdout_logfile=
/opt/Apps/Fastel
.InvoiceService
/logs/stdout
.log
##标准输出日志路径
stderr_logfile=
/opt/Apps/Fastel
.InvoiceService
/logs/err
.log
##错误日志路径
autostart=
true
##改服务随supervisor服务启动而启动
autorestart=
true
##服务stop后自动重启
#startsecs=5 ##子进程启动多少秒之后,此时状态如果是running,则我们认为启动成功了。默认值为1,非必须设置
#priority=1
#stopasgroup=true
#killasgroup=true
|
supervisorctl 命令管理服务
1
|
supervisorctl status
|
查看正在守候的所有服务状态
1
|
supervisorctl update
|
更新或者修改/etc/supervisord.d/下面的服务配置文件后,执行此命令重新加载配置
1
|
supervisorctl reload
|
重启supervisor中所有程序
1
|
supervisorctl restart all
|
重启supervisor中所有程序
1
|
supervisorctl restart service_name
|
重启指定的服务
1
|
supervisorctl stop all
|
停止所有服务
配置文件解释:
本文转自 曾哥最爱 51CTO博客,原文链接:http://blog.51cto.com/zengestudy/2052794,如需转载请自行联系原作者