Linux进程守护,supervisor安装及使用

Lan
Lan
2020-08-08 / 0 评论 / 723 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2020年08月08日,已超过1368天没有更新,若内容或图片失效,请留言反馈。

用Linux挂一些Python脚本啥的就离不开进程守护这个东西了,然后了解到supervisor似乎还不错,在网上经过一番折腾及搜索,于是在此总结一下。

Supervisor安装及配置

这里我演示的系统是:CentOS Linux release 7.7.1908 (Core)

image.png

一、使用yum安装supervisor

yum install supervisor

遇到下图,输入y即可。

image.png

安装完成:

image.png

二、设置开机启动

systemctl enable supervisord.service

image.png

四、编辑配置文件

进入到etc目录,就找到看到supervisord.conf这个文件了

编辑该文件(咳咳,宝塔面板真香)

files改成放配置文件的文件夹,默认就好

image.png然后我们在进入supervisord.d文件夹。

image.png

五、添加,配置ini文件

在里面新建文件,后缀为之前配置文件中的ini即可。

这个就是用来存放监控配置的相关信息了

[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 #输出日志文件
配置实例
[program:future_price_depth_new.py]
command=python /bot/mkr/future_price_depth_new.py 注意intergal_util.py用python3启动 [command=python3 /bot/mkr/future_price_depth_new.py]
directory=/bot/mkr/
user=root
stopsignal=INT
autostart=true
autorestart=true
startsecs=3
stderr_logfile=/bot/log/future_price_depth_new.err.log
stdout_logfile=/bot/log/future_price_depth_new.out.log

六、启动

supervisord   -c /etc/supervisor/supervisord.conf

-c 表示启动自己之前创建的配置文件的supervisor 后面跟着的就是路径

image.png

基本使用指令

supervisord   -c supervisor.conf                     通过配置文件启动supervisor

supervisorctl -c supervisor.conf status              查看状态

supervisorctl -c supervisor.conf reload              重新载入配置文件

supervisorctl -c supervisor.conf start [all]|[x]     启动所有/指定的程序进程

supervisorctl -c supervisor.conf stop [all]|[x]      关闭所有/指定的程序进程

输入supervisorctl进入命令行工具

image.png

因为我这台服务器暂不需要挂东西,所以我切换到我挂了东西的服务器(这是废话,忽略即可)

image.png

这里我有两个conf(因为我将配置文件中的ini改成了conf,所以后缀是conf)文件,所以会显示有两个任务

image.png

可以通过下述指令操作任务:

image.png

supervisorctl status:查看所有进程的状态

supervisorctl stop es:停止es

supervisorctl start es:启动es

supervisorctl restart es: 重启es

supervisorctl update :配置文件修改后可以使用该命令加载新的配置

supervisorctl reload: 重新启动配置中的所有程序


0

评论 (0)

取消