start/stop linux scripts

#!/bin/sh

export APP_CODE=apm

export APP_HOME=/usr/local/clo/app/ffo/rtns_adapter
export APP_JCLASS_HOME=${APP_HOME}/jclass

export SHUTDOWN_TIME=10

export JAVA_HOME=/usr/local/clo/ven/jdk1.6.0_45-64
export PW_MATRIX=/usr/local/ccms/security/.PASSWORD_MATRIX
export PW_MATRIX_LIB=/usr/local/ccms/security/jclass/pwm
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/ccms/lib
export CLASSPATH=/usr/local/ccms/security/jclass/pwm/PwMatrix.jar:${APP_HOME}/jclass/*

case "$OEC_ENV" in
"DEV1"*)
    export ENV=dev
    ;;
"UA1"*)
    export ENV=uat
    ;;
"PROD"*)
    export ENV=prod
    ;;
*) echo "Unable to find ENV definition, RTNS Adapter exit.";;
esac

export CFGPATH=/usr/local/clo/app/deploy/cfg/adapter-GMBT-${ENV}.properties

MAIN_CLASS=com.ssc.ssgm.fx.rtns.adapter.RTNSAdapterMain
pid=""

getpid() {
        pid=`ps -ef | grep java | grep ${MAIN_CLASS} | grep ${TCID} | grep ${CFGPATH} | grep ${ENV} | awk '{print $2}'`
}

start() {
        echo "Starting RTNSAdatper for TCID ${TCID}..."
    getpid
    if [ "X${pid}" = "X" ]
    then
        nohup $JAVA_HOME/bin/java -cp ${CLASSPATH} -Denv=${ENV} ${MAIN_CLASS} ${TCID} ${CFGPATH} &
        getpid
                if [ "X${pid}" = "X" ]
                then
                        echo "Failed to start RTNSAdapter for ${TCID}"
                else
                        echo "RTNSAdatper for ${TCID} is running. PID is ${pid}"
                fi

    else
        echo "RTNSAdatper is already running."
        exit 1
    fi
}

stop() {
        echo "Stopping RTNSAdapter for TCID ${TCID}..."
        getpid
    if [ "X${pid}" = "X" ]
    then
                echo "RTNSAdapter is not running."
        else
                kill ${pid}
                sleep $SHUTDOWN_TIME

                getpid

                if [ "X${pid}" = "X" ]
                then
                        echo "Stopped RTNSAdapter."
                else
                        echo "Failed to stop RTNSAdapter."
                        exit 1
                fi
        fi
}

usage() {
echo "Usage: $0 { start | stop | restart }"
        exit 1
}

if [ "$#" -ne 1 ]
then
        usage
        exit 1
else
if [ "${ENV}" = "prod" ]
then
export TCID="GMBH"
else
export TCID="GMBT"
fi

        case "$1" in
    'start')
        start
        ;;
    'stop')
        stop
        ;;
    'restart')
        stop
        start
    ;;
    *)
        usage
        ;;
        esac
        exit 0
fi

你可能感兴趣的:(script)