[monitor.idkin.com:/home/admin]# vi /etc/init.d/nrpe
#!/bin/bash # Datetime: 2011-11-21 # Author: Dandy # Email: penghjfy@126.com # Description: Nrpe Service control script start="/usr/local/nrpe/bin/nrpe -c /usr/local/nrpe/etc/nrpe.cfg -d" stop="kill -9 `cat /var/run/nrpe.pid`" restart="kill -USR2 `cat /var/run/nrpe.pid`" if [ $1 = start ];then count_pid=`/bin/ps aux|grep "nrpe"|grep -v "grep"|wc -l` Pid=$(/bin/ps -eaf|grep "nrpe" |grep -v "grep" |awk '{print $2}') if [ $count_pid -gt 2 ];then echo "Nrpe is running!" exit 0 else /usr/local/nrpe/bin/nrpe -c /usr/local/nrpe/etc/nrpe.cfg -d fi echo "Start Nrpe Service [OK]" elif [ $1 = stop ];then echo "Stop Nrpe Service [OK]" echo "Stop:"$stop eval $stop sleep 1 eval $0" c" elif [ $1 = restart ];then /bin/kill -INT `cat /var/run/nrpe.pid` echo "Restart:"$restart eval $restart sleep 1 eval $0" c" if [ $? -eq 0 ] ; then echo "`date +%Y-%m-%d_%H:%M:%S` nrpe sevice is kill!" >> /tmp/nrpe.log nohup /usr/local/nrpe/bin/nrpe -c /usr/local/nrpe/etc/nrpe.cfg -d > /dev/null 2>&1 & echo "Restart Nrpe Service [OK]" fi elif [ $1 = status ] ; then count_pid=`/bin/ps aux|grep "nrpe"|grep -v "grep"|wc -l` if [ $count_pid -gt 2 ];then echo "Nrpe is running!" exit 0 else echo "Nrpe is not running!" fi echo "Usages: sh nrpe [start|stop|restart|status]" fi [monitor.idkin.com:/home/admin]# chmod a+x /etc/init.d/nrpe [monitor.idkin.com:/home/admin]# /etc/init.d/nrpe status Nrpe is running! [monitor.idkin.com:/home/admin]# /etc/init.d/nrpe restart Restart:kill -USR2 3724 Restart Nrpe Service [OK] [monitor.idkin.com:/home/admin]# /etc/init.d/nrpe stop Stop Nrpe Service [OK] Stop:kill -9 19108 [monitor.idkin.com:/home/admin]# /etc/init.d/nrpe start Start Nrpe Service [OK]