mperham/sidekiq — Issue #30: Start sidekiq with config file
Author: jc00ke
Created: 2012-02-15 03:16:35+00:00
State: open

It would be nice to start Sidekiq with a config file, especially on EY. Since Sidekiq doesn't kick out a PID file, it's hard/impossible to manage with monit. I got something working today on my current project that I'll be able to publish, but as of now I wouldn't be able to easily pass in configuration options.

```sh
#!/bin/sh
#
# This script starts and stops the Sidekiq daemon
# This script belongs in /engineyard/bin/sidekiq
#

PATH=/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
CURDIR=`pwd`

usage() {
echo "Usage: $0 {start|stop|term|quit|pause|cont|abort} "
echo -e "\nstop) is a synonym for quit"
echo "quit) issues -QUIT to request the worker to stop"
echo "term) issues -TERM to request the worker to stop"
echo "pause) issues -USR2 when the current job finishes, worker remains running, but doesn't start any new jobs"
echo "cont) issues -CONT to continue after pausing"
echo "abort) issues -USR1 kills current job, or shuts down if there is no job"
echo "see https://github.com/mperham/sidekiq for more details"
echo -e "\nSet the GRACE_TIME env variable to configure how long we should wait for after issuing quit, before asumming a problem and killing the worker and job"
exit 1
}

...

#Baisc Setup of default values
APP=$1 ; ACTION=$2; RACK_ENV=$3; CONF_FILE=$4;

APP_DIR="/data/${APP}"
APP_ROOT="${APP_DIR}/current"
APP_SHARED="${APP_DIR}/shared"
APP_CONFIG="${APP_SHARED}/config"

if [ -e "${APP_CONFIG}/${CONF_FILE}" ]; then
logger -t "sidekiq_${APP}" -s "Good, found a conf file. Proceeding..."
else
logger -t "sidekiq_${APP}" -s "/data/${APP}/shared/config/${CONF_FILE} not found for app: ${APP}"
exit 1
fi

WORKER_REF=`echo $CONF_FILE | sed s/.conf//`
LOG_FILE="$APP_ROOT/log/$WORKER_REF.log"
LOCK_FILE="/tmp/$WORKER_REF.monit-lock"
PID_FILE="/var/run/engineyard/sidekiq/$APP/$WORKER_REF.pid"
GEMFILE="$APP_ROOT/Gemfile"
SIDEKIQ="sidekiq"
if [ -f $GEMFILE ];then
SIDEKIQ="bundle exec $APP_ROOT/ey_bundler_binstubs/sidekiq"
fi

if [ -d $APP_ROOT ]; then
USER=$(stat -L -c"%U" $APP_ROOT)
export HOME="/home/$USER"

# Fix for SD-3786 - stop sending in VERBOSE= and VVERBOSE= by default
if declare -p VERBOSE >/dev/null 2>&1; then export V="VERBOSE=$VERBOSE"; fi
if declare -p VVERBOSE >/dev/null 2>&1; then export VV="VVERBOSE=$VVERBOSE"; fi

# Older versions of sudo need us to call env for the env vars to be set correctly
COMMAND="/usr/bin/env $V $VV APP_ROOT=${APP_ROOT} RACK_ENV=${RACK_ENV} RAILS_ENV=${RACK_ENV} MERB_ENV=${RACK_ENV} QUEUE=${QUEUE} $SIDEKIQ -e ${RACK_ENV}"

...
```

The conf file argument to the script is used by monit to find the PID. I don't see a way around having this conf file, so, it would be nice to pass that conf file in to Sidekiq to set the CLI options. Otherwise I'm going to have to parse the conf file in bash, which I'd rather not do.

If you're ok with this, I'd like to work on it. It'd be nice to contribute more to this project than just some examples. :smile: