[Shell] a service can pull up, stop and restart the shell script

shell script:

! # / bin / bash 

#Jar package name 
jar_name = Resouce-0.0.1-SNAPSHOT.jar 
# service name 
SERVICE_NAME = CountServer 
# Services catalog 
SERVICE_HOME = $ (cd "$ (dirname" $ 0 ")"; pwd) 
# log directory 
= $ SERVICE_HOME SERVICE_LOGS / log 

#java virtual machine startup parameters 
the JAVA_OPTS = "- ms512m -mx512M -Xmn256m -Djava.awt.headless to true = -XX: MaxPermSize 128M =" 

# document generation process 
PID = $ SERVICE_NAME.pid 

# to enter the service directory 
$ SERVICE_HOME cd 

Case "$ 1" in 
    Start) 
        IF [-d $ SERVICE_LOGS!]; the then 
            mkdir "$ SERVICE_LOGS" 
        the else 
            echo "$ SERVICE_LOGS EXISTS!"  
        Fi
        nohup the JAVA_OPTS the Java $ -jar $ jar_name>$SERVICE_LOGS/$SERVICE_NAME.log  2>&1 &
        echo $! > $SERVICE_HOME/$PID
        echo "==== start $SERVICE_NAME ===="
        ;;
    stop)
        kill -9 `cat $SERVICE_HOME/$PID`
        rm -rf $SERVICE_HOME/$PID
        echo "==== stop $SERVICE_NAME ===="
        ;;
    restart)
        $0 stop
        sleep 2
        $0 start
        ;;
    *)
        $0 stop
        sleep 2
        $0 start
        ;;
esac
exit 0

  

File Address:

https://files.cnblogs.com/files/wuyizuokan/countServer.sh

Run the script:

With parameters:

stop:

start:

 

restart:

 

 

Guess you like

Origin www.cnblogs.com/wuyizuokan/p/11223272.html