supervisor 重启_.Net core 守护进程配置(supervisor)

1、介绍supervisor

Supervisor是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统。它可以很方便的监听、启动、停止、重启一个或多个进程。用Supervisor管理的进程,当一个进程意外被杀死,supervisort监听到进程死后,会自动将它重新拉起,很方便的做到进程自动恢复的功能,不再需要自己写shell脚本来控制。

2、安装环境

# 安装 python环境
yum install python-setuptools
# 安装 Supervisor
easy_install supervisor

3、配置Supervisor

# 新建配置目录命令:
mkdir /etc/supervisor
#生成supervisor的初始化配置文件 :
echo_supervisord_conf > /etc/supervisor/supervisord.conf

编辑配置supervisord.conf

vim supervisord.conf

主要是打开网络访问、默认启动配置目录2f5c2c9c29c20498239c8adbee324ed3.png

902fe2268ad5bf1e31ebded8580b9884.png

# 创建配置目录
mkdir /etc/supervisor/conf.d
# 进入目录
cd conf.d

#创建一个WebApplication1.conf配置
vi WebApplication1.conf
# 创建程序启动配置
# 进程名称
[program:WebApplication1]
# 执行命令
command=dotnet WebApplication1.dll
# 执行目录
directory=/root/aspnetcoreapi
# 掉线是否自动重启
autorestart=true
# 日志信息
stderr_logfile=/var/log/WebApplication1.err.log
stdout_logfile=/var/log/WebApplication1.out.log
# 环境.Net core
environment=ASPNETCORE_ENVIRONMENT=Production
# 执行用户
user=root
stopsignal=INT

4、启动Supervisor

# 启动Supervisor
supervisord -c /etc/supervisor/supervisord.conf
#查看状态
supervisorctl status

d12dad0261e5c833d7710581d1a2e748.png

5、bash终端控制

#启动Supervisor
supervisord -c /etc/supervisor/supervisord.conf
# 查看状态
supervisorctl status
# 停止某个服务
supervisorctl stop WebApplication1
# 开始某个服务
supervisorctl start WebApplication1
# 重启某个服务
supervisorctl restart WebApplication1
# 重启Supervisor
supervisorctl reload
# 修改Supervisor
supervisorctl update

6、将supervisor配置为开机自启动服务

# 编辑服务文件
vim /usr/lib/systemd/system/supervisord.service
# 内容
[Unit]
Description=Supervisor
[Service]
Type=forking
PIDFile=/var/run/supervisord.pid
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
# 保存退出 启动服务
systemctl enable supervisord
# 查看启动状态 返回enabled成功
systemctl is-enabled supervisord

#成功之后,就可以使用如下命令管理supervisor服务了
# 停止
systemctl stop supervisord
# 启动
systemctl start supervisord
# 状态
systemctl status supervisord
# 重载
systemctl reload supervisord
# 重启
systemctl restart supervisord

我们最后也可以看到我们将进程杀死之后马上会启动一个新的进程启动程序a92c463407429af30d0580c9e5456b03.png

最后我们可以通过我们配置的网络地址访问了,可以看到所有的程序方便管理

6e6cb007fd8d061f3fe012847de83431.png

出处:

https://www.cnblogs.com/chenxi001/archive/2020/09/04/13614831.html

版权申明:本文来源于网友收集或网友提供,如果有侵权,请转告版主或者留言,本公众号立即删除。

ebae3bfa7c74e5b09f27c169b535b896.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值