BigW Consortium Gitlab

background_jobs 1.36 KB
Newer Older
Pavel Novitskiy committed
1
#!/bin/sh
2 3 4 5 6

cd $(dirname $0)/..
app_root=$(pwd)
sidekiq_pidfile="$app_root/tmp/pids/sidekiq.pid"
sidekiq_logfile="$app_root/log/sidekiq.log"
7
sidekiq_config="$app_root/config/sidekiq_queues.yml"
8 9
gitlab_user=$(ls -l config.ru | awk '{print $3}')

Pavel Novitskiy committed
10
warn()
11 12 13 14
{
  echo "$@" 1>&2
}

Pavel Novitskiy committed
15
stop()
16
{
17
  bundle exec sidekiqctl stop $sidekiq_pidfile >> $sidekiq_logfile 2>&1
18 19
}

Pavel Novitskiy committed
20
killall()
21
{
22
  pkill -u $gitlab_user -f 'sidekiq [0-9]'
23 24
}

Pavel Novitskiy committed
25
restart()
26 27 28 29 30
{
  if [ -f $sidekiq_pidfile ]; then
    stop
  fi
  killall
31
  start_sidekiq -d -L $sidekiq_logfile >> $sidekiq_logfile 2>&1
32 33
}

Pavel Novitskiy committed
34
start_no_deamonize()
35
{
Jacob Vosmaer committed
36
  start_sidekiq >> $sidekiq_logfile 2>&1
37 38
}

Pavel Novitskiy committed
39
start_sidekiq()
40
{
41
  exec bundle exec sidekiq -C "${sidekiq_config}" -e $RAILS_ENV -P $sidekiq_pidfile "$@"
42 43
}

Pavel Novitskiy committed
44
load_ok()
45 46
{
  sidekiq_pid=$(cat $sidekiq_pidfile)
47
  if [ -z "$sidekiq_pid" ] ; then
48 49 50 51 52 53 54 55 56 57 58 59
    warn "Could not find a PID in $sidekiq_pidfile"
    exit 0
  fi

  if (ps -p $sidekiq_pid -o args | grep '\([0-9]\+\) of \1 busy' 1>&2) ; then
    warn "Too many busy Sidekiq workers"
    exit 1
  fi

  exit 0
}

60 61 62 63 64 65 66 67 68 69
case "$1" in
  stop)
    stop
    ;;
  start)
    restart
    ;;
  start_no_deamonize)
    start_no_deamonize
    ;;
Jacob Vosmaer committed
70 71 72
  start_foreground)
    start_sidekiq
    ;;
73 74 75 76 77 78
  restart)
    restart
    ;;
  killall)
    killall
    ;;
79 80 81
  load_ok)
    load_ok
    ;;
82
  *)
83
    echo "Usage: RAILS_ENV=your_env $0 {stop|start|start_no_deamonize|restart|killall|load_ok}"
84
esac