守护进程管理工具 supervisor (待完善)

参考地址

https://www.cnblogs.com/toutou/p/supervisor.html

 

 

[root@cxh ~]# yum install python-setuptools
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package python-setuptools-0.9.8-7.el7.noarch already installed and latest version
Nothing to do


[root@cxh ~]# easy_install supervisor
Searching for supervisor
Reading http://mirrors.aliyun.com/pypi/simple/supervisor/
Downloading http://mirrors.aliyun.com/pypi/packages/11/35/eab03782aaf70d87303b21a67c345b953d3b59d4e3971a568c51e523f5c0/supervisor-4.2.1.tar.gz#sha256=c479c875853e9c013d1fa73e529fd2165ff1ecaecc7e82810ba57e7362ae984d
Best match: supervisor 4.2.1
Processing supervisor-4.2.1.tar.gz
Writing /tmp/easy_install-iwp1na/supervisor-4.2.1/setup.cfg
Running supervisor-4.2.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-iwp1na/supervisor-4.2.1/egg-dist-tmp-eI3sNe
warning: no previously-included files matching '*' found under directory 'docs/.build'
creating /usr/lib/python2.7/site-packages/supervisor-4.2.1-py2.7.egg
Extracting supervisor-4.2.1-py2.7.egg to /usr/lib/python2.7/site-packages
Adding supervisor 4.2.1 to easy-install.pth file
Installing echo_supervisord_conf script to /usr/bin
Installing pidproxy script to /usr/bin
Installing supervisorctl script to /usr/bin
Installing supervisord script to /usr/bin

Installed /usr/lib/python2.7/site-packages/supervisor-4.2.1-py2.7.egg
Processing dependencies for supervisor
Finished processing dependencies for supervisor

[root@cxh ~]# mkdir /etc/supervisor


[root@cxh ~]# echo_supervisord_conf > /etc/supervisor/supervisord.conf

然后查看路径下的supervisord.conf。在文件尾部添加如下配置。

;conf.d 为配置表目录的文件夹,需要手动创建
[include]
files = conf.d/*.conf

为你的程序创建一个.conf文件,放在目录"/etc/supervisor/conf.d/"下。

[program:MGToastServer] ;程序名称,终端控制时需要的标识
command=dotnet MGToastServer.dll ; 运行程序的命令
directory=/root/文档/toastServer/ ; 命令执行的目录
autorestart=true ; 程序意外退出是否自动重启
stderr_logfile=/var/log/MGToastServer.err.log ; 错误日志文件
stdout_logfile=/var/log/MGToastServer.out.log ; 输出日志文件
environment=ASPNETCORE_ENVIRONMENT=Production ; 进程环境变量
user=root ; 进程执行的用户身份
stopsignal=INT

[root@cxh ~]# cd /etc/supervisor
[root@cxh supervisor]# ls
supervisord.conf
[root@cxh supervisor]# mkdir conf.d
[root@cxh supervisor]# ls
conf.d  supervisord.conf
[root@cxh supervisor]# cd conf.d
[root@cxh conf.d]# vim .conf
[root@cxh conf.d]# supervisord -c /etc/supervisor/supervisord.conf

成功
[root@cxh conf.d]# ps -ef | grep MGToastServer
root      6252  6108  0 12:14 pts/0    00:00:00 grep --color=auto MGToastServer

ps 如果服务已启动,修改配置文件可用“supervisorctl reload”命令来使其生效

 

 

配置Supervisor开机启动

a) 新建一个“supervisord.service”文件

# dservice 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/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

b) 将文件拷贝至"/usr/lib/systemd/system/supervisord.service"

c) 执行命令

systemctl enable supervisord

 

d) 执行命令来验证是否为开机启动

systemctl is-enabled supervisord

常用的相关管理命令

supervisorctl restart <application name> ;重启指定应用
supervisorctl stop <application name> ;停止指定应用
supervisorctl start <application name> ;启动指定应用
supervisorctl restart all ;重启所有应用
supervisorctl stop all ;停止所有应用
supervisorctl start all ;启动所有应用
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值