#!/usr/bin/env bash current_dir=$(cd "$(dirname "$0")"; pwd) cd $current_dir HOME=$current_dir MAINCLASS="manage.py" PRO_ARGS=" " PROGRAM_NAME="pyzoon" PID_DIR="$HOME/start.d" jcommand="python" PID_NAME=$PROGRAM_NAME".pid" pid=$PID_DIR/$PID_NAME echo "CURRENT_DIR="$HOME 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 $MAINCLASS $PRO_ARGS > /dev/null 2>&1 & then echo $! > "$pid" echo 'OK' else echo 'Failed' fi ;; 'run' ) $jcommand $MAINCLASS $PRO_ARGS ;; 'classpath' ) echo $jcommand $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'|'reload') ${0} stop ${0} start ;; 'list' ) ps aux | egrep '(PID|java|$PROGRAM_NAME)' ;; *) echo 'usage: `basename $0` {start|run|classpath|stop|reload|restart|list}' esac