Use Shell or other scripting languages to write a script for Linux restart process monitoring and fault

1.shell by a while-do loop, with a ps -ef | grep loader checks whether the process is running, if not running, start,

This ensures that the process of re-hang the collapse started in a timely manner.

Note 2:00: 1.ps -ef | grep must add its path when a process, or easy to grep wrong results;

             2. must be removed with the -v grep command itself from the result, otherwise the result is not empty.

#!/bin/sh 

while
do 
echo "Current DIR is " $PWD 

stillRunning=$(ps -ef |grep "$PWD/loader" |grep -v "grep") 


if [ "$stillRunning" ] ; then 
echo "TWS service was already started by another way" 


echo "Kill it and then startup by this shell, other wise this shell will loop out this message annoyingly" 


kill -9 $pidof $PWD/loader 
else 


echo "TWS service was not started" 


echo "Starting service ..." 
$PWD/loader 


echo "TWS service was exited!" 


fi 
sleep 10 


done 

    If you find that when you start this process and the presence of shell, indicating that it has started the process in other ways, he will continue to remind find the process,

The solution is to once they have been found to be other ways to begin the process that is kill off (kill -9 $ PWD / loader)

 

Guess you like

Origin www.cnblogs.com/arvin-feng/p/11108750.html