tee_input: allow using Revactor::TCP::Socket objects
[unicorn.git] / examples / init.sh
blob866a644e730426cce7abce838b536325fe614573
1 #!/bin/sh
2 set -u
3 set -e
4 # Example init script, this can be used with nginx, too,
5 # since nginx and unicorn accept the same signals
7 # Feel free to change any of the following variables for your app:
8 APP_ROOT=/home/x/my_app/current
9 PID=$APP_ROOT/tmp/pids/unicorn.pid
10 CMD="/usr/bin/unicorn -D -c $APP_ROOT/config/unicorn.rb"
11 INIT_CONF=$APP_ROOT/config/init.conf
13 test -f "$INIT_CONF" && . $INIT_CONF
15 old_pid="$PID.oldbin"
17 cd $APP_ROOT || exit 1
19 sig () {
20 test -s "$PID" && kill -$1 `cat $PID`
23 oldsig () {
24 test -s $old_pid && kill -$1 `cat $old_pid`
27 case $1 in
28 start)
29 sig 0 && echo >&2 "Already running" && exit 0
30 $CMD
32 stop)
33 sig QUIT && exit 0
34 echo >&2 "Not running"
36 force-stop)
37 sig TERM && exit 0
38 echo >&2 "Not running"
40 restart|reload)
41 sig HUP && echo reloaded OK && exit 0
42 echo >&2 "Couldn't reload, starting '$CMD' instead"
43 $CMD
45 upgrade)
46 sig USR2 && sleep 2 && sig 0 && oldsig QUIT && exit 0
47 echo >&2 "Couldn't upgrade, starting '$CMD' instead"
48 $CMD
51 echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop>"
52 exit 1
54 esac