aeolusproject/conductor

View on GitHub
conf/conductor-delayed_job

Summary

Maintainability
Test Coverage
#!/bin/bash
#
#
# conductor-delayed_job       startup script for conductor-delayed_job
#
# chkconfig: - 99 01
# description: conductor-delayed_job is service for running conductor
#   background jobs

[ -r /etc/sysconfig/conductor-rails ] && . /etc/sysconfig/conductor-rails

[ -r /etc/sysconfig/aeolus-conductor ] && . /etc/sysconfig/aeolus-conductor

RAILS_ENV="${RAILS_ENV:-production}"
CONDUCTOR_DIR="${CONDUCTOR_DIR:-/usr/share/aeolus-conductor}"
AEOLUS_USER="${AEOLUS_USER:-aeolus}"
DJOB_LOCKFILE="${DJOB_LOCKFILE:-/var/lock/subsys/conductor-delayed_job}"
DJOB_PIDDIR="${DJOB_PIDDIR:-/var/run/aeolus-conductor/}"

DJOB_PATH=$CONDUCTOR_DIR/script/
DJOB_PROG=delayed_job
DJOB_DAEMON_COUNT=2

. /etc/init.d/functions

start() {
    echo -n "Starting conductor-delayed_job: "

    daemon --user=$AEOLUS_USER $DJOB_PATH/$DJOB_PROG start -n $DJOB_DAEMON_COUNT --pid-dir=$DJOB_PIDDIR
    RETVAL=$?
    if [ $RETVAL -eq 0 ] && touch $DJOB_LOCKFILE ; then
      echo_success
      echo
    else
      echo_failure
      echo
    fi
}

stop() {
    echo -n "Shutting down conductor-delayed_job: "
    $DJOB_PATH/$DJOB_PROG stop --pid-dir=$DJOB_PIDDIR
    RETVAL=$?
    if [ $RETVAL -eq 0 ] && rm -f $DJOB_LOCKFILE ; then
      echo_success
      echo
    else
      echo_failure
      echo
    fi
}

rh_status() {
    DEAD=0
    for i in $(seq 0 $(($DJOB_DAEMON_COUNT - 1))); do
        status -p $DJOB_PIDDIR/$DJOB_PROG.$i.pid $DJOB_PROG.$i
        DEAD=$(($? | $DEAD))
    done
    return $DEAD
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
      start
     ;;
    stop)
      stop
      ;;
    restart)
      stop
      start
      ;;
    status)
      rh_status
      ;;
    condrestart|try-restart)
      rh_status_q || exit 0
      restart
      ;;
    force-reload)
      restart
      ;;
    *)
      echo "Usage: conductor-delayed_job {start|stop|restart|status}"
      exit 1
  ;;
esac

exit $RETVAL