]>
Commit | Line | Data |
---|---|---|
d822f970 | 1 | #!/bin/sh |
3918a5b1 | 2 | # |
d822f970 ER |
3 | # H2O - the optimized HTTP/1, HTTP/2 server |
4 | # | |
5 | # chkconfig: 345 85 15 | |
3918a5b1 ER |
6 | # description: H2O - the optimized HTTP/1, HTTP/2 server |
7 | # processname: h2o | |
8 | # config: /etc/h2o/h2o.conf | |
9 | # pidfile: /var/run/h2o/h2o.pid | |
10 | ||
d822f970 | 11 | # Source function library |
3918a5b1 ER |
12 | . /etc/rc.d/init.d/functions |
13 | ||
d822f970 ER |
14 | # Get network config |
15 | . /etc/sysconfig/network | |
16 | ||
17 | # Check that networking is up. | |
18 | if is_yes "${NETWORKING}"; then | |
19 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then | |
20 | msg_network_down "h2o" | |
21 | exit 1 | |
22 | fi | |
23 | else | |
24 | exit 0 | |
3918a5b1 ER |
25 | fi |
26 | ||
d822f970 ER |
27 | # Get service config - may override defaults |
28 | [ -f /etc/sysconfig/h2o ] && . /etc/sysconfig/h2o | |
29 | ||
3918a5b1 ER |
30 | # Path to the server binary, and short-form for messages. |
31 | h2o=/usr/sbin/h2o | |
32 | prog=h2o | |
33 | configfile=/etc/h2o/h2o.conf | |
34 | lockfile=${LOCKFILE-/var/lock/subsys/h2o} | |
b2015e1e | 35 | pidfile=/var/run/h2o/h2o.pid |
3918a5b1 ER |
36 | options="-m daemon -c $configfile" |
37 | ||
d822f970 ER |
38 | # configtest itself |
39 | # must return non-zero if check failed | |
40 | # output is discarded if checkconfig is ran without details | |
41 | configtest() { | |
42 | $h2o -t -c ${configfile} | |
43 | } | |
44 | ||
45 | # wrapper for configtest | |
46 | checkconfig() { | |
47 | local details=${1:-0} | |
48 | ||
49 | if [ $details = 1 ]; then | |
50 | # run config test and display report (status action) | |
51 | show "Checking %s configuration" "h2o"; busy | |
52 | local out | |
53 | out=$(configtest 2>&1) | |
54 | RETVAL=$? | |
55 | if [ $RETVAL = 0 ]; then | |
56 | ok | |
57 | else | |
58 | fail | |
59 | fi | |
60 | [ "$out" ] && echo >&2 "$out" | |
61 | else | |
62 | # run config test and abort with nice message if failed | |
63 | # (for actions checking status before action). | |
64 | configtest >/dev/null 2>&1 | |
65 | RETVAL=$? | |
66 | if [ $RETVAL != 0 ]; then | |
67 | show "Checking %s configuration" "h2o"; fail | |
68 | nls 'Configuration test failed. See details with %s "checkconfig"' $0 | |
69 | exit $RETVAL | |
70 | fi | |
71 | fi | |
72 | } | |
3918a5b1 ER |
73 | |
74 | start() { | |
d822f970 ER |
75 | # Check if the service is already running? |
76 | if [ -f $lockfile ]; then | |
77 | msg_already_running "h2o" | |
78 | return | |
79 | fi | |
80 | ||
81 | msg_starting "h2o" | |
82 | daemon --pidfile $pidfile $h2o $options | |
83 | RETVAL=$? | |
84 | [ $RETVAL -eq 0 ] && touch $lockfile | |
3918a5b1 ER |
85 | } |
86 | ||
87 | stop() { | |
d822f970 ER |
88 | if [ ! -f $lockfile ]; then |
89 | msg_not_running "h2o" | |
90 | return | |
91 | fi | |
92 | ||
93 | # Stop daemons. | |
94 | msg_stopping "h2o" | |
95 | killproc --pidfile $pidfile h2o -TERM | |
96 | rm -f $lockfile | |
3918a5b1 ER |
97 | } |
98 | ||
99 | reload() { | |
d822f970 ER |
100 | if [ ! -f $lockfile ]; then |
101 | msg_not_running "h2o" | |
102 | RETVAL=7 | |
103 | return | |
104 | fi | |
105 | ||
106 | checkconfig | |
107 | msg_reloading "h2o" | |
108 | killproc --pidfile $pidfile h2o -HUP | |
109 | RETVAL=$? | |
3918a5b1 ER |
110 | } |
111 | ||
d822f970 ER |
112 | condrestart() { |
113 | if [ ! -f $lockfile ]; then | |
114 | msg_not_running "h2o" | |
115 | RETVAL=$1 | |
116 | return | |
117 | fi | |
118 | ||
119 | checkconfig | |
120 | stop | |
121 | start | |
3918a5b1 ER |
122 | } |
123 | ||
d822f970 | 124 | RETVAL=0 |
3918a5b1 ER |
125 | # See how we were called. |
126 | case "$1" in | |
127 | start) | |
d822f970 ER |
128 | start |
129 | ;; | |
3918a5b1 | 130 | stop) |
d822f970 ER |
131 | stop |
132 | ;; | |
3918a5b1 | 133 | restart) |
d822f970 ER |
134 | checkconfig |
135 | stop | |
136 | start | |
137 | ;; | |
138 | try-restart) | |
139 | condrestart 0 | |
140 | ;; | |
141 | reload|force-reload) | |
142 | reload | |
143 | ;; | |
144 | checkconfig|configtest) | |
145 | checkconfig 1 | |
146 | ;; | |
147 | status) | |
148 | status --pidfile $pidfile h2o | |
149 | RETVAL=$? | |
150 | ;; | |
3918a5b1 | 151 | *) |
d822f970 ER |
152 | msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|status}" |
153 | exit 3 | |
3918a5b1 ER |
154 | esac |
155 | ||
156 | exit $RETVAL |