1. 程式人生 > >設置自己的服務為自動重啟

設置自己的服務為自動重啟

art init bin stat top chkconfig 服務 service init.d

#!/bin/bash

description: testsrv

chkconfig: - 99 1

. /etc/init.d/functions
SCRIPT_NAME=testsrv
start(){
if [ -f /var/lock/subsys/$SCRIPT_NAME ];then
action " starting testsrv: "
else
touch /var/lock/subsys/$SCRIPT_NAME
action " starting testsrv: "
fi
}
stop(){
if [ -f /var/lock/subsys/$SCRIPT_NAME ];then

rm -rf /var/lock/subsys/$SCRIPT_NAME
action " stoping testsrv: " false
else
action " stoping testsrv: " false

       fi

}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
if [ -f /var/lock/subsys/$SCRIPT_NAME ];then
echo $SCRIPT_NAME is starting
else
echo $SCRIPT_NAME is stoping
fi
;;

*)
echo service testsrv {start|stop|restart}
esac

設置自己的服務為自動重啟