Skip to content

Instantly share code, notes, and snippets.

@imkarthikk
Forked from ponchik/sidekiq.sh
Last active October 12, 2017 19:43

Revisions

  1. @ponchik ponchik renamed this gist Apr 16, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @ponchik ponchik created this gist Apr 16, 2015.
    54 changes: 54 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    #!/bin/bash

    SCRIPT='cd /web/vcms/; bundle exec sidekiq'
    RUNAS=dimon
    NAME=vcms-sidekiq

    PIDFILE=/web/vcms/tmp/pids/sidekiq.pid
    LOGFILE=/web/vcms/log/sidekiq.log

    start() {
    if [ -f $PIDFILE ] && kill -0 $(cat $PIDFILE); then
    echo 'Service already running' >&2
    exit 1
    fi
    echo 'Starting service...' >&2
    cd /web/vcms; sidekiq -d -e production &
    }

    stop() {
    sidekiqctl stop $PIDFILE
    }

    status() {
    printf "%-50s" "Checking $NAME..."
    if [ -f $PIDFILE ]; then
    PID=$(cat $PIDFILE)
    if [ -z "$(ps axf | grep ${PID} | grep -v grep)" ]; then
    printf "%s\n" "The process appears to be dead but pidfile still exists"
    else
    echo "Running, the PID is $PID"
    fi
    else
    printf "%s\n" "Service not running"
    fi
    }


    case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    status)
    status
    ;;
    restart)
    stop
    start
    ;;
    *)
    echo "Usage: $0 {start|stop|status|restart}"
    esac