当前位置:网站首页 / Linux / 正文

Ubuntu/CentOS使用Supervisor管理进程

时间:2018年06月28日 | 作者 : liuhui | 分类 : Linux | 浏览: 5686次 | 评论 0

阿里云限量代金券 | 此广告位出租25元/月

1.安装supervisor

#pip  
pip install supervisor  

#ubuntu  
sudo apt-get install supervisor  

#centos (可能需要先安装epel源) 
yum install epel-release
yum -y install supervisor

2.启动

安装完后如supervisor没启动,可以使用如下,手动启动

#启动supervisor  
/usr/bin/supervisord -c /etc/supervisord.conf  
或者
supervisord -c /etc/supervisord.conf

进入 cd /etc 目录 找到supervisord.conf 配置文件和supervisord.d 文件夹,编辑supervisord.conf文件,拉到最底部我们可以看到
2.png

files = supervisord.d/*.ini 这句代码说明它会加载supervisord.d文件夹中的所有.ini配置文件

3.添加开机自启动

#创建supervisord.service  
vi /usr/lib/systemd/system/supervisord.service  
  
#supervisord.service文件内容  
[Unit]  
Description=Supervisor  
  
[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

激活开机启动

#激活开机启动  systemctl enable supervisord.service
  
#如修改了supervisord.service配置文件需重新加载  
systemctl daemon-reload

各种开机自启动脚本:https://github.com/Supervisor/initscripts

4.创建一个配置文件

[program:DeployLinux]   #DeployLinux  为程序的名称
command=dotnet DeployLinux.dll #需要执行的命令
directory=/home/publish #命令执行的目录
environment=ASPNETCORE__ENVIRONMENT=Production #环境变量
user=root #用户
stopsignal=INT 
autostart=true #是否自启动
autorestart=true #是否自动重启
startsecs=3 #自动重启时间间隔(s)
stderr_logfile=/var/log/ossoffical.err.log #错误日志文件
stdout_logfile=/var/log/ossoffical.out.log #输出日志文件
#加载配置文件  
supervisorctl reread  

#启动spring-app  
supervisorctl start spring-app  

#查看进程状态  
supervisorctl status


推荐您阅读更多有关于“”的文章

猜你喜欢

网站分类
关注电脑博士
友情链接

分享:

支付宝

微信