当前位置: 首页 > Linux

linux监控进程,进程关闭自动重启解决方案

时间:2023-04-06 01:50:31 Linux

Linux监控进程,进程关闭自动重启解决方案corntab+shell脚本检测进程该方案简单,不需要额外安装软件。缺点是有间隔,corntab设置每秒执行一次shell脚本时有间隔#!/bin/bash#@authorsmallForest#@email1032817724@qq.comproc_name="xiaofei.php"#processnameproc_num(){num=`ps-ef|grep$proc_name|grep-vgrep|wc-l`return$num}proc_numnumber=$?echo$numberif[$number-eq0]then#cd/Applications/MAMP/htdocs/aa/bb/public#输入路径nohupphpxiaofei.php>xiaofei2>&1&#创建daemon进程fisupervisorscheme该scheme响应速度快,占用系统资源多安装Pythonyuminstallpython-setuptools安装Supervisoreasy_installsupervisor查看是否成功echo_supervisord_conf有输出,是否正确创建目录,初始化配置mkdir/usr/supervisorcho_supervisord_conf>/usr/supervisor/supervisord.confmkdir/usr/supervisor/supervisord.d/修改系统配置文件vim/usr/supervisor/supervisord.confinclude添加一行[include]files=/usr/supervisor/supervisord.d/*.confstartsupervisorsupervisord-c/usr/supervisor/supervisord.conflsof-i:9001查看端口创建子配置文件vim/usr/supervisor/supervisord.d/supervisor_test_one.confinput[program:test_one]command=php/root/lianxi_php/xiaofei.php;要监视的进程路径路径优先级=1;数字越大,优先级越高numprocs=1;启动多个进程autostart=true;启动autorestart=true并启动supervisord;自动重启startretries=10;启动失败最大重试次数exitcodes=0;正常退出代码stopsignal=KILL;用于终止进程的信号stopwaitsecs=10;发送SIGKILLredirect_stderr=true之前的等待时间;redirectstderrtostdoutrestartsupervisorsupervisord-c/usr/supervisor/supervisord.conf会有一个supervisor>inputreload,如果顺利,如果不顺利,需要不断查看日志。参考链接