web 910 Bytes
Newer Older
Pavel Novitskiy's avatar
Pavel Novitskiy committed
1
#!/bin/sh
2 3 4 5

cd $(dirname $0)/..
app_root=$(pwd)

6 7 8 9 10
# Switch to experimental PUMA configuration
if [ -n "${EXPERIMENTAL_PUMA}" ]; then
  exec bin/web_puma "$@"
fi

11 12
unicorn_pidfile="$app_root/tmp/pids/unicorn.pid"
unicorn_config="$app_root/config/unicorn.rb"
Jacob Vosmaer's avatar
Jacob Vosmaer committed
13
unicorn_cmd="bundle exec unicorn_rails -c $unicorn_config -E $RAILS_ENV"
14

Pavel Novitskiy's avatar
Pavel Novitskiy committed
15
get_unicorn_pid()
16 17
{
  local pid=$(cat $unicorn_pidfile)
18
  if [ -z "$pid" ] ; then
19 20 21 22 23 24
    echo "Could not find a PID in $unicorn_pidfile"
    exit 1
  fi
  unicorn_pid=$pid
}

Pavel Novitskiy's avatar
Pavel Novitskiy committed
25
start()
26
{
27
  exec $unicorn_cmd -D
Jacob Vosmaer's avatar
Jacob Vosmaer committed
28 29 30 31
}

start_foreground()
{
32
  exec $unicorn_cmd
33 34
}

Pavel Novitskiy's avatar
Pavel Novitskiy committed
35
stop()
36 37 38 39 40
{
  get_unicorn_pid
  kill -QUIT $unicorn_pid
}

Pavel Novitskiy's avatar
Pavel Novitskiy committed
41
reload()
42 43 44 45 46 47 48 49 50
{
  get_unicorn_pid
  kill -USR2 $unicorn_pid
}

case "$1" in
  start)
    start
    ;;
Jacob Vosmaer's avatar
Jacob Vosmaer committed
51 52 53
  start_foreground)
    start_foreground
    ;;
54 55 56 57 58 59 60 61 62 63
  stop)
    stop
    ;;
  reload)
    reload
    ;;
  *)
    echo "Usage: RAILS_ENV=your_env $0 {start|stop|reload}"
    ;;
esac