码迷,mamicode.com
首页 > 其他好文 > 详细

服务脚本

时间:2020-05-26 20:01:19      阅读:66      评论:0      收藏:0      [点我收藏+]

标签:name   ini   tar   start   read   bash   stat   脚本   ons   

#!/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
	

  

服务脚本

标签:name   ini   tar   start   read   bash   stat   脚本   ons   

原文地址:https://www.cnblogs.com/dissipate/p/12967806.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!