launcher: get rid of backwards compatibility code
[unicorn.git] / examples / init.sh
blobe4839767ec037a94fb63cd19f9cab502bf95a6d8
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
11 action="$1"
12 set -u
14 test -f "$INIT_CONF" && . $INIT_CONF
16 old_pid="$PID.oldbin"
18 cd $APP_ROOT || exit 1
20 sig () {
21 test -s "$PID" && kill -$1 `cat $PID`
24 oldsig () {
25 test -s $old_pid && kill -$1 `cat $old_pid`
28 case $action in
29 start)
30 sig 0 && echo >&2 "Already running" && exit 0
31 $CMD
33 stop)
34 sig QUIT && exit 0
35 echo >&2 "Not running"
37 force-stop)
38 sig TERM && exit 0
39 echo >&2 "Not running"
41 restart|reload)
42 sig HUP && echo reloaded OK && exit 0
43 echo >&2 "Couldn't reload, starting '$CMD' instead"
44 $CMD
46 upgrade)
47 sig USR2 && sleep 2 && sig 0 && oldsig QUIT && exit 0
48 echo >&2 "Couldn't upgrade, starting '$CMD' instead"
49 $CMD
51 reopen-logs)
52 sig USR1
55 echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
56 exit 1
58 esac