bump version to 0.97.0pre
[unicorn.git] / examples / init.sh
blob35ec896efe3b197cb4a86630ac6ea44ddde7a5af
1 #!/bin/sh
2 set -e
3 # Example init script, this can be used with nginx, too,
4 # since nginx and unicorn accept the same signals
6 # Feel free to change any of the following variables for your app:
7 APP_ROOT=/home/x/my_app/current
8 PID=$APP_ROOT/tmp/pids/unicorn.pid
9 CMD="/usr/bin/unicorn -D -c $APP_ROOT/config/unicorn.rb"
10 INIT_CONF=$APP_ROOT/config/init.conf
12 test -f "$INIT_CONF" && . $INIT_CONF
14 old_pid="$PID.oldbin"
16 cd $APP_ROOT || exit 1
18 sig () {
19 test -s "$PID" && kill -$1 `cat $PID`
22 oldsig () {
23 test -s $old_pid && kill -$1 `cat $old_pid`
26 case $1 in
27 start)
28 sig 0 && echo >&2 "Already running" && exit 0
29 $CMD
31 stop)
32 sig QUIT && exit 0
33 echo >&2 "Not running"
35 force-stop)
36 sig TERM && exit 0
37 echo >&2 "Not running"
39 restart|reload)
40 sig HUP && echo reloaded OK && exit 0
41 echo >&2 "Couldn't reload, starting '$CMD' instead"
42 $CMD
44 upgrade)
45 sig USR2 && sleep 2 && sig 0 && oldsig QUIT && exit 0
46 echo >&2 "Couldn't upgrade, starting '$CMD' instead"
47 $CMD
50 echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop>"
51 exit 1
53 esac