Skip to content

Commit

Permalink
Fix sysvinit script crash and not working, fixed tatsushid#8
Browse files Browse the repository at this point in the history
* the real process is a perl process as xplained in
  h2o/h2o#84 (comment)
  so we need to point in the start-and-stop-daemon to property
  managed.. so in init scritp is commented and fixed the functions
* starts a set of superdaemon program (named start_server) and a
  support library written in Perl, for hot-deploying TCP servers
  so the provided init script does nothing cos does not point real process
  • Loading branch information
mckaygerhard committed Feb 19, 2021
1 parent 711b72d commit 8ae3fce
Showing 1 changed file with 16 additions and 31 deletions.
47 changes: 16 additions & 31 deletions src/debian/h2o.init
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
# Required-Stop: $local_fs $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop h2o HTTP Server
# Description: H2O - the optimized HTTP/1, HTTP/2 server
# Short-Description: Optimized HTTP/1.x, HTTP/2 server
# Description: Manages the h2o daemon, the optimized HTTP/1.x and HTTP/2
# server.
### END INIT INFO

# Author: Tatsushi Demachi <tdemachi@gmail.com>
Expand All @@ -15,7 +16,7 @@

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="h2o"
DESC="optimized HTTP/1 HTTP/2 server"
NAME=h2o
CONFIG_FILE=/etc/h2o/h2o.conf
DAEMON=/usr/sbin/h2o
Expand Down Expand Up @@ -47,7 +48,7 @@ fi
#
do_start()
{
# Return
# the real daemon start by a perl implementation so we trap the return as:
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
Expand All @@ -56,31 +57,18 @@ do_start()
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
# The above code will not work for interpreted scripts, use the next
# six lines below instead (Ref: #643337, start-stop-daemon(8) )
#start-stop-daemon --start --quiet --pidfile $PIDFILE --startas $DAEMON \
# --name $NAME --test > /dev/null \
# || return 1
#start-stop-daemon --start --quiet --pidfile $PIDFILE --startas $DAEMON \
# --name $NAME -- $DAEMON_ARGS \
# || return 2

# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
# on this one. As a last resort, sleep for some time.
}

#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
# the starting of the server is xplained here https://github.com/h2o/h2o/issues/84#issuecomment-68315426
# is a perl process in fact.. is a set of superdaemon program (named start_server)
# and a support library written in Perl, for hot-deploying TCP servers,
# so the perl process is the real program to kill but only with pid reported by h2o:
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --exec /usr/bin/perl
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
Expand All @@ -89,7 +77,7 @@ do_stop()
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --pidfile $PIDFILE --exec /usr/bin/perl
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
Expand All @@ -107,13 +95,11 @@ do_configtest() {
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
# as the running h2o is started by a perl process, (from the start_server)
# so the perl process is the real program to send the signal:
log_daemon_msg "Reloading $DESC configuration files" "$NAME"
start-stop-daemon --oknodo --stop --signal HUP --quiet --pidfile "$PIDFILE" --exec "/usr/bin/perl"
log_end_msg $?
}

case "$1" in
Expand Down Expand Up @@ -177,7 +163,6 @@ case "$1" in
log_end_msg $?
;;
*)
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload|force-reload|configtest}" >&2
exit 3
;;
Expand Down

0 comments on commit 8ae3fce

Please sign in to comment.