WildFly 的 System V init 脚本

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/bin/bash

: ${JAVA_HOME:=/usr/lib/jvm/jdk-7u51}
export JAVA_HOME

: ${SCALA_HOME:=/opt/scala-2.10.2}
export SCALA_HOME

PROC_LOCATION=/opt/wildfly-8.0.0.Final
PROC_NAME='WildFly App Server'
PROC_USER=wildfly
PROC_APP=wildfly
SLEEPTIME=8

export WILDFLY_HOME=${PROC_LOCATION}

# for multi instances adapt those lines.
TMP_DIR=/var/tmp
PID_FILE=/var/run/${PROC_APP}.pid

PREFIX_CMD=
## PREFIX_CMD='echo =>'

SUDO_CMD=/usr/bin/sudo

case "$1" in
  start)
    echo "Starting service ${PROC_NAME}"
    ${PREFIX_CMD} mkdir -p /var/log/${PROC_APP}
    ${PREFIX_CMD} chown -R ${PROC_USER} /var/log/${PROC_APP}
    ${PREFIX_CMD} ${SUDO_CMD} -u ${PROC_USER} -E ${WILDFLY_HOME}/bin/standalone.sh  >> /var/log/${PROC_APP}/${PROC_APP}.log  &
    exit $?
    ;;

  stop)
    echo "Stopping service ${PROC_NAME}"
    ProcessId=`ps auwwx | grep -v awk | awk '/'${PROC_USER}'/ && /org.jboss.as.standalone/ { print $2 }'`
    ${PREFIX_CMD} kill ${ProcessId}
    exit $?
    ;;

  restart)
    $0 stop
    echo "Zzz ... $SLEEPTIME secs"
    sleep $SLEEPTIME
    $0 start
    ;;

  probe|status)
    ProcessId=`ps auwwx | grep -v awk | awk '/'${PROC_USER}'/ && /org.jboss.as.standalone/ { print $0 }'`
    if [ "x${ProcessId}" != "x" ]; then
        echo $ProcessId
    else
        echo "No process is running."
    fi
    ;;

  *)
    echo "Usage: $0   start | stop | restart | probe | status"
    exit 1
    ;;

esac

#End