当前位置:   article > 正文

Supervisor实现进程守护,Linux守护程序_进程守护backoff

进程守护backoff

以守护某一进程为例 :whistle_capture

环境:ubuntu 
运行Supervisor需要root权限 

 

1 安装Supervisor

apt-get install supervisor

安装完成后我们可以在/etc/supervisor/找到Supervisor

2.vi /etc/supervisor/supervisord.conf 
配置文件中注释是用冒号注释;

[include] 
files = /etc/supervisor/conf.d/*.conf 
我们在[include]后面添加新program

program相关参数说明:

[program:nginx] nginx为我们定义进程名, 
directory=/home/ubuntu/webvideo/nginx 待守护程序所在根目录 
command=/home/ubuntu/webvideo/nginx/sbin/nginx -g ‘daemon off;’ 启动程序命令 
autostart =true 在 supervisord 启动的时候也自动启动 
startsecs=5 启动 5 秒后没有异常退出,就当作已经正常启动了 
autorestart =true 程序异常退出后自动重启 
startretries=3 启动失败自动重试次数,默认是 3 
user=ubuntu 用哪个用户启动 
redirect_stderr=true 把 stderr 重定向到 stdout,默认 false,用于保存程序输出作为log 
stdout_logfile_maxbytes=20MB stdout 日志文件大小,默认 50MB 
stdout_logfile_backups=20 stdout 日志文件备份数,即一个log写满后会接这开一个log往下写 
stdout_logfile =/home/ubuntu/webvideo/nginx/logs/nginx_stdout.loglog存储路径
 

  1. [program:whistle_capture]
  2. directory=/home/V3/build/
  3. command=/home/V3/build/whistle_capture
  4. autostart=true
  5. startsecs=3
  6. autorestart=true
  7. startretries=3
  8. user=root
  9. redirect_stderr=true
  10. stdout_logfile_maxbytes=20MB
  11. stdout_logfile_backups=20
  12. stdout_logfile = /home/V3/nginx_stdout.log

3.更新在编辑好的配置文件

#supervisorctl reload

启动supervisord   

sudo supervisord -c /etc/supervisor/supervisord.conf

4.supervisord 常用操作

  1. supervisorctl status #查看守护程序状态
  2. supervisorctl stop whistle_capture #停止nginx
  3. supervisorctl start whistle_capture #启动nginx
  4. supervisorctl restart whistle_capture #重启 nginx 程序
  5. supervisorctl reread #读取有更新(增加)的配置文件,但不会启动新添加的程序
  6. supervisorctl update #重启配置文件修改过的程序

5 supervisord 进程状态

  1. STOPPED (0) 进程已停止
  2. STARTING (10) 该进程由于启动请求而开始。
  3. RUNNING (20) 该过程正在运行。
  4. BACKOFF (30)该过程进入“ 启动”状态,但随后退出的速度太快而无法移至“ 运行”状态。 前面有startsecs 这个参数设定
  5. STOPPING (40) 由于停止请求,该进程正在停止。
  6. EXITED (100)该进程从RUNNING状态退出(预期或意外)。
  7. FATAL (200)该过程无法成功启动。
  8. UNKNOWN (1000)该进程处于未知状态(supervisord 编程错误)。

错误解决方法:

Supervisor on Debian Wheezy: another program is already listening on a port that one of our HTTP ser

 

解决办法

Terminal上输入

ps -ef | grep supervisord
  • 1

获取所有supervisord正在运行的pid

  1. root 2503 1 0 Nov19 ? 00:03:23 /usr/bin/python /usr/bin/supervisord
  2. root 21337 2556 0 18:15 pts/8 00:00:00 grep --color=auto supervisord
  • 1
  • 2

pid=2503

kill -s SIGTERM 2503  

增加到开机自启动项

#vim /etc/rc.local

  1. sleep 3
  2. /usr/src/MacTcp/IpCfg enp2s0 MZ &
  3. insmod /home/driver/dvrs_hw.ko
  4. #cd /home/V3/build
  5. #/home/V3/build/whistle_capture > /dev/null &
  6. #/home/V3/build/whistle_capture >> /root/whistle_capture.log &
  7. cd /etc/openvpn
  8. openvpn /etc/openvpn/client.conf > /dev/null &
  9. sudo supervisord -c /etc/supervisor/supervisord.conf
  10. exit 0
  11. ~
错误2Error: 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

解决方法:

find / -name supervisor.sock

unlink /name/supervisor.sock

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/blog/article/detail/57966
推荐阅读
相关标签
  

闽ICP备14008679号