前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Linux进程守护,supervisor安装及使用

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

作者头像
SingYi
发布2022-07-14 14:19:48
2.4K0
发布2022-07-14 14:19:48
举报
文章被收录于专栏:Lan小站Lan小站

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

Supervisor安装及配置

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

image.png
image.png

一、使用yum安装supervisor

yum install supervisor

遇到下图,输入y即可。

image.png
image.png

安装完成:

image.png
image.png

二、设置开机启动

systemctl enable supervisord.service

image.png
image.png

四、编辑配置文件

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

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

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

image.png
image.png

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

image.png
image.png

五、添加,配置ini文件

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

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

代码语言:javascript
复制
[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 #输出日志文件
代码语言:javascript
复制
配置实例
[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
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

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

image.png
image.png

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

image.png
image.png

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

image.png
image.png

supervisorctl status:查看所有进程的状态 supervisorctl stop es:停止es supervisorctl start es:启动es supervisorctl restart es: 重启es supervisorctl update :配置文件修改后可以使用该命令加载新的配置 supervisorctl reload: 重新启动配置中的所有程序

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Supervisor安装及配置
    • 一、使用yum安装supervisor
      • 二、设置开机启动
        • 四、编辑配置文件
          • 五、添加,配置ini文件
            • 六、启动
            • 基本使用指令
            相关产品与服务
            命令行工具
            腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档