Skip to content

Instantly share code, notes, and snippets.

@ba0f3
Created October 1, 2015 01:56
Show Gist options
  • Save ba0f3/a3525a3e3a2d0aca3aca to your computer and use it in GitHub Desktop.
Save ba0f3/a3525a3e3a2d0aca3aca to your computer and use it in GitHub Desktop.
Simple H2O init script
#!/bin/bash
### BEGIN INIT INFO
# Provides: h2o
# Required-Start: networking
# Required-Stop: networking
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: H2o HTTP Server
# Description: H2O is the optimized HTTP/1.x, HTTP/2 server
### END INIT INFO
# h2o This script takes care of starting and stopping
# H2O HTTP server
# chkconfig: - 60 50
# description: H2O is the optimized HTTP/1.x, HTTP/2 server
# processname: h2o
# config: /etc/h2o/h2o.conf
NAME=h2o
CONFIG=/etc/h2o/h2o.conf
DAEMON=/usr/local/bin/h2o
PID=/var/run/h2o/h2o.pid
start() {
echo -n "Starting $NAME: "
if [ -f $PID ]; then
if [ -d /proc/`cat $PID` ]; then
echo "FAIL"
echo "process is already running"
exit 1
fi
fi
$DAEMON -c $CONFIG -m daemon
}
stop() {
echo -n "Shutting down $NAME: "
if [ -f $PID ]; then
if [ -d /proc/`cat $PID` ]; then
kill -TERM `cat $PID`
echo "OK"
fi
else
echo "FAIL"
echo "process is not running"
fi
}
reload() {
echo -n "Reloading $NAME: "
if [ -f $PID ]; then
if [ -d /proc/`cat $PID` ]; then
kill -SIGHUP `cat $PID`
echo "OK"
fi
else
echo "FAIL"
echo "process is not running"
fi
}
status() {
echo -n "$NAME is "
if [ -f $PID ]; then
if [ -d /proc/`cat $PID` ]; then
echo "running [pid `cat $PID`]"
exit 0
fi
fi
echo "not running"
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop && start
;;
reload)
reload
;;
status)
status
;;
*)
echo "Usage: $NAME {start|stop|restart|reload|status]"
exit 1
;;
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment