2020-05-18 08:08:08 -04:00
|
|
|
#!/usr/bin/env bash
|
2013-10-09 10:45:32 -04:00
|
|
|
|
2021-11-09 10:12:42 -05:00
|
|
|
cd $(dirname $0)/..
|
2021-09-08 05:09:10 -04:00
|
|
|
app_root=$(pwd)
|
|
|
|
sidekiq_workers=${SIDEKIQ_WORKERS:-1}
|
2021-10-11 08:11:56 -04:00
|
|
|
sidekiq_queues=${SIDEKIQ_QUEUES:-*} # Queues to listen to; default to `*` (all)
|
2021-09-08 05:09:10 -04:00
|
|
|
sidekiq_pidfile="$app_root/tmp/pids/sidekiq-cluster.pid"
|
|
|
|
sidekiq_logfile="$app_root/log/sidekiq.log"
|
2021-11-09 10:12:42 -05:00
|
|
|
gitlab_user=$(ls -l config.ru | awk '{print $3}')
|
2013-10-09 10:45:32 -04:00
|
|
|
|
2021-11-01 14:12:42 -04:00
|
|
|
trap cleanup EXIT
|
|
|
|
|
2021-09-08 05:09:10 -04:00
|
|
|
warn()
|
|
|
|
{
|
|
|
|
echo "$@" 1>&2
|
|
|
|
}
|
|
|
|
|
|
|
|
get_sidekiq_pid()
|
|
|
|
{
|
2021-11-09 10:12:42 -05:00
|
|
|
if [ ! -f $sidekiq_pidfile ]; then
|
2021-09-08 05:09:10 -04:00
|
|
|
warn "No pidfile found at $sidekiq_pidfile; is Sidekiq running?"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2021-11-09 10:12:42 -05:00
|
|
|
cat $sidekiq_pidfile
|
2021-09-08 05:09:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
stop()
|
|
|
|
{
|
|
|
|
sidekiq_pid=$(get_sidekiq_pid)
|
|
|
|
|
2021-11-09 10:12:42 -05:00
|
|
|
if [ $sidekiq_pid ]; then
|
|
|
|
kill -TERM $sidekiq_pid
|
2021-09-08 05:09:10 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
restart()
|
|
|
|
{
|
2021-11-09 10:12:42 -05:00
|
|
|
if [ -f $sidekiq_pidfile ]; then
|
2021-09-08 05:09:10 -04:00
|
|
|
stop
|
|
|
|
fi
|
|
|
|
|
2021-10-11 08:11:56 -04:00
|
|
|
start_sidekiq "$@"
|
2021-09-08 05:09:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
start_sidekiq()
|
|
|
|
{
|
|
|
|
cmd="exec"
|
|
|
|
chpst=$(command -v chpst)
|
|
|
|
|
|
|
|
if [ -n "$chpst" ]; then
|
|
|
|
cmd="${cmd} ${chpst} -P"
|
|
|
|
fi
|
|
|
|
|
2021-10-11 08:11:56 -04:00
|
|
|
# sidekiq-cluster expects an argument per process.
|
2021-11-09 10:12:42 -05:00
|
|
|
for (( i=1; i<=$sidekiq_workers; i++ ))
|
2021-09-08 05:09:10 -04:00
|
|
|
do
|
2021-10-11 08:11:56 -04:00
|
|
|
processes_args+=("${sidekiq_queues}")
|
2021-09-08 05:09:10 -04:00
|
|
|
done
|
|
|
|
|
2021-11-09 10:12:42 -05:00
|
|
|
${cmd} bin/sidekiq-cluster "${processes_args[@]}" -P $sidekiq_pidfile -e $RAILS_ENV "$@" 2>&1 | tee -a $sidekiq_logfile
|
2021-09-08 05:09:10 -04:00
|
|
|
}
|
|
|
|
|
2021-11-01 14:12:42 -04:00
|
|
|
cleanup()
|
|
|
|
{
|
|
|
|
stop
|
|
|
|
}
|
|
|
|
|
2021-09-08 05:09:10 -04:00
|
|
|
action="$1"
|
|
|
|
shift
|
|
|
|
|
|
|
|
case "$action" in
|
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
;;
|
|
|
|
start)
|
|
|
|
restart "$@" &
|
|
|
|
;;
|
|
|
|
start_foreground)
|
|
|
|
start_sidekiq "$@"
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
restart "$@" &
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Usage: RAILS_ENV=<env> SIDEKIQ_WORKERS=<n> $0 {stop|start|start_foreground|restart}"
|
|
|
|
esac
|