2013-01-10 01:04:51 -05:00
|
|
|
#!/bin/bash
|
|
|
|
# sidekiq Init script for Sidekiq
|
2013-01-10 01:06:31 -05:00
|
|
|
# chkconfig: 345 100 75
|
2013-01-10 01:04:51 -05:00
|
|
|
#
|
|
|
|
# Description: Starts and Stops Sidekiq message processor for Stratus application.
|
|
|
|
#
|
|
|
|
# User-specified exit parameters used in this script:
|
|
|
|
#
|
|
|
|
# Exit Code 5 - Incorrect User ID
|
|
|
|
# Exit Code 6 - Directory not found
|
|
|
|
|
|
|
|
|
|
|
|
#Variable Set
|
|
|
|
APP="stratus"
|
|
|
|
APP_DIR="/opt/railsapps/${APP}"
|
|
|
|
APP_CONFIG="${APP_DIR}/config"
|
|
|
|
LOG_FILE="$APP_DIR/log/sidekiq.log"
|
|
|
|
LOCK_FILE="$APP_DIR/${APP}-lock"
|
|
|
|
PID_FILE="$APP_DIR/${APP}.pid"
|
|
|
|
GEMFILE="$APP_DIR/Gemfile"
|
|
|
|
SIDEKIQ="sidekiq"
|
|
|
|
APP_ENV="production"
|
|
|
|
BUNDLE="bundle"
|
|
|
|
|
|
|
|
START_CMD="$BUNDLE exec $SIDEKIQ -e $APP_ENV -P $PID_FILE"
|
|
|
|
RETVAL=0
|
|
|
|
|
|
|
|
|
|
|
|
start() {
|
|
|
|
|
|
|
|
status
|
|
|
|
if [ $? -eq 1 ]; then
|
|
|
|
|
|
|
|
[ `id -u` == '0' ] || (echo "$SIDEKIQ runs as root only .."; exit 5)
|
|
|
|
[ -d $APP_DIR ] || (echo "$APP_DIR not found!.. Exiting"; exit 6)
|
|
|
|
cd $APP_DIR
|
|
|
|
echo "Starting $SIDEKIQ message processor .. "
|
|
|
|
$START_CMD >> $LOG_FILE 2>&1 &
|
|
|
|
RETVAL=$?
|
|
|
|
#Sleeping for 8 seconds for process to be precisely visible in process table - See status ()
|
|
|
|
sleep 8
|
|
|
|
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
|
|
|
|
return $RETVAL
|
|
|
|
else
|
|
|
|
echo "$SIDEKIQ message processor is already running .. "
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
|
|
|
|
echo "Stopping $SIDEKIQ message processor .."
|
|
|
|
SIG="INT"
|
|
|
|
kill -$SIG `cat $PID_FILE`
|
|
|
|
RETVAL=$?
|
|
|
|
[ $RETVAL -eq 0 ] && rm -f $LOCK_FILE
|
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status() {
|
|
|
|
|
2013-06-07 12:16:26 -04:00
|
|
|
ps -ef | egrep 'sidekiq [0-9]+.[0-9]+.[0-9]+' | grep -v grep
|
2013-01-10 01:04:51 -05:00
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
;;
|
2014-02-06 05:45:00 -05:00
|
|
|
restart)
|
|
|
|
stop
|
|
|
|
while status > /dev/null
|
|
|
|
do
|
|
|
|
sleep 0.5
|
|
|
|
done
|
|
|
|
start
|
|
|
|
;;
|
2013-01-10 01:04:51 -05:00
|
|
|
status)
|
|
|
|
status
|
|
|
|
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "$SIDEKIQ message processor is running .."
|
|
|
|
RETVAL=0
|
|
|
|
else
|
|
|
|
echo "$SIDEKIQ message processor is stopped .."
|
|
|
|
RETVAL=1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
2014-02-17 17:58:52 -05:00
|
|
|
echo "Usage: $0 {start|stop|restart|status}"
|
2013-01-10 01:04:51 -05:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
exit $RETVAL
|