Created
March 28, 2016 20:37
-
-
Save murilomothsin/b2c4c6009ac1a44051f9 to your computer and use it in GitHub Desktop.
Init sidekiq script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chkconfig --add sidekiq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# | |
# sidekiq Init script for sidekiq | |
# | |
# chkconfig: 345 25 75 | |
# description: Starts and stops sidekiq message processor | |
# Source function library. | |
# . /etc/rc.d/init.d/functions | |
# You will need to modify these | |
APP="your_app" | |
AS_USER="your_user" | |
APP_DIR="/home/your_user/${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" | |
# [ -e /etc/sysconfig/sidekiq-your_app ] && . /etc/sysconfig/sidekiq-your_app | |
START_CMD="$BUNDLE exec $SIDEKIQ -e $APP_ENV -P $PID_FILE" | |
CMD="cd ${APP_DIR}; ${START_CMD} >> ${LOG_FILE} 2>&1 &" | |
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 .. " | |
su -c "$CMD" - $AS_USER | |
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() { | |
ps -ef | grep 'sidekiq [0-9].[0-9].[0-9]' | grep -v grep | |
return $? | |
} | |
restart() { | |
stop | |
start | |
} | |
reload() { | |
restart | |
} | |
force_reload() { | |
restart | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
;; | |
reload) | |
;; | |
force_reload) | |
;; | |
status) | |
status | |
if [ $? -eq 0 ]; then | |
echo "$SIDEKIQ message processor is running .." | |
RETVAL=0 | |
else | |
echo "$SIDEKIQ message processor is stopped .." | |
RETVAL=1 | |
fi | |
;; | |
*) | |
echo "Usage: $0 {start|stop|status}" | |
exit 0 | |
;; | |
esac | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment