5 # Required-Start: $local_fs $network
6 # Required-Stop: $local_fs $network
7 # Default-Start: 2 3 4 5
9 # Short-Description: Start/stop unicorn Rack app server
12 # Example init script, this can be used with nginx, too,
13 # since nginx and unicorn accept the same signals.
15 # Feel free to change any of the following variables for your app:
17 APP_ROOT
=/home
/x
/my_app
/current
18 PID
=$APP_ROOT/tmp
/pids
/unicorn.pid
19 CMD
="/usr/bin/unicorn -D -c $APP_ROOT/config/unicorn.rb"
20 INIT_CONF
=$APP_ROOT/config
/init.conf
21 UPGRADE_DELAY
=${UPGRADE_DELAY-2}
25 test -f "$INIT_CONF" && .
$INIT_CONF
29 cd $APP_ROOT ||
exit 1
32 test -s "$PID" && kill -$1 $
(cat $PID)
36 test -s "$OLD" && kill -$1 $
(cat $OLD)
41 sig
0 && echo >&2 "Already running" && exit 0
46 echo >&2 "Not running"
50 echo >&2 "Not running"
53 sig HUP
&& echo reloaded OK
&& exit 0
54 echo >&2 "Couldn't reload, starting '$CMD' instead"
60 echo >&2 "Old upgraded process still running with $OLD"
70 if test -n "$cur_pid" &&
71 kill -USR2 "$cur_pid" &&
72 sleep $UPGRADE_DELAY &&
73 new_pid
=$
(cat $PID) &&
74 test x
"$new_pid" != x
"$cur_pid" &&
79 while kill -0 "$cur_pid" 2>/dev
/null
&& test $n -ge 0
81 printf '.' && sleep 1 && n
=$
(( $n - 1 ))
85 if test $n -lt 0 && kill -0 "$cur_pid" 2>/dev
/null
87 echo >&2 "$cur_pid still running after $TIMEOUT seconds"
92 echo >&2 "Couldn't upgrade, starting '$CMD' instead"
99 echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"