shell開發的啓動和中止應用的腳本

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

調用方法:java

附上一份Linux系統自帶的腳本:apache

#!/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
相關文章
相關標籤/搜索