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

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

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

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

Pavel Novitskiy's avatar
Pavel Novitskiy committed
20
start()
21
{
Jacob Vosmaer's avatar
Jacob Vosmaer committed
22 23 24 25 26 27
  $unicorn_cmd -D
}

start_foreground()
{
  $unicorn_cmd
28 29
}

Pavel Novitskiy's avatar
Pavel Novitskiy committed
30
stop()
31 32 33 34 35
{
  get_unicorn_pid
  kill -QUIT $unicorn_pid
}

Pavel Novitskiy's avatar
Pavel Novitskiy committed
36
reload()
37 38 39 40 41 42 43 44 45
{
  get_unicorn_pid
  kill -USR2 $unicorn_pid
}

case "$1" in
  start)
    start
    ;;
Jacob Vosmaer's avatar
Jacob Vosmaer committed
46 47 48
  start_foreground)
    start_foreground
    ;;
49 50 51 52 53 54 55 56 57 58
  stop)
    stop
    ;;
  reload)
    reload
    ;;
  *)
    echo "Usage: RAILS_ENV=your_env $0 {start|stop|reload}"
    ;;
esac