Long restart time on Debian

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Long restart time on Debian

Max Uetrecht
Hi,

after setting up a rather minor isc-dhcp-server configuration, I noticed
a long restart time (about 2s). I've created an issue on the ISC git:
https://gitlab.isc.org/isc-projects/dhcp/issues/42

Can you reproduce my issue / help me reduce restart time?


_______________________________________________
dhcp-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/dhcp-users

attachment0 (8K) Download Attachment
signature.asc (858 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Long restart time on Debian

Max Uetrecht

Following up my chat with Mr. Markwalkder (from the isc gitlab), the delay seems to be caused by the systemd start script. When starting isc-dhcp-server via `service isc-dhcp-server start`, I get the following syslog output

Aug 26 17:10:18 host systemd[1]: Starting LSB: DHCP server...
Aug 26 17:10:18 host isc-dhcp-server[27031]: Launching IPv4 server only.
Aug 26 17:10:18 host dhcpd[27051]: Wrote 0 deleted host decls to leases file.
Aug 26 17:10:18 host dhcpd[27051]: Wrote 0 new dynamic host decls to leases file.
Aug 26 17:10:18 host dhcpd[27051]: Wrote 7 leases to leases file.
Aug 26 17:10:18 host dhcpd[27053]: Server starting service.
Aug 26 17:10:20 host isc-dhcp-server[27031]: Starting ISC DHCPv4 server: dhcpd.
Aug 26 17:10:20 host systemd[1]: Started LSB: DHCP server.




# cat /etc/init.d/isc-dhcp-server
#!/bin/sh

### BEGIN INIT INFO
# Provides:          isc-dhcp-server
# Required-Start:    $remote_fs $network $syslog
# Required-Stop:     $remote_fs $network $syslog
# Should-Start:      $local_fs slapd $named
# Should-Stop:       $local_fs slapd
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: DHCP server
# Description:       Dynamic Host Configuration Protocol Server
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin

test -f /usr/sbin/dhcpd || exit 0

DHCPD_DEFAULT="${DHCPD_DEFAULT:-/etc/default/isc-dhcp-server}"

# It is not safe to start if we don't have a default configuration...
if [ ! -f "$DHCPD_DEFAULT" ]; then
	echo "$DHCPD_DEFAULT does not exist! - Aborting..."
	if [ "$DHCPD_DEFAULT" = "/etc/default/isc-dhcp-server" ]; then
		echo "Run 'dpkg-reconfigure isc-dhcp-server' to fix the problem."
	fi
	exit 0
fi

. /lib/lsb/init-functions

# Read init script configuration
[ -f "$DHCPD_DEFAULT" ] && . "$DHCPD_DEFAULT"

NAME4=dhcpd
NAME6=dhcpd6

DESC4="ISC DHCPv4 server"
DESC6="ISC DHCPv6 server"

# use already specified config file or fallback to defaults
DHCPDv4_CONF=${DHCPDv4_CONF:-/etc/dhcp/dhcpd.conf}
DHCPDv6_CONF=${DHCPDv6_CONF:-/etc/dhcp/dhcpd6.conf}

# try to read pid file name from config file or fallback to defaults
if [ -z "$DHCPDv4_PID" ]; then
	DHCPDv4_PID=$(sed -n -e 's/^[ \t]*pid-file-name[ \t]*"\(.*\)"[ \t]*;.*$/\1/p' < "$DHCPDv4_CONF" 2>/dev/null | head -n 1)
fi
if [ -z "$DHCPDv6_PID" ]; then
	DHCPDv6_PID=$(sed -n -e 's/^[ \t]*dhcpv6-pid-file-name[ \t]*"\(.*\)"[ \t]*;.*$/\1/p' < "$DHCPDv6_CONF" 2>/dev/null | head -n 1)
fi
DHCPDv4_PID="${DHCPDv4_PID:-/var/run/dhcpd.pid}"
DHCPDv6_PID="${DHCPDv6_PID:-/var/run/dhcpd6.pid}"

test_config()
{
	VERSION="$1"
	CONF="$2"

	if ! /usr/sbin/dhcpd -t $VERSION -q -cf "$CONF" > /dev/null 2>&1; then
		echo "dhcpd self-test failed. Please fix $CONF."
		echo "The error was: "
		/usr/sbin/dhcpd -t $VERSION -cf "$CONF"
		exit 1
	fi
}

check_status()
{
        OPTION="$1"
        PIDFILE="$2"
        NAME="$3"

        if [ ! -r "$PIDFILE" ]; then
                test "$OPTION" != -v || echo "$NAME is not running."
		return 3
        fi

        if read pid < "$PIDFILE" && ps -p "$pid" > /dev/null 2>&1; then
		test "$OPTION" != -v || echo "$NAME is running."
		return 0
        else
		test "$OPTION" != -v || echo "$NAME is not running but $PIDFILE exists."
		return 1
        fi
}

start_daemon()
{
	VERSION="$1"
	CONF="$2"
	NAME="$3"
	PIDFILE="$4"
	DESC="$5"

	shift 5
	INTERFACES="$*"

	test_config "$VERSION" "$CONF"
	log_daemon_msg "Starting $DESC" "$NAME"

	if [ -e "$PIDFILE" ]; then
		log_failure_msg "dhcpd service already running (pid file $PIDFILE currenty exists)"
		exit 1
	fi

	touch /var/lib/dhcp/$NAME.leases

	start-stop-daemon --start --quiet --pidfile $PIDFILE \
		--exec /usr/sbin/dhcpd -- $VERSION -q -cf $CONF $INTERFACES
	sleep 2

	if check_status -q $PIDFILE $NAME; then
		log_end_msg 0
	else
		log_failure_msg "check syslog for diagnostics."
		log_end_msg 1
		exit 1
	fi
}

stop_daemon()
{
	if check_status -q $DHCPDv4_PID $NAME4; then
		log_daemon_msg "Stopping $DESC4" "$NAME4"
		start-stop-daemon --stop --quiet --pidfile $DHCPDv4_PID
		log_end_msg $?
		rm -f "$DHCPDv4_PID"
	fi

	if check_status -q $DHCPDv6_PID $NAME6; then
		log_daemon_msg "Stopping $DESC6" "$NAME6"
		start-stop-daemon --stop --quiet --pidfile $DHCPDv6_PID
		log_end_msg $?
		rm -f "$DHCPDv6_PID"
	fi
}

case "$1" in
	start)
		if test -n "$INTERFACES" -a -z "$INTERFACESv4"; then
                        echo "DHCPv4 interfaces are no longer set by the INTERFACES variable in" >&2
                        echo "/etc/default/isc-dhcp-server.  Please use INTERFACESv4 instead." >&2
                        echo "Migrating automatically for now, but this will go away in the future." >&2
                        INTERFACESv4="$INTERFACES"
		fi
		if test -n "$INTERFACESv4"; then
			echo "Launching IPv4 server only."
			start_daemon "-4" "$DHCPDv4_CONF" "$NAME4" \
				"$DHCPDv4_PID" "$DESC4" "$INTERFACESv4"
		fi
		if test -n "$INTERFACESv6"; then
			echo "Launching IPv6 server only."
			start_daemon "-6" "$DHCPDv6_CONF" "$NAME6" \
				"$DHCPDv6_PID" "$DESC6" "$INTERFACESv6"
		fi
		if test -z "$INTERFACESv4" -a -z "$INTERFACESv6"; then
			echo "Launching both IPv4 and IPv6 servers (please configure INTERFACES in /etc/default/isc-dhcp-server if you only want one or the other)."
			start_daemon "-4" "$DHCPDv4_CONF" "$NAME4" \
				"$DHCPDv4_PID" "$DESC4" ""
			start_daemon "-6" "$DHCPDv6_CONF" "$NAME6" \
				"$DHCPDv6_PID" "$DESC6" ""
		fi
		;;
	stop)
		stop_daemon
		;;
	restart | force-reload)
		$0 stop
		sleep 2
		$0 start
		if [ "$?" != "0" ]; then
			exit 1
		fi
		;;
	status)
		if test -n "$INTERFACES" -a -z "$INTERFACESv4"; then
                        INTERFACESv4="$INTERFACES"
		fi
		if test -n "$INTERFACESv4"; then
			echo -n "Status of $DESC4: "
			check_status -v $DHCPDv4_PID $NAME4 || exit $?
		fi
		if test -n "$INTERFACESv6"; then
			echo -n "Status of $DESC6: "
			check_status -v $DHCPDv6_PID $NAME6 || exit $?
		fi
		;;
	*)
		echo "Usage: $0 {start|stop|restart|force-reload|status}"
		exit 1
esac

exit 0


Has anyone already experienced this issue?
Thanks in advanve for your help.

Am 26.08.19 um 14:55 schrieb Max Uetrecht:
Hi,

after setting up a rather minor isc-dhcp-server configuration, I noticed 
a long restart time (about 2s). I've created an issue on the ISC git: 
https://gitlab.isc.org/isc-projects/dhcp/issues/42

Can you reproduce my issue / help me reduce restart time?


_______________________________________________
dhcp-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/dhcp-users

attachment0 (8K) Download Attachment
attachment1 (8K) Download Attachment
signature.asc (858 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Long restart time on Debian

Thomas Markwalder
Here's where the two seconds is coming from:

start-stop-daemon --start --quiet --pidfile $PIDFILE \
		--exec /usr/sbin/dhcpd -- $VERSION -q -cf $CONF $INTERFACES
	sleep 2

They are explicitly waiting two seconds before the check status.


_______________________________________________
dhcp-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/dhcp-users
Reply | Threaded
Open this post in threaded view
|

Re: Long restart time on Debian

Max Uetrecht

Thank you! Kind of strange to find this in the default init.d script, shipped with the Debian package. 


On Mon, Aug 26, 2019 at 19:21, Thomas Markwalder <[hidden email]> wrote:
Here's where the two seconds is coming from:

start-stop-daemon --start --quiet --pidfile $PIDFILE \
		--exec /usr/sbin/dhcpd -- $VERSION -q -cf $CONF $INTERFACES
	sleep 2

They are explicitly waiting two seconds before the check status.




_______________________________________________
dhcp-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/dhcp-users

publicKey - max.uetrecht@protonmail.com - c6f0fd8f4a71e73eb1e97f5e742a58b4f8658423.asc (4K) Download Attachment