supervisor安装及配置说明

1、安装

sudo apt-get install supervisor  # ubuntu下安装,推荐使用apt-get
pip install supervisor  # centos下安装,使用pip安装

2、卸载

sudo apt-get remove supervisor  # ubuntu下卸载
pip uninstall supervisor  # centos下卸载

3、查看是否安装成功(有配置信息输出则安装成功)

echo_supervisord_conf

4、创建配置文件夹

mkdir /etc/supervisor
mkdir /etc/supervisor/conf.d

5、配置文件

5.1 生成配置文件(方法1)

sudo echo_supervisord_conf > /etc/supervisor/supervisord.conf

备注:supervisord.conf中最后一行需要根据子进程配置文件的设置对应修改

5.2 直接复制以下文件(方法2)

; supervisor config file

[unix_http_server]
file=/cetc/data1/apps/sup/supervisor.sock   ; (the path to the socket file)
chmod=0700                       ; sockef file mode (default 0700)

[supervisord]
logfile=/cetc/data1/apps/sup/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/cetc/data1/apps/sup/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/cetc/data1/apps/sup/supervisor            ; ('AUTO' child log dir, default $TEMP)

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///cetc/data1/apps/sup/supervisor.sock ; use a unix:// URL  for a unix socket

; The [include] section can just contain the "files" setting.  This
; setting can list multiple files (separated by whitespace or
; newlines).  It can also contain wildcards.  The filenames are
; interpreted as relative to this file.  Included files *cannot*
; include files themselves.

[include]
files = /etc/supervisor/conf.d/*.conf

备注:如果复制上述代码,记得修改file、logfile、pidfile、childlogdir、serverurl、files等相关路径。

6、子进程配置文件说明

根据需管理的项目编写一个配置文件,放在/etc/supervisor/conf.d目录下便于多项目下supervisor的管理,如任意定义一个和脚本相关的项目名称的选项组(/etc/supervisor/conf.d/test.conf):

[program:nlp_platform]  # 项目名
directory=/home/cd063/apps/nlp_platform  # 项目路径
command=sudo bash /home/cd063/apps/nlp_platform/startup_fastapi.sh startmaster  # 脚本执行命令
autostart=true  # supervisor启动的时候是否随着同时启动,默认True
autorestart=false  # 当程序exit的时候,这个program不会自动重启,默认unexpected,设置子进程挂掉后自动重启的情况,有三个选项,false,unexpected和true。如果为false的时候,无论什么情况下,都不会被重新启动,如果为unexpected,只有当进程的退出码不在下面的exitcodes里面定义的
startsecs=10  # 这个选项是子进程启动多少秒之后,此时状态如果是running,则我们认为启动成功了。默认值为1
startretries=3
stderr_logfile=/home/cd063/apps/nlp_platform/logs/supervisor.err.log  # 日志输出 (可输出到项目的logs中方便查看)
stdout_logfile=/home/cd063/apps/nlp_platform/logs/supervisor.out.log  # 日志输出 (可输出到项目的logs中方便查看)

备注:如果项目需要指定python环境运行,可通过修改启动脚本中的命令,将命令改为特定conda环境的绝对路径运行即可。

7、启动supervisor服务

supervisord -c /etc/supervisor/supervisord.conf

8、supervisorctl

启动后,可通过supervisorctl客户端控制进程启动、停止、重启。

supervisorctl

bash终端常用命令(不用输supervisorctl)

supervisorctl status  # 开始所有进程
supervisorctl stop vtime_admin  # 停止vtime_admin进程
supervisorctl start vtime_admin  # 开始vtime_admin进程
supervisorctl restart vtime_admin  # 重启vtime_admin进程
supervisorctl restart all  # 重启所有的进程
supervisorctl reread  # 读取有更新(增加)的配置文件,不会启动新添加的程序
supervisorctl update  # 重启配置文件修改过的程序

9、supervisor开机自启

vim打开supervisord.service文件

vim /lib/systemd/system/supervisord.service

将下面内容写入supervisord.service中

[Unit]
Description=Process Monitoring and Control Daemon
After=rc-local.service nss-user-lookup.target

[Service]
Type=forking
ExecStart=[supervisord安装路径]/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=[supervisord安装路径]/supervisord shutdown
ExecReload=[supervisord安装路径]/supervisord reload
killMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

:wq退出并执行下面命令

systemctl enable supervisord

出现下面内容证明设置成功!
在这里插入图片描述

10、关机测试

reboot
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
Supervisor是一个用于管理进程的工具,可以通过配置文件来指定要监控和管理的进程。在配置Supervisor之前,您需要创建一个supervisord.conf文件,并将其放置在/etc/supervisor目录下。您可以使用以下命令来创建和编辑配置文件: ``` sudo mkdir /etc/supervisor echo_supervisord_conf > /etc/supervisor/supervisord.conf ``` 在配置文件中,您可以使用supervisorctl命令行工具来查看和管理进程的状态。一些常用的supervisorctl命令包括: - supervisorctl:查看所有进程的状态 - supervisorctl stop <name>:停止特定的进程 - supervisorctl start <name>:启动特定的进程 - supervisorctl restart <name>:重启特定的进程 - supervisorctl update:加载新的配置(当配置文件修改后) - supervisorctl reload:重新启动配置中的所有程序 您还可以通过运行以下命令来启动Supervisor: ``` supervisord -c /home/supervisord.conf ``` 以上是关于Supervisor配置和常用命令的简要说明。希望能对您有所帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Supervisor 配置详解](https://blog.csdn.net/chenyulancn/article/details/123965900)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [详解 Linux 环境下进程管理工具 Supervisor](https://blog.csdn.net/jake_tian/article/details/101444283)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风吹半夏灬

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值