#!/usr/bin/env bash #JAVA_HOME=/opt/jdk1.7.0_07 if [ -z "${APP_HOME}" ]; then export APP_HOME="$(cd "`dirname "$0"`"/..; pwd)" fi # Find the java binary if [ -n "${JAVA_HOME}" ]; then RUNNER="${JAVA_HOME}/bin/java" else if [ `command -v java` ]; then RUNNER="java" else echo "JAVA_HOME is not set" >&2 exit 1 fi fi cd $APP_HOME # ----------------------------------------------------------- # For a full list of available configuration files do # java -jar start.jar --help # ----------------------------------------------------------- if [ ! -d $APP_HOME/logs ] then mkdir -p $APP_HOME/logs fi echo "dir_path="$dir_path MAINCLASS="com.jiusuo.osf.hub.Main" LIB_DIR="lib" CLASS_DIR="conf" JVM_ARGS="$JAVA_OPTS -Dapp.home=$APP_HOME -Dapp.logs=$APP_HOME/logs" PRO_ARGS="" PROGRAM_NAME="fsserver" PID_DIR="$APP_HOME/start.d" jcommand=$RUNNER runtype="-classpath" APPEND_LIB="$APP_HOME/$CLASS_DIR" PID_NAME="$PROGRAM_NAME.pid" pid=$PID_DIR/$PID_NAME echo "CURRENT_DIR="$APP_HOME filelist=`ls $APP_HOME"/"$LIB_DIR"/"*.jar` for f in $filelist do name=$f APPEND_LIB=$APPEND_LIB:$name done case $1 in 'start' ) mkdir -p "$PID_DIR" if [ -f "$pid" ]; then echo $pid existsed, pid: `cat $pid` if kill -0 `cat "$pid"` > /dev/null 2>&1; then echo $PROGRAM_NAME running as process `cat $pid`. Stop it first. exit 1 fi fi echo -n 'Starting : ' if $jcommand $JVM_ARGS $runtype $APPEND_LIB $MAINCLASS $PRO_ARGS > /dev/null 2>&1 & then echo $! > "$pid" echo 'OK' else echo 'Failed' fi ;; 'run' ) $jcommand $JVM_ARGS $runtype $APPEND_LIB $MAINCLASS $PRO_ARGS ;; 'classpath' ) echo $jcommand $JVM_ARGS $runtype $APPEND_LIB $MAINCLASS $PRO_ARGS ;; 'stop' ) if [ -f "$pid" ]; then if kill `cat "$pid"` > /dev/null 2>&1; then echo stopping $PROGRAM_NAME kill `cat "$pid"` rm $pid else echo No $PROGRAM_NAME to stop fi else echo No $PROGRAM_NAME to stop fi ;; 'restart' ) ${0} stop ${0} start ;; 'list' ) ps aux | egrep '(PID|java|$PROGRAM_NAME)' ;; *) echo 'usage: `basename $0` {start|run|stop|list}' esac