Skip to content

Instantly share code, notes, and snippets.

@aks
Created March 8, 2018 21:59
Show Gist options
  • Select an option

  • Save aks/eb05452e26b294bbc5900cf503fe8ceb to your computer and use it in GitHub Desktop.

Select an option

Save aks/eb05452e26b294bbc5900cf503fe8ceb to your computer and use it in GitHub Desktop.
Bash scripts to make it easy to start, stop, and watch sidekiq server
#!/bin/bash
PROG="${0##*/}"
def_config="-C config/sidekiq.yml"
def_log="-L log/sidekiq.log"
def_pid="-P tmp/pids/sidekiq.pid"
def_queue="-q data_migration"
usage() {
cat <<MSG
$PROG [options]
Start sidekiq with some default options, unless overridden.
These are the defaults:
$def_config
$def_log
$def_pid
$def_queue
Options:
-c INT concurrency count (# processor threads)
-C CONFIG path to YAML config file
-d daemonize (background)
-e ENV application environment
-g TAG Process tag for procline
-h show the help
-i INT unique process index on this machine
-L LOGFILE path to writable logfile
-n norun -- show but do not run the effective command
-P PIDFILE path to pid file
-q QUEUE[,WEIGHT] Queues to process with optional weights
-r [PATH|DIR] Rails app dir with workers or file to require
-t TIMEOUT Shutdown timeout
-v Be more verbose
-V Show the version and exit
MSG
exit
}
version() {
bundle exec sidekiq --version
}
show_cmd() {
printf 1>&2 "%s %s\n" "$1" "$2"
}
add_default() {
if [[ -n "$1" ]] ; then
opts+=" $1"
fi
}
opts=''
while getopts 'c:C:de:hg:i:L:nP:q:r:t:Vv' opt ; do
case "$opt" in
d) opts+=" -d" ;;
C) opts+=" -C '$OPTARG'" def_config= ;;
L) opts+=" -L '$OPTARG'" def_log= ;;
n) norun=1 ;;
P) opts+=" -P '$OPTARG'" def_pid= ;;
q) opts+=" -q '$OPTARG'" def_queue= ;;
h) usage ;;
V) version ;;
v) verbose=1 opts+=' -v' ;;
[cegirt]) opts+=" -$opt '$OPTARG'" ;;
*) usage ;;
esac
done
shift $(( OPTIND - 1 ))
add_default "$def_config"
add_default "$def_log"
add_default "$def_pid"
add_default "$def_queue"
cmd="bundle exec bin/sidekiq $opts"
if (( norun )) ; then
show_cmd "(norun)" "$cmd"
else
if (( verbose )); then
show_cmd "-->" "$cmd"
fi
eval "$cmd"
fi
exit
#!/bin/bash
bundle exec bin/sidekiqctl stop tmp/pids/sidekiq.pid
#!/bin/bash
tail -f log/sidekiq.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment