don't set listen(2) backlog on inherited sockets
[yahns.git] / examples / init.sh
blob6fe1ae662649960ed4bdc47791c449b27542e52f
1 #!/bin/sh
2 # To the extent possible under law, Eric Wong has waived all copyright and
3 # related or neighboring rights to this examples
4 set -e
5 ### BEGIN INIT INFO
6 # Provides: yahns
7 # Required-Start: $local_fs $network
8 # Required-Stop: $local_fs $network
9 # Default-Start: 2 3 4 5
10 # Default-Stop: 0 1 6
11 # Short-Description: Start/stop yahns Ruby app server
12 ### END INIT INFO
14 # Feel free to change any of the following variables for your app:
15 TIMEOUT=${TIMEOUT-60}
16 APP_ROOT=/home/x/my_app/current
17 PID=$APP_ROOT/tmp/pids/yahns.pid
18 CMD="/usr/bin/yahns -D -c $APP_ROOT/config/yahns.rb"
19 INIT_CONF=$APP_ROOT/config/init.conf
20 UPGRADE_DELAY=${UPGRADE_DELAY-2}
21 action="$1"
22 set -u
24 test -f "$INIT_CONF" && . $INIT_CONF
26 OLD="$PID.oldbin"
28 cd $APP_ROOT || exit 1
30 sig () {
31 test -s "$PID" && kill -$1 $(cat $PID)
34 oldsig () {
35 test -s "$OLD" && kill -$1 $(cat $OLD)
38 case $action in
39 start)
40 sig 0 && echo >&2 "Already running" && exit 0
41 $CMD
43 stop)
44 sig QUIT && exit 0
45 echo >&2 "Not running"
47 force-stop)
48 sig TERM && exit 0
49 echo >&2 "Not running"
51 restart|reload)
52 sig HUP && echo reloaded OK && exit 0
53 echo >&2 "Couldn't reload, starting '$CMD' instead"
54 $CMD
56 upgrade)
57 if oldsig 0
58 then
59 echo >&2 "Old upgraded process still running with $OLD"
60 exit 1
63 cur_pid=
64 if test -s "$PID"
65 then
66 cur_pid=$(cat $PID)
69 if test -n "$cur_pid" &&
70 kill -USR2 "$cur_pid" &&
71 sleep $UPGRADE_DELAY &&
72 new_pid=$(cat $PID) &&
73 test x"$new_pid" != x"$cur_pid" &&
74 kill -0 "$new_pid" &&
75 kill -QUIT "$cur_pid"
76 then
77 n=$TIMEOUT
78 while kill -0 "$cur_pid" 2>/dev/null && test $n -ge 0
80 printf '.' && sleep 1 && n=$(( $n - 1 ))
81 done
82 echo
84 if test $n -lt 0 && kill -0 "$cur_pid" 2>/dev/null
85 then
86 echo >&2 "$cur_pid still running after $TIMEOUT seconds"
87 exit 1
89 exit 0
91 echo >&2 "Couldn't upgrade, starting '$CMD' instead"
92 $CMD
94 reopen-logs)
95 sig USR1
98 echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
99 exit 1
101 esac