vim /etc/init.d/sidekiq
Copy and paste the code below and change appropriately Save and exit (ESC + :wq)
sudo update-rc.d sidekiq defaults
sudo service sidekiq start
sudo service sidekiq status
| #!/bin/bash | |
| # 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 | |
| # You will need to modify these | |
| APP="{{ app_name }}" | |
| AS_USER="{{ deploy_user }}" | |
| APP_DIR="{{ app_directory }}" | |
| LOG_FILE="$APP_DIR/log/sidekiq.log" | |
| LOCK_FILE="$APP_DIR/tmp/pids/sidekiq-${APP}-lock" | |
| PID_FILE="$APP_DIR/tmp/pids/sidekiq-${APP}.pid" | |
| SIDEKIQ="sidekiq" | |
| APP_ENV="production" | |
| BUNDLE="bundle" | |
| START_CMD="$BUNDLE exec $SIDEKIQ -e $APP_ENV -P $PID_FILE -C ${APP_DIR}/config/sidekiq.yml" | |
| CMD="cd ${APP_DIR}; ${START_CMD} >> ${LOG_FILE} 2>&1 &" | |
| RETVAL=0 | |
| start() { | |
| status | |
| if [ $? -eq 1 ]; then | |
| [ `id -u` == '0' ] || (echo >&2 "$SIDEKIQ runs as root only ..."; exit 5) | |
| [ -d $APP_DIR ] || (echo >&2 "$APP_DIR not found!... Exiting"; exit 6) | |
| cd $APP_DIR | |
| echo >&2 "Starting $SIDEKIQ message processor ..." | |
| su -c "$CMD" - $AS_USER | |
| RETVAL=$? | |
| sleep 8 | |
| [ $RETVAL -eq 0 ] && touch $LOCK_FILE | |
| return $RETVAL | |
| else | |
| echo >&2 "$SIDEKIQ message processor is already running ..." | |
| fi | |
| } | |
| stop() { | |
| status | |
| if [ $? -eq 0 ]; then | |
| echo >&2 "Stopping sidekiq message processor ..." | |
| SIG="INT" | |
| kill -$SIG `cat $PID_FILE` | |
| RETVAL=$? | |
| [ $RETVAL -eq 0 ] && rm -f $LOCK_FILE | |
| return $RETVAL | |
| else | |
| echo >&2 "Sidekiq message processor is stopped already ..." | |
| fi | |
| } | |
| status() { | |
| ps -ef | grep 'sidekiq [0-9].[0-9].[0-9]' | grep -v grep | |
| return $? | |
| } | |
| restart() { | |
| if [ -f $LOCK_FILE ]; then | |
| stop | |
| fi | |
| echo >&2 "Waiting while stopping ..." | |
| sleep 4 | |
| start | |
| } | |
| case "$1" in | |
| start) | |
| start | |
| ;; | |
| stop) | |
| stop | |
| ;; | |
| restart) | |
| restart | |
| ;; | |
| status) | |
| status | |
| if [ $? -eq 0 ]; then | |
| echo >&2 "$SIDEKIQ message processor is running ..." | |
| RETVAL=0 | |
| else | |
| echo >&2 "$SIDEKIQ message processor is stopped ..." | |
| RETVAL=1 | |
| fi | |
| ;; | |
| *) | |
| echo >&2 "Usage: $0 {start|stop|restart|status}" | |
| exit 0 | |
| ;; | |
| esac | |
| exit $RETVAL |