launcher.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/usr/bin/env bash
  2. unset CDPATH
  3. bin=`dirname "$0"`
  4. bin=`cd "$bin"; pwd`
  5. cygwin=false
  6. case "`uname`" in
  7. CYGWIN*) cygwin=true;;
  8. esac
  9. APP_HOME=$bin
  10. # some Java parameters
  11. PYTHON=`which python 2>/dev/null`
  12. if [[ $PY_HOME != "" ]]; then
  13. PYTHON=$PY_HOME/bin/python
  14. fi
  15. if test -z "$PYTHON"; then
  16. echo "No python found in the PATH. Please install Python and set PY_HOME."
  17. exit 1
  18. fi
  19. DEF_APP_NAME=yiistock-server
  20. # restore ordinary behaviour
  21. # unset IFS
  22. CLASS=yiis/manage.py
  23. export PYTHONPATH=$APP_HOME
  24. # run it
  25. COMMAND=$1
  26. PID_DIR="$APP_HOME/start.d"
  27. PID_NAME="$DEF_APP_NAME.pid"
  28. PID_FILE="$PID_DIR/$PID_NAME"
  29. start(){
  30. mkdir -p "$PID_DIR"
  31. if [ -f "$PID_FILE" ]; then
  32. echo $PID_FILE existsed, pid: `cat $PID_FILE`
  33. if kill -0 `cat "$PID_FILE"` > /dev/null 2>&1; then
  34. echo $DEF_APP_NAME running as process `cat $PID_FILE`. Stop it first.
  35. exit 1
  36. fi
  37. fi
  38. echo "starting $DEF_APP_NAME ..."
  39. if "$PYTHON" $APP_HOME/$CLASS "$@" >/dev/null 2>&1 &
  40. then
  41. echo $! > "$PID_FILE"
  42. echo "$DEF_APP_NAME has started! "
  43. else
  44. echo "$DEF_APP_NAME has start Failed"
  45. fi
  46. }
  47. run(){
  48. echo "run $DEF_APP_NAME"
  49. exec "$PYTHON" $APP_HOME/$CLASS "$@"
  50. }
  51. stop(){
  52. if [ -f "$PID_FILE" ]; then
  53. if kill `cat $PID_FILE` > /dev/null 2>&1; then
  54. echo "stop $DEF_APP_NAME ..."
  55. kill `cat $PID_FILE`
  56. rm $PID_FILE
  57. else
  58. echo No $DEF_APP_NAME to stop
  59. fi
  60. else
  61. echo No $DEF_APP_NAME to stop
  62. fi
  63. }
  64. status(){
  65. mkdir -p "$PID_DIR"
  66. if [ -f "$PID_FILE" ]; then
  67. echo $PID_FILE existsed, pid: `cat $PID_FILE`
  68. if kill -0 `cat "$PID_FILE"` > /dev/null 2>&1;
  69. then
  70. echo $DEF_APP_NAME [`cat $PID_FILE`] is running.
  71. exit 0
  72. else
  73. echo "$DEF_APP_NAME is not running"
  74. exit 0
  75. fi
  76. fi
  77. }
  78. docommand() {
  79. case "$COMMAND" in
  80. 'start')
  81. start
  82. ;;
  83. 'run')
  84. run
  85. ;;
  86. 'stop')
  87. stop
  88. ;;
  89. 'restart')
  90. stop;
  91. sleep 5
  92. start;
  93. ;;
  94. 'status')
  95. status
  96. ;;
  97. *)
  98. echo "usage: [start|run|stop|restart|status|log]"
  99. ;;
  100. esac
  101. }
  102. docommand "$@"
  103. exit 0