服务脚本

#!/bin/env sh

program=`basename $0|awk -F. '{print $1}'`
lock=/var/lock/subsys/$program
source /etc/rc.d/init.d/functions

function start(){
	if [ -e $lock ];then
		echo "$program is already running" && return 2
	else
		touch $lock && action "$program started" /bin/true && return 0
	fi
}

function stop(){
	if [ ! -e $lock ];then
		action "$program is not running" /bin/false && return 3
	else
		rm -f $lock && action "$program stopped" /bin/true && return 0
	fi
}

function status(){
	if [ ! -e $lock ];then
		action "$program is not running" /bin/false && return 0
	else
		action "$program is running" /bin/true && return 0
	fi
}

function usage(){
	action "usage:$program start|stop|status|restart" /bin/false && return 6
}

if [ $# -ne 1 ];then
	usage
	exit 5
fi

case $1 in
start)
	start
	;;
stop)
	stop
	;;
status)
	status
	;;
restart)
	stop
	start
	;;
*)	
	usage
	;;
esac
	

  

猜你喜欢

转载自www.cnblogs.com/dissipate/p/12967806.html