Shell Script _ Start stop restart SH script

Source: Internet
Author: User

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 #!/bin/sh## java envexport JAVA_HOME=/usr/java/jdk1.7.0_79export JRE_HOME=$JAVA_HOME/jre## service name## 服务所在目录SERVICE_DIR=/usr/local/services/dubbodemo## 服务名称SERVICE_NAME=dub-service-demoJAR_NAME=$SERVICE_NAME\.jarPID=$SERVICE_NAME\.pidcd $SERVICE_DIRcase "$1" in    start)        ##nohup &  以守护进程启动        nohup $JRE_HOME/bin/java -Xms256m -Xmx512m -jar $JAR_NAME >/dev/null 2>&1 &        echo $! > $SERVICE_DIR/$PID        echo "=== start $SERVICE_NAME"        ;;    stop)        kill `cat $SERVICE_DIR/$PID`        rm -rf $SERVICE_DIR/$PID        echo "=== stop $SERVICE_NAME"        ## 停止5秒        sleep 5        ##        P_ID=`ps -ef | grep -w "$SERVICE_NAME" | grep -v "grep" | awk ‘{print $2}‘`        if [ "$P_ID" == "" ]; then            echo "=== $SERVICE_NAME process not exists or stop success"        else            echo "=== $SERVICE_NAME process pid is:$P_ID"            echo "=== begin kill $SERVICE_NAME process, pid is:$P_ID"            kill -9 $P_ID        fi        ;;    restart)        $0 stop        sleep 2        $0 start        echo "=== restart $SERVICE_NAME"        ;;    *)        ## restart        $0 stop        sleep 2        $0 start        ;;esacexit 0




From for notes (Wiz)

Shell Script _ Start stop restart SH script

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.