123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- #!/usr/bin/env bash
- unset CDPATH
- bin=`dirname "$0"`
- bin=`cd "$bin"; pwd`
- cygwin=false
- case "`uname`" in
- CYGWIN*) cygwin=true;;
- esac
- APP_HOME=$bin
- # some Java parameters
- PYTHON=`which python 2>/dev/null`
- if [[ $PY_HOME != "" ]]; then
- PYTHON=$PY_HOME/bin/python
- fi
- if test -z "$PYTHON"; then
- echo "No python found in the PATH. Please install Python and set PY_HOME."
- exit 1
- fi
- DEF_APP_NAME=yiistock-server
-
- # restore ordinary behaviour
- # unset IFS
- CLASS=yiis/manage.py
- export PYTHONPATH=$APP_HOME
- # run it
- COMMAND=$1
- PID_DIR="$APP_HOME/start.d"
- PID_NAME="$DEF_APP_NAME.pid"
- PID_FILE="$PID_DIR/$PID_NAME"
- start(){
- mkdir -p "$PID_DIR"
- if [ -f "$PID_FILE" ]; then
- echo $PID_FILE existsed, pid: `cat $PID_FILE`
- if kill -0 `cat "$PID_FILE"` > /dev/null 2>&1; then
- echo $DEF_APP_NAME running as process `cat $PID_FILE`. Stop it first.
- exit 1
- fi
- fi
- echo "starting $DEF_APP_NAME ..."
- if "$PYTHON" $APP_HOME/$CLASS "$@" >/dev/null 2>&1 &
- then
- echo $! > "$PID_FILE"
- echo "$DEF_APP_NAME has started! "
- else
- echo "$DEF_APP_NAME has start Failed"
- fi
- }
- run(){
- echo "run $DEF_APP_NAME"
- exec "$PYTHON" $APP_HOME/$CLASS "$@"
- }
- stop(){
- if [ -f "$PID_FILE" ]; then
- if kill `cat $PID_FILE` > /dev/null 2>&1; then
- echo "stop $DEF_APP_NAME ..."
- kill `cat $PID_FILE`
- rm $PID_FILE
- else
- echo No $DEF_APP_NAME to stop
- fi
- else
- echo No $DEF_APP_NAME to stop
- fi
- }
- status(){
- mkdir -p "$PID_DIR"
- if [ -f "$PID_FILE" ]; then
- echo $PID_FILE existsed, pid: `cat $PID_FILE`
- if kill -0 `cat "$PID_FILE"` > /dev/null 2>&1;
- then
- echo $DEF_APP_NAME [`cat $PID_FILE`] is running.
- exit 0
- else
- echo "$DEF_APP_NAME is not running"
- exit 0
- fi
- fi
- }
- docommand() {
- case "$COMMAND" in
- 'start')
- start
- ;;
- 'run')
- run
- ;;
- 'stop')
- stop
- ;;
- 'restart')
- stop;
- sleep 5
- start;
- ;;
- 'status')
- status
- ;;
- *)
- echo "usage: [start|run|stop|restart|status|log]"
- ;;
- esac
- }
- docommand "$@"
- exit 0
|