linux监控进程并且自动重启

1、Linux下有时需要监控进程的运行状态,并且能够自动重启,以下为sphinx自动重启脚本

vim /etc/sh/searchd.sh

#!/bin/sh
pid = `ps -ef  |  grep  " searchd "  |  grep -v  " grep "  |  wc -l`
if [  $pid  -eq  0  ]
 
then
        echo "begin restart,please waiting..."
        /usr/local/sphinx/bin/searchd -c /usr/local/sphinx/etc/sphinx.conf
         exit  1
else
       
  echo  -e  " exist ,don't need restart "
fi

然后保存改shell脚本并且设置可执行chmod +w /etc/sh/searchd.sh

最后加入crontab中每个1分钟或多久执行一次查询

你可能感兴趣的:(linux,脚本)