Skip to content

Instantly share code, notes, and snippets.

@nddeluca
Forked from dyerc/sidekiq
Last active August 29, 2015 14:12
Show Gist options
  • Save nddeluca/c5dac3733d634309c801 to your computer and use it in GitHub Desktop.
Save nddeluca/c5dac3733d634309c801 to your computer and use it in GitHub Desktop.

Revisions

  1. @dyerc dyerc revised this gist Apr 6, 2013. 1 changed file with 5 additions and 7 deletions.
    12 changes: 5 additions & 7 deletions sidekiq
    Original file line number Diff line number Diff line change
    @@ -25,25 +25,23 @@ APP_ENV="production"
    BUNDLE="bundle"

    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
    export RBENV_ROOT="/home/${AS_USER}/.rbenv"

    if [ -d "${RBENV_ROOT}" ]; then
    export PATH="${RBENV_ROOT}/bin:${PATH}"
    eval "$(rbenv init -)"
    fi

    [ `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 &

    su -c "$CMD" - $AS_USER

    RETVAL=$?
    #Sleeping for 8 seconds for process to be precisely visible in process table - See status ()
    sleep 8
  2. @dyerc dyerc created this gist Apr 6, 2013.
    99 changes: 99 additions & 0 deletions sidekiq
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,99 @@
    #!/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="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/${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
    export RBENV_ROOT="/home/${AS_USER}/.rbenv"

    if [ -d "${RBENV_ROOT}" ]; then
    export PATH="${RBENV_ROOT}/bin:${PATH}"
    eval "$(rbenv init -)"
    fi

    [ `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() {

    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