shll bat2

# etc 启动
ETC_PATH=/etc/init.d

OMS_SIGN=oms.daemon.Launcher

check_started() {
    count=`ps -ef | grep $OMSD | grep $OMS_SIGN | wc -l`
    if [ $count -gt 0 ]; then
        echo "$CAPTION is already running."
        exit
    fi
}

check_stopped() {
    count=`ps -ef | grep $OMSD| grep $OMS_SIGN | wc -l`
    if [ $count -eq 0 ]; then
        echo "$CAPTION is not running."
        exit
    fi
}

check_java(){
    if [ ! -f $JAVA_HOME/bin/java ]; then
        echo "Error: $JAVA_HOME/bin/java doesn't exist."
        exit
    fi
}

check_java

case "$1" in
  start )
    shift
    check_started
    echo "Starting $CAPTION"
    $PRUNSRV \
        -home $JAVA_HOME \
        -cp $LIB \
        -user $OMSUSER \
        -pidfile $PID \
        $1 \
        -procname $OMSD \
        $MAIN
    sleep 1
    echo "$CAPTION is started"
    # 当用 root 启动,造成 PID 文件只有 root 才能访问,当用 OMSUSER 停止时会
    # 造成失败. 这里将 PID 设置成任意用户可以访问
    chmod 777 $PID
    exit $?
    ;;
  stop )
    shift
    check_stopped
    echo "Stopping $CAPTION"
    $PRUNSRV \
        -home $JAVA_HOME \
        -cp $LIB \
        -user $OMSUSER \
        -pidfile $PID \
        $1 \
        -stop \
        $MAIN
    echo "$CAPTION has stopped"
    $JAVA_EXE -cp $LIB $MAIN waitstop
    exit $?
    ;;
  restart)
    shift
    $SCRIPT stop $*
    $SCRIPT start $*
    ;;
  install )
    shift
    if [[ $EUID -ne 0 ]]; then
       echo "This command must be run as root."
       exit 1
    fi
    if [[ -f $ETC_PATH/omsd ]]; then
        echo "$CAPTION is already installed."
        exit 1
    fi
    echo "Installing $CAPTION"
    chmod +x $PRUNSRV
    # copy omsd to /etc/init.d/
    cat $TEMPLATE | sed "s|EXEC_TEMPLATE|$SCRIPT|g" > $ETC_PATH/omsd
    chmod +x $ETC_PATH/omsd
    # 激活
    chkconfig omsd on
    echo Installation of $NAME is complete
    exit $?
    ;;
  uninstall )
    shift
    if [[ $EUID -ne 0 ]]; then
       echo "This command must be run as root."
       exit 1
    fi
    if [[ -f $ETC_PATH/omsd ]]; then
        echo "Uninstalling $CAPTION"
    else
        echo "$CAPTION is not installed."
        exit 1
    fi
    $SCRIPT stop
    echo "remove $CAPTION"
    chkconfig omsd off
    echo "remove $ETC_PATH/omsd"
    rm -f $ETC_PATH/omsd
    echo Uninstallation of $NAME is complete
    exit $?
    ;;
    * )
    echo 'Usage: omsd start|stop|restart|install|uninstall'
    exit 1
    ;;
esac

你可能感兴趣的:(bat)