crunchd 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: crunchd
  4. # Required-Start:
  5. # Required-Stop:
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 1
  8. # Short-Description: crunchy task worker daemon
  9. ### END INIT INFO
  10. set -e
  11. VIRTUALENV=/opt/Opal/current
  12. DJANGO_PROJECT_DIR=/opt/Opal/release/opal
  13. DJANGO_SETTINGS_MODULE=settings
  14. CRUNCHD_PID_FILE="/var/run/crunchd.pid"
  15. CRUNCHD_LOG_FILE="/var/log/crunchd.log"
  16. CRUNCHD_LOG_LEVEL="INFO"
  17. CRUNCHD="crunchd"
  18. export DJANGO_SETTINGS_MODULE
  19. # /etc/init.d/ssh: start and stop the crunchy task worker daemon.
  20. test -x "$CRUNCHD" || exit 0
  21. if test -f /etc/default/crunchd; then
  22. . /etc/default/crunchd
  23. fi
  24. . /lib/lsb/init-functions
  25. chdir $DJANGO_PROJECT_DIR
  26. CRUNCHD_OPTS="-f $CRUNCHD_LOG_FILE -l $CRUNCHD_LOG_LEVEL -p \
  27. $CRUNCHD_PID_FILE -d"
  28. if [ -n "$2" ]; then
  29. CRUNCHD_OPTS="$CRUNCHD_OPTS $2"
  30. fi
  31. # Are we running from init?
  32. run_by_init() {
  33. ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ]
  34. }
  35. check_dev_null() {
  36. if [ ! -c /dev/null ]; then
  37. if [ "$1" = log_end_msg ]; then
  38. log_end_msg 1 || true
  39. fi
  40. if ! run_by_init; then
  41. log_action_msg "/dev/null is not a character device!"
  42. fi
  43. exit 1
  44. fi
  45. }
  46. export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
  47. if [ ! -n "$VIRTUALENV" ]; then
  48. . "$VIRTUALENV/current/bin/activate"
  49. export PATH="$VIRTUALENV/current/bin:$PATH"
  50. fi
  51. case "$1" in
  52. start)
  53. check_dev_null
  54. log_daemon_msg "Starting crunchy task worker server" "crunchd"
  55. if start-stop-daemon --start --quiet --oknodo --pidfile $CRUNCHD_PID_FILE --exec $CRUNCHD -- $CRUNCHD_OPTS; then
  56. log_end_msg 0
  57. else
  58. log_end_msg 1
  59. fi
  60. ;;
  61. stop)
  62. log_daemon_msg "Stopping crunchy task worker server" "crunchd"
  63. if start-stop-daemon --stop --quiet --oknodo --pidfile $CRUNCHD_PID_FILE; then log_end_msg 0
  64. else
  65. log_end_msg 1
  66. fi
  67. ;;
  68. reload|force-reload)
  69. echo "Use start+stop"
  70. ;;
  71. restart)
  72. log_daemon_msg "Restarting crunchgy task worker server" "crunchd"
  73. start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $CRUNCHD_PID_FILE
  74. check_for_no_start log_end_msg
  75. check_dev_null log_end_msg
  76. if start-stop-daemon --start --quiet --oknodo --pidfile $CRUNCHD_PID_FILE --exec $CRUNCHD -- $CRUNCHD_OPTS; then
  77. log_end_msg 0
  78. else
  79. log_end_msg 1
  80. fi
  81. ;;
  82. try-restart)
  83. log_daemon_msg "Restarting crunchy task worker server" "crunchd"
  84. set +e
  85. start-stop-daemon --stop --quiet --retry 30 --pidfile $CRUNCHD_PID_FILE
  86. RET="$?"
  87. set -e
  88. case $RET in
  89. 0)
  90. # old daemon stopped
  91. check_dev_null log_end_msg
  92. if start-stop-daemon --start --quiet --oknodo --pidfile $CRUNCHD_PID_FILE --exec $CRUNCHD -- $CRUNCHD_OPTS; then
  93. log_end_msg 0
  94. else
  95. log_end_msg 1
  96. fi
  97. ;;
  98. 1)
  99. # daemon not running
  100. log_progress_msg "(not running)"
  101. log_end_msg 0
  102. ;;
  103. *)
  104. # failed to stop
  105. log_progress_msg "(failed to stop)"
  106. log_end_msg 1
  107. ;;
  108. esac
  109. ;;
  110. status)
  111. status_of_proc -p $CRUNCHD_PID_FILE $CRUNCHD crunchd && exit 0 || exit $?
  112. ;;
  113. *)
  114. log_action_msg "Usage: /etc/init.d/crunchd {start|stop|force-reload|restart|try-restart|status}"
  115. exit 1
  116. esac
  117. exit 0