123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- #! /bin/sh
- ### BEGIN INIT INFO
- # Provides: crunchd
- # Required-Start:
- # Required-Stop:
- # Default-Start: 2 3 4 5
- # Default-Stop: 1
- # Short-Description: crunchy task worker daemon
- ### END INIT INFO
- set -e
- VIRTUALENV=/opt/Opal/current
- DJANGO_PROJECT_DIR=/opt/Opal/release/opal
- DJANGO_SETTINGS_MODULE=settings
- CRUNCHD_PID_FILE="/var/run/crunchd.pid"
- CRUNCHD_LOG_FILE="/var/log/crunchd.log"
- CRUNCHD_LOG_LEVEL="INFO"
- CRUNCHD="crunchd"
- export DJANGO_SETTINGS_MODULE
- # /etc/init.d/ssh: start and stop the crunchy task worker daemon.
- test -x "$CRUNCHD" || exit 0
- if test -f /etc/default/crunchd; then
- . /etc/default/crunchd
- fi
- . /lib/lsb/init-functions
- chdir $DJANGO_PROJECT_DIR
- CRUNCHD_OPTS="-f $CRUNCHD_LOG_FILE -l $CRUNCHD_LOG_LEVEL -p \
- $CRUNCHD_PID_FILE -d"
- if [ -n "$2" ]; then
- CRUNCHD_OPTS="$CRUNCHD_OPTS $2"
- fi
- # Are we running from init?
- run_by_init() {
- ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ]
- }
- check_dev_null() {
- if [ ! -c /dev/null ]; then
- if [ "$1" = log_end_msg ]; then
- log_end_msg 1 || true
- fi
- if ! run_by_init; then
- log_action_msg "/dev/null is not a character device!"
- fi
- exit 1
- fi
- }
- export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
- if [ ! -n "$VIRTUALENV" ]; then
- . "$VIRTUALENV/current/bin/activate"
- export PATH="$VIRTUALENV/current/bin:$PATH"
- fi
- case "$1" in
- start)
- check_dev_null
- log_daemon_msg "Starting crunchy task worker server" "crunchd"
- if start-stop-daemon --start --quiet --oknodo --pidfile $CRUNCHD_PID_FILE --exec $CRUNCHD -- $CRUNCHD_OPTS; then
- log_end_msg 0
- else
- log_end_msg 1
- fi
- ;;
- stop)
- log_daemon_msg "Stopping crunchy task worker server" "crunchd"
- if start-stop-daemon --stop --quiet --oknodo --pidfile $CRUNCHD_PID_FILE; then log_end_msg 0
- else
- log_end_msg 1
- fi
- ;;
- reload|force-reload)
- echo "Use start+stop"
- ;;
- restart)
- log_daemon_msg "Restarting crunchgy task worker server" "crunchd"
- start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $CRUNCHD_PID_FILE
- check_for_no_start log_end_msg
- check_dev_null log_end_msg
- if start-stop-daemon --start --quiet --oknodo --pidfile $CRUNCHD_PID_FILE --exec $CRUNCHD -- $CRUNCHD_OPTS; then
- log_end_msg 0
- else
- log_end_msg 1
- fi
- ;;
- try-restart)
- log_daemon_msg "Restarting crunchy task worker server" "crunchd"
- set +e
- start-stop-daemon --stop --quiet --retry 30 --pidfile $CRUNCHD_PID_FILE
- RET="$?"
- set -e
- case $RET in
- 0)
- # old daemon stopped
- check_dev_null log_end_msg
- if start-stop-daemon --start --quiet --oknodo --pidfile $CRUNCHD_PID_FILE --exec $CRUNCHD -- $CRUNCHD_OPTS; then
- log_end_msg 0
- else
- log_end_msg 1
- fi
- ;;
- 1)
- # daemon not running
- log_progress_msg "(not running)"
- log_end_msg 0
- ;;
- *)
- # failed to stop
- log_progress_msg "(failed to stop)"
- log_end_msg 1
- ;;
- esac
- ;;
- status)
- status_of_proc -p $CRUNCHD_PID_FILE $CRUNCHD crunchd && exit 0 || exit $?
- ;;
- *)
- log_action_msg "Usage: /etc/init.d/crunchd {start|stop|force-reload|restart|try-restart|status}"
- exit 1
- esac
- exit 0
|