supervisor 的更新

仅为随机记录,以便后续遗忘参考使用

当已运行的supervisor 更新时,因时间久远,遇到种种问题,仅做记录备案

目的:

  1. 为supervisor 添加一个新程序

  2. 重新启动supervisord后,Web界面可以控制管理新程序

1. 为新程序添加配置文件


[root@server-247 ~]# cd /etc/supervisor/conf.d/
[root@server-247 conf.d]# vi RiskcopInitDynServerV2_Basic.ini


2. 具体内容如下:
[root@server-247 conf.d]# cat RiskcopInitDynServerV2_Basic.ini
[program:RiskCop_Init_DynServerV2_Basic]   #  为程序的名称
command=bash -c "lsof -i :7799 |awk 'NR==2{print$2}' |xargs kill -9; python3 Init_Heart_0923.py"  #需要执行的命令
directory=/home/TestEnv/riskcop/FunctionalTest/Risk_Init_DynV2_Basic/Init0510/Init_Scripts/ #命令执行的目录
#environment=ASPNETCORE__ENVIRONMENT=Production #环境变量
user=root #用户
priority=999
stopsignal=INT
autostart=true #是否自启动
startsecs=10 # #指程序启动时需要程序至少稳定运行x秒才认为程序运行正常,在这x秒中程序状态为正在启动(s)
autorestart=true #是否自动重启
startretries=3 # # 重启失败拉起次数
#stderr_logfile=/var/log/RiskcopInit_Server.err.log #错误日志文件
#stdout_logfile=/var/log/RiskcopInit_Web.out.log #输出日志文件

redirect_stderr=true
stderr_logfile_maxbytes=20MB
stderr_logfile_backups = 20
stderr_logfile=/etc/supervisor/logs/RiskcopInitDynServerV2Basic.err.log #错误日志文件
stdout_logfile_maxbytes=20MB
stdout_logfile_backups = 20
stdout_logfile=/etc/supervisor/logs/RiskcopInitDynServerV2Basic.out.log #输出日志文件

stopasgroup=true
killasgroup=true


3. 查看
[root@server-247 conf.d]# ll
total 24
-rw-r--r--. 1 root root 1152 Mar 28 17:49 RiskcopInitDynServer.ini
-rw-r--r--. 1 root root 1149 Nov 25  2022 RiskcopInitDynServer.ini_bak
-rw-r--r--  1 root root 1190 Jun 13 10:40 RiskcopInitDynServerV2_Basic.ini  
-rw-r--r--. 1 root root 1146 Mar 28 18:11 RiskcopInitServer.ini
-rw-r--r--. 1 root root 1143 Feb 15 16:34 RiskcopInitServer.ini_bak
-rw-r--r--. 1 root root 1051 Mar 28 18:03 RiskcopInitWeb.ini
[root@server-247 conf.d]#
[root@server-247 conf.d]#
[root@server-247 conf.d]#

2. 修改配置文件后,重启动程序时,报错如下:

错误原因最后定位是 supervisor 配置文件编码格式非 utf-8 造成

[root@server-247 etc]# supervisord -c /etc/supervisord.conf
Error: 'utf-8' codec can't decode byte 0xb3 in position 48: invalid start byte
For help, use /usr/local/bin/supervisord -h
[root@server-247 etc]# 
[root@server-247 etc]#
 

错误原因:配置文件编码格式问题,经检查 supervisor 的配置文件读取的是 /etc/supervisord.conf 中的 /etc/supervisor/conf.d/*.ini  如下:
[root@server-247 etc]#

并且 supervisor 的配置文件路径可以查看
[root@server-247 etc]# cat /etc/supervisord.conf
; Sample supervisor config file.
...
...
...

; interpreted as relative to this file.  Included files *cannot*
; include files themselves.

[include]
files = /etc/supervisor/conf.d/*.ini           # 此处是supervisor 配置文件路径,

 2.1 查询配置文件编码格式

# 查询文件编码格式命令
file -i

2.1 查询配置文件编码格式

# 查询文件编码格式命令
file -i 

[root@server-247 etc]# cd /etc/supervisor/conf.d/
[root@server-247 conf.d]# ll
total 24
-rw-r--r--. 1 root root 1152 Mar 28 17:49 RiskcopInitDynServer.ini
-rw-r--r--. 1 root root 1149 Nov 25  2022 RiskcopInitDynServer.ini_bak
-rw-r--r--  1 root root 1079 Jun 13 09:45 RiskcopInitDynServerV2_Basic.ini
-rw-r--r--. 1 root root 1146 Mar 28 18:11 RiskcopInitServer.ini
-rw-r--r--. 1 root root 1143 Feb 15 16:34 RiskcopInitServer.ini_bak
-rw-r--r--. 1 root root 1051 Mar 28 18:03 RiskcopInitWeb.ini
[root@server-247 conf.d]#

[root@server-247 conf.d]# file  -i RiskcopInitDynServer.ini
RiskcopInitDynServer.ini: text/plain; charset=utf-8
[root@server-247 conf.d]#

[root@server-247 conf.d]# file  -i RiskcopInitDynServerV2_Basic.ini
RiskcopInitDynServerV2_Basic.ini: text/plain; charset=iso-8859-1     # 编码格式 iso-8859-1
[root@server-247 conf.d]# 

2.2 修改 RiskcopInitDynServerV2_Basic.ini 编码格式为:utf-8

本人偷懒,使用Nodepad++ 更改 程序配置文件RiskcopInitDynServerV2_Basic.ini 的编码格式,具体方式如下图所示,更新后保存即可

supervisor 的更新_第1张图片

 3. 重启supervisor

先关闭supervisor启动脚本,之后再关闭supervisord服务

# 先关闭 运行的程序,方法2种:

方法一: 命令关闭所有程序
# supervisorctl stop all

方法二: Web 界面关闭所有程序

# 杀死 supervisord 进程
# ps aux | grep supervisord
# kill pid


[root@server-247 conf.d]# ps -ef|grep supervisor
root      14545      1  0 Jul24 ?        00:01:06 /usr/bin/python3 /usr/local/bin/supervisord -c /etc/supervisord.conf
root     166160 149571  0 10:53 pts/14   00:00:00 grep --color=auto supervisor
[root@server-247 conf.d]#
[root@server-247 conf.d]#
[root@server-247 conf.d]# kill -9 14545
[root@server-247 conf.d]#
[root@server-247 conf.d]# ps -ef|grep supervisor
root     167421 149571  0 11:03 pts/14   00:00:00 grep --color=auto supervisor
[root@server-247 conf.d]#


方法二: Web 界面关闭所有程序supervisor 的更新_第2张图片


3.1

# 启动supervisor  (启动服务端)

[root@server-247 etc]# supervisord -c /etc/supervisord.conf
Error: Another program is already listening on a port that one of our HTTP servers is configured to use.  Shut this program down first before starting supervisord.
For help, use /usr/local/bin/supervisord -h
[root@server-247 etc]#

# 提示已在运行

结束supervisor,后重新运行即可

[root@server-247 etc]#  ps -ef|grep supervisor
root      31179      1  0 May16 ?        00:10:54 /usr/bin/python3 /usr/local/bin/supervisord -c /etc/supervisord.conf
root      69356  67312  0 11:08 pts/188  00:00:00 tail -f /tmp/supervisord.log
root      69400  67518  0 11:10 pts/194  00:00:00 grep --color=auto supervisor
[root@server-247 etc]#
[root@server-247 etc]#
[root@server-247 etc]# kill -9 31179
[root@server-247 etc]#
[root@server-247 etc]#  ps -ef|grep supervisor
root      69356  67312  0 11:08 pts/188  00:00:00 tail -f /tmp/supervisord.log
root      69425  67518  0 11:11 pts/194  00:00:00 grep --color=auto supervisor
[root@server-247 etc]#

启动错误问题2:

当运行 supervisord -c /etc/supervisord.conf 命令时,出现了 "Unlinking stale socket /tmp/supervisor.sock" 的错误提示。这个错误通常发生在之前的Supervisor进程意外终止或没有正确关闭的情况下

# 查询 supervisor 未启动
[root@server-248 supervisor]# ps -ef|grep supervisor
root     132781 126069  0 10:49 pts/19   00:00:00 tail -f /tmp/supervisord.log
root     134333 266539  0 10:52 pts/9    00:00:00 grep --color=auto supervisor
[root@server-248 supervisor]#
[root@server-248 supervisor]#

# 启动 supervisor 
[root@server-248 supervisor]# supervisord -c /etc/supervisord.conf
Unlinking stale socket /tmp/supervisor.sock                # 上次未

[root@server-248 supervisor]#
[root@server-248 supervisor]# rm /tmp/supervisor.sock
rm: remove socket ‘/tmp/supervisor.sock’? y
[root@server-248 supervisor]#

3.2 启动supervisor 服务端

[root@server-247 etc]# supervisord -c /etc/supervisord.conf
[root@server-247 etc]#
[root@server-247 etc]#  ps -ef|grep supervisor
root      69356  67312  0 11:08 pts/188  00:00:00 tail -f /tmp/supervisord.log
root      69429      1  0 11:11 ?        00:00:00 /usr/bin/python3 /usr/local/bin/supervisord -c /etc/supervisord.conf
root      69529  67518  0 11:11 pts/194  00:00:00 grep --color=auto supervisor
[root@server-247 etc]#
[root@server-247 etc]#



 

 
3.3 命令查询supervisor 程序

[root@server-247 etc]# supervisorctl
RiskCop_Init_DynServer           RUNNING   pid 69430, uptime 0:00:22
RiskCop_Init_DynServerV2_Basic   RUNNING   pid 69431, uptime 0:00:22
RiskCop_Init_Server              RUNNING   pid 69432, uptime 0:00:22
RiskCop_Init_Web                 RUNNING   pid 69433, uptime 0:00:22
supervisor>
supervisor> exit

[root@server-247 etc]#

 3.4 查询程序进程

[root@server-247 etc]# ps -ef|grep python3*
root       2109      1  0 May14 ?        00:04:19 /usr/bin/python2 -Es /usr/sbin/tuned -l -P
root      67228 250007 99 09:31 pts/169  01:40:15 python3 Init_Heart_V2.py
root      69429      1  0 11:11 ?        00:00:00 /usr/bin/python3 /usr/local/bin/supervisord -c /etc/supervisord.conf
root      69430  69429  0 11:11 ?        00:00:00 bash -c lsof -i :7788 |awk 'NR==2{print$2}' |xargs kill -9; python3 Dyn_SocketServer.py
root      69431  69429  0 11:11 ?        00:00:00 bash -c lsof -i :7799 |awk 'NR==2{print$2}' |xargs kill -9; python3 Init_Heart_0923.py
root      69432  69429  0 11:11 ?        00:00:00 bash -c lsof -i :7777 |awk 'NR==2{print$2}' |xargs kill -9; python3 Socket_Server.py
root      69433  69429  0 11:11 ?        00:00:00 bash -c lsof -i :8888 |awk 'NR==2{print$2}' |xargs kill -9; python3 manage.py runserver
root      69448  69430 99 11:11 ?        00:00:39 python3 Dyn_SocketServer.py
root      69450  69432 99 11:11 ?        00:00:39 python3 Socket_Server.py
root      69451  69431 99 11:11 ?        00:00:47 python3 Init_Heart_0923.py
root      69453  69433  0 11:11 ?        00:00:00 python3 manage.py runserver
root      69521  69453  3 11:11 ?        00:00:01 /usr/bin/python3 manage.py runserver
root      69540  67518  0 11:12 pts/194  00:00:00 grep --color=auto python3*
[root@server-247 etc]# 

3.5 Web 界面查看

supervisor 的更新_第3张图片

 到此已完成supervisor 新程序的添加工作

你可能感兴趣的:(运维)