shell开发的启动和停止应用的脚本

原创
2016/08/20 11:42
阅读数 240
#! /bin/sh    

#启动方法      
start(){
 now=`date "+%Y%m%d%H%M%S"`
 printf "$now"
 exec java -Xms128m -Xmx512m -jar schedMaster.jar &
}
#停止方法    
stop(){
 ps -ef|grep schedMaster.jar|awk '{print $2}'|while read pid
 do
    kill -9 $pid
 done
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
printf 'Usage: %s {start|stop|restart}\n' "$prog"
exit 1

调用方法:

附上一份Linux系统自带的脚本:

#!/bin/bash
#chkconfig:2345 55 25
#processname:httpd 
#version 1.0
#description:source httpd server daemon
PROG=/usr/local/httpd/bin/apachectl
PIDFILE=/usr/local/httpd/logs/httpd.pid
SERVICE=httpd

start(){
	sleep 1
	if [ -e $PIDFILE ];then
         	echo "$SERVICE already running"
	else
		$PROG start &> /dev/null
		echo "starting $SERVICE"
	fi
	}

stop(){
	sleep 1
	if [ -e $PIDFILE ];then
         	$PROG stop &> /dev/null
        	 echo "stopping $SERVICE"
	else
		echo "$SERVICE is stop! stop failure"
	fi
	}

status(){
          if [ -e $PIDFILE ];then
         	   echo "$SERVICE is running!"
  	    else
        	   echo "$SERVICE is stop"
          fi
  	}
  

restart(){
          stop
          start
	  }

case "$1" in
  "start")
          start
          ;;
  
  "stop")
          stop
          ;;
  
  "status")
          status
          ;;
  
  "restart")
          restart
          ;;
  
 *)
          echo "Usage: $0 start|stop|status|restart"
         ;;
esac

 

展开阅读全文
加载中

作者的其它热门文章

打赏
0
5 收藏
分享
打赏
0 评论
5 收藏
0
分享
返回顶部
顶部