-
-
Save cloudrck/08dfd4210d0d646e46f4 to your computer and use it in GitHub Desktop.
Debian Sidekiq Init 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
#!/usr/bin/env bash | |
### BEGIN INIT INFO | |
# Provides: sidekiq | |
# Required-Start: $local_fs $network | |
# Required-Stop: $local_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: sidekiq | |
# Description: sidekiq daemon | |
### END INIT INFO | |
# sidekiq Init script for Sidekiq | |
# chkconfig: 345 100 75 | |
# | |
# 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 | |
# | |
# chmod 755 /etc/init.d/sidekiq | |
# update-rc.d sidekiq defaults | |
# | |
# You will need to modify these | |
APP="myapp" | |
AS_USER="myuser" | |
APP_DIR="/var/www/${APP}/current" | |
APP_CONFIG="${APP_DIR}/config" | |
LOG_FILE="$APP_DIR/log/sidekiq.log" | |
LOCK_FILE="$APP_DIR/tmp/sidekiq${APP}-lock" | |
PID_FILE="$APP_DIR/tmp/pids/sidekiq${APP}.pid" | |
SIDEKIQ="sidekiq" | |
APP_ENV="production" | |
BUNDLE="bundle" | |
WORKER_FILE="./boot.rb" | |
START_CMD="$BUNDLE exec $SIDEKIQ -e $APP_ENV -r $WORKER_FILE -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() { | |
status | |
if [ $? -eq 0 ]; then | |
echo "Stopping sidekiq message processor .." | |
SIG="INT" | |
kill -$SIG `cat $PID_FILE` | |
RETVAL=$? | |
[ $RETVAL -eq 0 ] && rm -f $LOCK_FILE | |
return $RETVAL | |
else | |
echo "Sidekiq message processor is stopped already .." | |
fi | |
} | |
status() { | |
ps -ef | grep 'sidekiq [0-9].[0-9].[0-9]' | grep -v grep | |
return $? | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
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