#!/bin/sh # # H2O - the optimized HTTP/1, HTTP/2 server # # chkconfig: 345 85 15 # description: H2O - the optimized HTTP/1, HTTP/2 server # processname: h2o # config: /etc/h2o/h2o.conf # pidfile: /var/run/h2o/h2o.pid # Source function library . /etc/rc.d/init.d/functions # Get network config . /etc/sysconfig/network # Check that networking is up. if is_yes "${NETWORKING}"; then if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then msg_network_down "h2o" exit 1 fi else exit 0 fi # Get service config - may override defaults [ -f /etc/sysconfig/h2o ] && . /etc/sysconfig/h2o # Path to the server binary, and short-form for messages. h2o=/usr/sbin/h2o prog=h2o configfile=/etc/h2o/h2o.conf lockfile=${LOCKFILE-/var/lock/subsys/h2o} pidfile=/var/run/h2o/h2o.pid options="-m daemon -c $configfile" # configtest itself # must return non-zero if check failed # output is discarded if checkconfig is ran without details configtest() { $h2o -t -c ${configfile} } # wrapper for configtest checkconfig() { local details=${1:-0} if [ $details = 1 ]; then # run config test and display report (status action) show "Checking %s configuration" "h2o"; busy local out out=$(configtest 2>&1) RETVAL=$? if [ $RETVAL = 0 ]; then ok else fail fi [ "$out" ] && echo >&2 "$out" else # run config test and abort with nice message if failed # (for actions checking status before action). configtest >/dev/null 2>&1 RETVAL=$? if [ $RETVAL != 0 ]; then show "Checking %s configuration" "h2o"; fail nls 'Configuration test failed. See details with %s "checkconfig"' $0 exit $RETVAL fi fi } start() { # Check if the service is already running? if [ -f $lockfile ]; then msg_already_running "h2o" return fi msg_starting "h2o" daemon --pidfile $pidfile $h2o $options RETVAL=$? [ $RETVAL -eq 0 ] && touch $lockfile } stop() { if [ ! -f $lockfile ]; then msg_not_running "h2o" return fi # Stop daemons. msg_stopping "h2o" killproc --pidfile $pidfile h2o -TERM rm -f $lockfile } reload() { if [ ! -f $lockfile ]; then msg_not_running "h2o" RETVAL=7 return fi checkconfig msg_reloading "h2o" killproc --pidfile $pidfile h2o -HUP RETVAL=$? } condrestart() { if [ ! -f $lockfile ]; then msg_not_running "h2o" RETVAL=$1 return fi checkconfig stop start } RETVAL=0 # See how we were called. case "$1" in start) start ;; stop) stop ;; restart) checkconfig stop start ;; try-restart) condrestart 0 ;; reload|force-reload) reload ;; checkconfig|configtest) checkconfig 1 ;; status) status --pidfile $pidfile h2o RETVAL=$? ;; *) msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|status}" exit 3 esac exit $RETVAL