pyzoon.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env bash
  2. current_dir=$(cd "$(dirname "$0")"; pwd)
  3. cd $current_dir
  4. HOME=$current_dir
  5. MAINCLASS="manage.py"
  6. PRO_ARGS=" "
  7. PROGRAM_NAME="pyzoon"
  8. PID_DIR="$HOME/start.d"
  9. jcommand="python"
  10. PID_NAME=$PROGRAM_NAME".pid"
  11. pid=$PID_DIR/$PID_NAME
  12. echo "CURRENT_DIR="$HOME
  13. case $1 in
  14. 'start' )
  15. mkdir -p "$PID_DIR"
  16. if [ -f "$pid" ]; then
  17. echo $pid existsed, pid: `cat $pid`
  18. if kill -0 `cat "$pid"` > /dev/null 2>&1; then
  19. echo $PROGRAM_NAME running as process `cat $pid`. Stop it first.
  20. exit 1
  21. fi
  22. fi
  23. echo -n 'Starting : '
  24. if $jcommand $MAINCLASS $PRO_ARGS > /dev/null 2>&1 &
  25. then
  26. echo $! > "$pid"
  27. echo 'OK'
  28. else
  29. echo 'Failed'
  30. fi
  31. ;;
  32. 'run' )
  33. $jcommand $MAINCLASS $PRO_ARGS
  34. ;;
  35. 'classpath' )
  36. echo $jcommand $MAINCLASS $PRO_ARGS
  37. ;;
  38. 'stop' )
  39. if [ -f "$pid" ]; then
  40. if kill `cat "$pid"` > /dev/null 2>&1; then
  41. echo stopping $PROGRAM_NAME
  42. kill `cat "$pid"`
  43. rm $pid
  44. else
  45. echo No $PROGRAM_NAME to stop
  46. fi
  47. else
  48. echo No $PROGRAM_NAME to stop
  49. fi
  50. ;;
  51. 'restart'|'reload')
  52. ${0} stop
  53. ${0} start
  54. ;;
  55. 'list' )
  56. ps aux | egrep '(PID|java|$PROGRAM_NAME)'
  57. ;;
  58. *)
  59. echo 'usage: `basename $0` {start|run|classpath|stop|reload|restart|list}'
  60. esac