]> git.pld-linux.org Git - packages/h2o.git/blob - h2o.init
717b1f7641e2998e282f08419ac2a847b24901ec
[packages/h2o.git] / h2o.init
1 #!/bin/sh
2 #
3 # H2O - the optimized HTTP/1, HTTP/2 server
4 #
5 # chkconfig: 345 85 15
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
11 # Source function library
12 . /etc/rc.d/init.d/functions
13
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
25 fi
26
27 # Get service config - may override defaults
28 [ -f /etc/sysconfig/h2o ] && . /etc/sysconfig/h2o
29
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}
35 pidfile=/var/run/h2o.pid
36 options="-m daemon -c $configfile"
37
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 }
73
74 start() {
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
85 }
86
87 stop() {
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
97 }
98
99 reload() {
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=$?
110 }
111
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
122 }
123
124 RETVAL=0
125 # See how we were called.
126 case "$1" in
127   start)
128         start
129         ;;
130   stop)
131         stop
132         ;;
133   restart)
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         ;;
151   *)
152         msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|status}"
153         exit 3
154 esac
155
156 exit $RETVAL
This page took 0.123895 seconds and 2 git commands to generate.