Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v2 0/8] package/dhcp: rework the SysV init scripts
@ 2015-08-21 16:45 Benoît Thébaudeau
  2015-08-21 16:45 ` [Buildroot] [PATCH v2 1/8] package/dhcp: fix SysV init scripts option passing Benoît Thébaudeau
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: Benoît Thébaudeau @ 2015-08-21 16:45 UTC (permalink / raw)
  To: buildroot

Hi all,

This v2 only appends new patches to the series.

Best regards,
Beno?t

Beno?t Th?baudeau (8):
  package/dhcp: fix SysV init scripts option passing
  package/dhcp/S80dhcp-server: support extra options
  package/dhcp/S80dhcp-server: allow empty INTERFACES
  package/dhcp: fix SysV init scripts output text
  package/dhcp: remove sleep from SysV init scripts restart
  package/dhcp: SysV init scripts: remove PID files after stop
  package/dhcp/S80dhcp-server: support IPv6 lease file
  package/dhcp: SysV init scripts: refactor using functions

 package/dhcp/S80dhcp-relay  | 64 ++++++++++++++++++++++++--------------
 package/dhcp/S80dhcp-server | 76 +++++++++++++++++++++++++++++----------------
 2 files changed, 91 insertions(+), 49 deletions(-)

-- 
2.1.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Buildroot] [PATCH v2 1/8] package/dhcp: fix SysV init scripts option passing
  2015-08-21 16:45 [Buildroot] [PATCH v2 0/8] package/dhcp: rework the SysV init scripts Benoît Thébaudeau
@ 2015-08-21 16:45 ` Benoît Thébaudeau
  2015-08-21 16:45 ` [Buildroot] [PATCH v2 2/8] package/dhcp/S80dhcp-server: support extra options Benoît Thébaudeau
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Benoît Thébaudeau @ 2015-08-21 16:45 UTC (permalink / raw)
  To: buildroot

The SysV init scripts have configuration variables like INTERFACES whose
contents have to be passed to the daemon. These variables are
initialized as empty strings, but some of them are not allowed to be
empty and there was no means of filling them apart from creating a root
FS overlay to overwrite these scripts.

This commit adds support for files under /etc/default/ to set these
configuration variables. Such light files can now be added to the root
FS skeleton or overlays without having to duplicate most of the SysV
init scripts.

Signed-off-by: Beno?t Th?baudeau <benoit@wsystem.com>
---
 package/dhcp/S80dhcp-relay  | 4 ++++
 package/dhcp/S80dhcp-server | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/package/dhcp/S80dhcp-relay b/package/dhcp/S80dhcp-relay
index 9faa13d..74ec63c 100755
--- a/package/dhcp/S80dhcp-relay
+++ b/package/dhcp/S80dhcp-relay
@@ -13,6 +13,10 @@ INTERFACES=""
 # Additional options that are passed to the DHCP relay daemon?
 OPTIONS=""
 
+# Read configuration variable file if it is present
+CFG_FILE="/etc/default/dhcrelay"
+[ -r "${CFG_FILE}" ] && . "${CFG_FILE}"
+
 # Sanity checks
 test -f /usr/sbin/dhcrelay || exit 0
 test -n "$INTERFACES" || exit 0
diff --git a/package/dhcp/S80dhcp-server b/package/dhcp/S80dhcp-server
index fb99f9a..b9c47ba 100755
--- a/package/dhcp/S80dhcp-server
+++ b/package/dhcp/S80dhcp-server
@@ -7,6 +7,10 @@
 #       Separate multiple interfaces with spaces, e.g. "eth0 eth1".
 INTERFACES=""
 
+# Read configuration variable file if it is present
+CFG_FILE="/etc/default/dhcpd"
+[ -r "${CFG_FILE}" ] && . "${CFG_FILE}"
+
 # Sanity checks
 test -f /usr/sbin/dhcpd || exit 0
 test -f /etc/dhcp/dhcpd.conf || exit 0
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Buildroot] [PATCH v2 2/8] package/dhcp/S80dhcp-server: support extra options
  2015-08-21 16:45 [Buildroot] [PATCH v2 0/8] package/dhcp: rework the SysV init scripts Benoît Thébaudeau
  2015-08-21 16:45 ` [Buildroot] [PATCH v2 1/8] package/dhcp: fix SysV init scripts option passing Benoît Thébaudeau
@ 2015-08-21 16:45 ` Benoît Thébaudeau
  2015-08-21 16:45 ` [Buildroot] [PATCH v2 3/8] package/dhcp/S80dhcp-server: allow empty INTERFACES Benoît Thébaudeau
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Benoît Thébaudeau @ 2015-08-21 16:45 UTC (permalink / raw)
  To: buildroot

Add an OPTIONS configuration variable in order to make it possible to
pass custom extra options to dhcpd.

Signed-off-by: Beno?t Th?baudeau <benoit@wsystem.com>
---
 package/dhcp/S80dhcp-server | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/package/dhcp/S80dhcp-server b/package/dhcp/S80dhcp-server
index b9c47ba..ec4aad5 100755
--- a/package/dhcp/S80dhcp-server
+++ b/package/dhcp/S80dhcp-server
@@ -7,6 +7,9 @@
 #       Separate multiple interfaces with spaces, e.g. "eth0 eth1".
 INTERFACES=""
 
+# Additional options that are passed to the DHCP server daemon?
+OPTIONS=""
+
 # Read configuration variable file if it is present
 CFG_FILE="/etc/default/dhcpd"
 [ -r "${CFG_FILE}" ] && . "${CFG_FILE}"
@@ -21,7 +24,7 @@ case "$1" in
 		echo -n "Starting DHCP server: "
 		test -d /var/lib/dhcp/ || mkdir -p /var/lib/dhcp/
 		test -f /var/lib/dhcp/dhcpd.leases || touch /var/lib/dhcp/dhcpd.leases
-		start-stop-daemon -S -x /usr/sbin/dhcpd -- -q $INTERFACES
+		start-stop-daemon -S -x /usr/sbin/dhcpd -- -q $OPTIONS $INTERFACES
 		[ $? = 0 ] && echo "OK" || echo "FAIL"
 		;;
 	stop)
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Buildroot] [PATCH v2 3/8] package/dhcp/S80dhcp-server: allow empty INTERFACES
  2015-08-21 16:45 [Buildroot] [PATCH v2 0/8] package/dhcp: rework the SysV init scripts Benoît Thébaudeau
  2015-08-21 16:45 ` [Buildroot] [PATCH v2 1/8] package/dhcp: fix SysV init scripts option passing Benoît Thébaudeau
  2015-08-21 16:45 ` [Buildroot] [PATCH v2 2/8] package/dhcp/S80dhcp-server: support extra options Benoît Thébaudeau
@ 2015-08-21 16:45 ` Benoît Thébaudeau
  2015-08-21 16:45 ` [Buildroot] [PATCH v2 4/8] package/dhcp: fix SysV init scripts output text Benoît Thébaudeau
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Benoît Thébaudeau @ 2015-08-21 16:45 UTC (permalink / raw)
  To: buildroot

The dhcpd daemon does not require network interface names to be
specified on the command line.

From dhcpd(8):
"The names of the network interfaces on which dhcpd should listen for
broadcasts may be specified on the command line.  This should be done
on systems where dhcpd is unable to identify non-broadcast interfaces,
but should not be required on other systems.  If no interface names
are specified on the command line dhcpd will identify all network
interfaces which are up, eliminating non-broadcast interfaces if
possible, and listen for DHCP broadcasts on each interface."

dhcpd exits with "Not configured to listen on any interfaces!" only if
no requested (those in INTERFACES, or all if empty) non-broadcast
interfaces matching the subnet declarations in dhcpd.conf are up.

Signed-off-by: Beno?t Th?baudeau <benoit@wsystem.com>
---
 package/dhcp/S80dhcp-server | 1 -
 1 file changed, 1 deletion(-)

diff --git a/package/dhcp/S80dhcp-server b/package/dhcp/S80dhcp-server
index ec4aad5..fad6a36 100755
--- a/package/dhcp/S80dhcp-server
+++ b/package/dhcp/S80dhcp-server
@@ -17,7 +17,6 @@ CFG_FILE="/etc/default/dhcpd"
 # Sanity checks
 test -f /usr/sbin/dhcpd || exit 0
 test -f /etc/dhcp/dhcpd.conf || exit 0
-test -n "$INTERFACES" || exit 0
 
 case "$1" in
 	start)
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Buildroot] [PATCH v2 4/8] package/dhcp: fix SysV init scripts output text
  2015-08-21 16:45 [Buildroot] [PATCH v2 0/8] package/dhcp: rework the SysV init scripts Benoît Thébaudeau
                   ` (2 preceding siblings ...)
  2015-08-21 16:45 ` [Buildroot] [PATCH v2 3/8] package/dhcp/S80dhcp-server: allow empty INTERFACES Benoît Thébaudeau
@ 2015-08-21 16:45 ` Benoît Thébaudeau
  2015-08-21 16:45 ` [Buildroot] [PATCH v2 5/8] package/dhcp: remove sleep from SysV init scripts restart Benoît Thébaudeau
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Benoît Thébaudeau @ 2015-08-21 16:45 UTC (permalink / raw)
  To: buildroot

Fix various messages displayed by these scripts:
 - remove extra "dhcpd3" for `S80dhcp-server stop`,
 - make start-stop-daemon quiet in order to avoid extra messages like
   "stopped /usr/sbin/dhcpd (pid 174)" being output between the command
   description and its result,
 - fix the script names in the usage strings.

Signed-off-by: Beno?t Th?baudeau <benoit@wsystem.com>
---
 package/dhcp/S80dhcp-relay  | 6 +++---
 package/dhcp/S80dhcp-server | 8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/package/dhcp/S80dhcp-relay b/package/dhcp/S80dhcp-relay
index 74ec63c..dbcfa62 100755
--- a/package/dhcp/S80dhcp-relay
+++ b/package/dhcp/S80dhcp-relay
@@ -33,12 +33,12 @@ DHCRELAYPID=/var/run/dhcrelay.pid
 case "$1" in
 	start)
 		echo -n "Starting DHCP relay: "
-		start-stop-daemon -S -x /usr/sbin/dhcrelay -- -q $OPTIONS $IFCMD $SERVERS
+		start-stop-daemon -S -q -x /usr/sbin/dhcrelay -- -q $OPTIONS $IFCMD $SERVERS
 		[ $? = 0 ] && echo "OK" || echo "FAIL"
 		;;
 	stop)
 		echo -n "Stopping DHCP relay: "
-		start-stop-daemon -K -x /usr/sbin/dhcrelay
+		start-stop-daemon -K -q -x /usr/sbin/dhcrelay
 		[ $? = 0 ] && echo "OK" || echo "FAIL"
 		;;
 	restart | force-reload)
@@ -47,7 +47,7 @@ case "$1" in
 		$0 start
 		;;
 	*)
-		echo "Usage: /etc/init.d/dhcp-relay {start|stop|restart|force-reload}"
+		echo "Usage: $0 {start|stop|restart|force-reload}"
 		exit 1
 esac
 
diff --git a/package/dhcp/S80dhcp-server b/package/dhcp/S80dhcp-server
index fad6a36..7c1695c 100755
--- a/package/dhcp/S80dhcp-server
+++ b/package/dhcp/S80dhcp-server
@@ -23,12 +23,12 @@ case "$1" in
 		echo -n "Starting DHCP server: "
 		test -d /var/lib/dhcp/ || mkdir -p /var/lib/dhcp/
 		test -f /var/lib/dhcp/dhcpd.leases || touch /var/lib/dhcp/dhcpd.leases
-		start-stop-daemon -S -x /usr/sbin/dhcpd -- -q $OPTIONS $INTERFACES
+		start-stop-daemon -S -q -x /usr/sbin/dhcpd -- -q $OPTIONS $INTERFACES
 		[ $? = 0 ] && echo "OK" || echo "FAIL"
 		;;
 	stop)
-		echo -n "Stopping DHCP server: dhcpd3"
-		start-stop-daemon -K -x /usr/sbin/dhcpd
+		echo -n "Stopping DHCP server: "
+		start-stop-daemon -K -q -x /usr/sbin/dhcpd
 		[ $? = 0 ] && echo "OK" || echo "FAIL"
 		;;
 	restart | force-reload)
@@ -40,7 +40,7 @@ case "$1" in
 		fi
 		;;
 	*)
-		echo "Usage: /etc/init.d/dhcp-server {start|stop|restart|force-reload}"
+		echo "Usage: $0 {start|stop|restart|force-reload}"
 		exit 1
 esac
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Buildroot] [PATCH v2 5/8] package/dhcp: remove sleep from SysV init scripts restart
  2015-08-21 16:45 [Buildroot] [PATCH v2 0/8] package/dhcp: rework the SysV init scripts Benoît Thébaudeau
                   ` (3 preceding siblings ...)
  2015-08-21 16:45 ` [Buildroot] [PATCH v2 4/8] package/dhcp: fix SysV init scripts output text Benoît Thébaudeau
@ 2015-08-21 16:45 ` Benoît Thébaudeau
  2015-08-21 16:45 ` [Buildroot] [PATCH v2 6/8] package/dhcp: SysV init scripts: remove PID files after stop Benoît Thébaudeau
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Benoît Thébaudeau @ 2015-08-21 16:45 UTC (permalink / raw)
  To: buildroot

No sleep is required for the restart and force-reload operations to
succeed.

Signed-off-by: Beno?t Th?baudeau <benoit@wsystem.com>
---
 package/dhcp/S80dhcp-relay  | 1 -
 package/dhcp/S80dhcp-server | 1 -
 2 files changed, 2 deletions(-)

diff --git a/package/dhcp/S80dhcp-relay b/package/dhcp/S80dhcp-relay
index dbcfa62..c8f79ff 100755
--- a/package/dhcp/S80dhcp-relay
+++ b/package/dhcp/S80dhcp-relay
@@ -43,7 +43,6 @@ case "$1" in
 		;;
 	restart | force-reload)
 		$0 stop
-		sleep 2
 		$0 start
 		;;
 	*)
diff --git a/package/dhcp/S80dhcp-server b/package/dhcp/S80dhcp-server
index 7c1695c..1f27b54 100755
--- a/package/dhcp/S80dhcp-server
+++ b/package/dhcp/S80dhcp-server
@@ -33,7 +33,6 @@ case "$1" in
 		;;
 	restart | force-reload)
 		$0 stop
-		sleep 2
 		$0 start
 		if [ "$?" != "0" ]; then
 			exit 1
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Buildroot] [PATCH v2 6/8] package/dhcp: SysV init scripts: remove PID files after stop
  2015-08-21 16:45 [Buildroot] [PATCH v2 0/8] package/dhcp: rework the SysV init scripts Benoît Thébaudeau
                   ` (4 preceding siblings ...)
  2015-08-21 16:45 ` [Buildroot] [PATCH v2 5/8] package/dhcp: remove sleep from SysV init scripts restart Benoît Thébaudeau
@ 2015-08-21 16:45 ` Benoît Thébaudeau
  2015-08-21 16:45 ` [Buildroot] [PATCH v2 7/8] package/dhcp/S80dhcp-server: support IPv6 lease file Benoît Thébaudeau
  2015-08-21 16:45 ` [Buildroot] [PATCH v2 8/8] package/dhcp: SysV init scripts: refactor using functions Benoît Thébaudeau
  7 siblings, 0 replies; 10+ messages in thread
From: Benoît Thébaudeau @ 2015-08-21 16:45 UTC (permalink / raw)
  To: buildroot

These daemons do not remove their PID files, so do it manually in the
scripts.

Signed-off-by: Beno?t Th?baudeau <benoit@wsystem.com>
---
 package/dhcp/S80dhcp-relay  | 12 ++++++++++--
 package/dhcp/S80dhcp-server | 12 ++++++++++--
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/package/dhcp/S80dhcp-relay b/package/dhcp/S80dhcp-relay
index c8f79ff..c6f7f0f 100755
--- a/package/dhcp/S80dhcp-relay
+++ b/package/dhcp/S80dhcp-relay
@@ -17,6 +17,9 @@ OPTIONS=""
 CFG_FILE="/etc/default/dhcrelay"
 [ -r "${CFG_FILE}" ] && . "${CFG_FILE}"
 
+# PID files generated by the daemon
+PID_FILES="/var/run/dhcrelay.pid /var/run/dhcrelay6.pid"
+
 # Sanity checks
 test -f /usr/sbin/dhcrelay || exit 0
 test -n "$INTERFACES" || exit 0
@@ -38,8 +41,13 @@ case "$1" in
 		;;
 	stop)
 		echo -n "Stopping DHCP relay: "
-		start-stop-daemon -K -q -x /usr/sbin/dhcrelay
-		[ $? = 0 ] && echo "OK" || echo "FAIL"
+		if start-stop-daemon -K -q -x /usr/sbin/dhcrelay; then
+			# This daemon does not remove its PID file when it exits.
+			rm -f ${PID_FILES}
+			echo "OK"
+		else
+			echo "FAIL"
+		fi
 		;;
 	restart | force-reload)
 		$0 stop
diff --git a/package/dhcp/S80dhcp-server b/package/dhcp/S80dhcp-server
index 1f27b54..52cfe11 100755
--- a/package/dhcp/S80dhcp-server
+++ b/package/dhcp/S80dhcp-server
@@ -14,6 +14,9 @@ OPTIONS=""
 CFG_FILE="/etc/default/dhcpd"
 [ -r "${CFG_FILE}" ] && . "${CFG_FILE}"
 
+# PID files generated by the daemon
+PID_FILES="/var/run/dhcpd.pid /var/run/dhcpd6.pid"
+
 # Sanity checks
 test -f /usr/sbin/dhcpd || exit 0
 test -f /etc/dhcp/dhcpd.conf || exit 0
@@ -28,8 +31,13 @@ case "$1" in
 		;;
 	stop)
 		echo -n "Stopping DHCP server: "
-		start-stop-daemon -K -q -x /usr/sbin/dhcpd
-		[ $? = 0 ] && echo "OK" || echo "FAIL"
+		if start-stop-daemon -K -q -x /usr/sbin/dhcpd; then
+			# This daemon does not remove its PID file when it exits.
+			rm -f ${PID_FILES}
+			echo "OK"
+		else
+			echo "FAIL"
+		fi
 		;;
 	restart | force-reload)
 		$0 stop
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Buildroot] [PATCH v2 7/8] package/dhcp/S80dhcp-server: support IPv6 lease file
  2015-08-21 16:45 [Buildroot] [PATCH v2 0/8] package/dhcp: rework the SysV init scripts Benoît Thébaudeau
                   ` (5 preceding siblings ...)
  2015-08-21 16:45 ` [Buildroot] [PATCH v2 6/8] package/dhcp: SysV init scripts: remove PID files after stop Benoît Thébaudeau
@ 2015-08-21 16:45 ` Benoît Thébaudeau
  2015-08-21 16:45 ` [Buildroot] [PATCH v2 8/8] package/dhcp: SysV init scripts: refactor using functions Benoît Thébaudeau
  7 siblings, 0 replies; 10+ messages in thread
From: Benoît Thébaudeau @ 2015-08-21 16:45 UTC (permalink / raw)
  To: buildroot

The IPv6 lease file has a different name.

Signed-off-by: Beno?t Th?baudeau <benoit@wsystem.com>
---
 package/dhcp/S80dhcp-server | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/package/dhcp/S80dhcp-server b/package/dhcp/S80dhcp-server
index 52cfe11..d3652b4 100755
--- a/package/dhcp/S80dhcp-server
+++ b/package/dhcp/S80dhcp-server
@@ -25,7 +25,10 @@ case "$1" in
 	start)
 		echo -n "Starting DHCP server: "
 		test -d /var/lib/dhcp/ || mkdir -p /var/lib/dhcp/
-		test -f /var/lib/dhcp/dhcpd.leases || touch /var/lib/dhcp/dhcpd.leases
+		for lease_file in /var/lib/dhcp/dhcpd.leases \
+					/var/lib/dhcp/dhcpd6.leases; do
+			test -f "${lease_file}" || touch "${lease_file}"
+		done
 		start-stop-daemon -S -q -x /usr/sbin/dhcpd -- -q $OPTIONS $INTERFACES
 		[ $? = 0 ] && echo "OK" || echo "FAIL"
 		;;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Buildroot] [PATCH v2 8/8] package/dhcp: SysV init scripts: refactor using functions
  2015-08-21 16:45 [Buildroot] [PATCH v2 0/8] package/dhcp: rework the SysV init scripts Benoît Thébaudeau
                   ` (6 preceding siblings ...)
  2015-08-21 16:45 ` [Buildroot] [PATCH v2 7/8] package/dhcp/S80dhcp-server: support IPv6 lease file Benoît Thébaudeau
@ 2015-08-21 16:45 ` Benoît Thébaudeau
  7 siblings, 0 replies; 10+ messages in thread
From: Benoît Thébaudeau @ 2015-08-21 16:45 UTC (permalink / raw)
  To: buildroot

Refactor these scripts using start()/stop() functions rather than having
these scripts invoke themselves.

By the way, clean up these scripts.

Signed-off-by: Beno?t Th?baudeau <benoit@wsystem.com>
---
 package/dhcp/S80dhcp-relay  | 63 +++++++++++++++++++++-----------------
 package/dhcp/S80dhcp-server | 74 +++++++++++++++++++++++++--------------------
 2 files changed, 76 insertions(+), 61 deletions(-)

diff --git a/package/dhcp/S80dhcp-relay b/package/dhcp/S80dhcp-relay
index c6f7f0f..2f9ed50 100755
--- a/package/dhcp/S80dhcp-relay
+++ b/package/dhcp/S80dhcp-relay
@@ -1,61 +1,68 @@
 #!/bin/sh
-#
-# $Id: dhcp3-relay,v 1.1 2004/04/16 15:41:08 ml Exp $
-#
+
+NAME="dhcrelay"
+DESC="DHCP relay"
+DAEMON="/usr/sbin/${NAME}"
+
+# On what interfaces should the DHCP relay serve DHCP requests?
+INTERFACES=""
 
 # What servers should the DHCP relay forward requests to?
-# e.g: SERVERS="192.168.0.1"
+# E.g: SERVERS="192.168.0.1"
 SERVERS=""
 
-# On what interfaces should the DHCP relay (dhrelay) serve DHCP requests?
-INTERFACES=""
-
 # Additional options that are passed to the DHCP relay daemon?
 OPTIONS=""
 
 # Read configuration variable file if it is present
-CFG_FILE="/etc/default/dhcrelay"
+CFG_FILE="/etc/default/${NAME}"
 [ -r "${CFG_FILE}" ] && . "${CFG_FILE}"
 
 # PID files generated by the daemon
-PID_FILES="/var/run/dhcrelay.pid /var/run/dhcrelay6.pid"
+PID_FILES="/var/run/${NAME}.pid /var/run/${NAME}6.pid"
 
 # Sanity checks
-test -f /usr/sbin/dhcrelay || exit 0
+test -f "${DAEMON}" || exit 0
 test -n "$INTERFACES" || exit 0
 test -n "$SERVERS" || exit 0
 
-# Build command line for interfaces (will be passed to dhrelay below.)
+# Build command line for interfaces (will be passed to dhcrelay below).
 IFCMD=""
 for I in $INTERFACES; do
 	IFCMD=${IFCMD}"-i "${I}" "
 done
 
-DHCRELAYPID=/var/run/dhcrelay.pid
+start()
+{
+	echo -n "Starting ${DESC}: "
+	start-stop-daemon -S -q -x "${DAEMON}" -- -q $OPTIONS $IFCMD $SERVERS &&
+			echo "OK" || echo "FAIL"
+}
+
+stop()
+{
+	echo -n "Stopping ${DESC}: "
+	if start-stop-daemon -K -q -x "${DAEMON}"; then
+		# This daemon does not remove its PID file when it exits.
+		rm -f ${PID_FILES}
+		echo "OK"
+	else
+		echo "FAIL"
+	fi
+}
 
 case "$1" in
 	start)
-		echo -n "Starting DHCP relay: "
-		start-stop-daemon -S -q -x /usr/sbin/dhcrelay -- -q $OPTIONS $IFCMD $SERVERS
-		[ $? = 0 ] && echo "OK" || echo "FAIL"
+		start
 		;;
 	stop)
-		echo -n "Stopping DHCP relay: "
-		if start-stop-daemon -K -q -x /usr/sbin/dhcrelay; then
-			# This daemon does not remove its PID file when it exits.
-			rm -f ${PID_FILES}
-			echo "OK"
-		else
-			echo "FAIL"
-		fi
+		stop
 		;;
-	restart | force-reload)
-		$0 stop
-		$0 start
+	restart|force-reload)
+		stop
+		start
 		;;
 	*)
 		echo "Usage: $0 {start|stop|restart|force-reload}"
 		exit 1
 esac
-
-exit 0
diff --git a/package/dhcp/S80dhcp-server b/package/dhcp/S80dhcp-server
index d3652b4..5b6e861 100755
--- a/package/dhcp/S80dhcp-server
+++ b/package/dhcp/S80dhcp-server
@@ -1,57 +1,65 @@
 #!/bin/sh
-#
-# $Id: dhcp3-server.init.d,v 1.4 2003/07/13 19:12:41 mdz Exp $
-#
 
-# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
-#       Separate multiple interfaces with spaces, e.g. "eth0 eth1".
+NAME="dhcpd"
+DESC="DHCP server"
+DAEMON="/usr/sbin/${NAME}"
+DAEMON_CONF="/etc/dhcp/${NAME}.conf"
+DAEMON_LIB_DIR="/var/lib/dhcp"
+LEASE_FILES="${DAEMON_LIB_DIR}/${NAME}.leases ${DAEMON_LIB_DIR}/${NAME}6.leases"
+
+# On what interfaces should the DHCP server serve DHCP requests?
+# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
 INTERFACES=""
 
 # Additional options that are passed to the DHCP server daemon?
 OPTIONS=""
 
 # Read configuration variable file if it is present
-CFG_FILE="/etc/default/dhcpd"
+CFG_FILE="/etc/default/${NAME}"
 [ -r "${CFG_FILE}" ] && . "${CFG_FILE}"
 
 # PID files generated by the daemon
-PID_FILES="/var/run/dhcpd.pid /var/run/dhcpd6.pid"
+PID_FILES="/var/run/${NAME}.pid /var/run/${NAME}6.pid"
 
 # Sanity checks
-test -f /usr/sbin/dhcpd || exit 0
-test -f /etc/dhcp/dhcpd.conf || exit 0
+test -f "${DAEMON}" || exit 0
+test -f "${DAEMON_CONF}" || exit 0
+
+start()
+{
+	echo -n "Starting ${DESC}: "
+	test -d "${DAEMON_LIB_DIR}" || mkdir -p "${DAEMON_LIB_DIR}"
+	for lease_file in ${LEASE_FILES}; do
+		test -f "${lease_file}" || touch "${lease_file}"
+	done
+	start-stop-daemon -S -q -x "${DAEMON}" -- -q $OPTIONS $INTERFACES &&
+			echo "OK" || echo "FAIL"
+}
+
+stop()
+{
+	echo -n "Stopping ${DESC}: "
+	if start-stop-daemon -K -q -x "${DAEMON}"; then
+		# This daemon does not remove its PID file when it exits.
+		rm -f ${PID_FILES}
+		echo "OK"
+	else
+		echo "FAIL"
+	fi
+}
 
 case "$1" in
 	start)
-		echo -n "Starting DHCP server: "
-		test -d /var/lib/dhcp/ || mkdir -p /var/lib/dhcp/
-		for lease_file in /var/lib/dhcp/dhcpd.leases \
-					/var/lib/dhcp/dhcpd6.leases; do
-			test -f "${lease_file}" || touch "${lease_file}"
-		done
-		start-stop-daemon -S -q -x /usr/sbin/dhcpd -- -q $OPTIONS $INTERFACES
-		[ $? = 0 ] && echo "OK" || echo "FAIL"
+		start
 		;;
 	stop)
-		echo -n "Stopping DHCP server: "
-		if start-stop-daemon -K -q -x /usr/sbin/dhcpd; then
-			# This daemon does not remove its PID file when it exits.
-			rm -f ${PID_FILES}
-			echo "OK"
-		else
-			echo "FAIL"
-		fi
+		stop
 		;;
-	restart | force-reload)
-		$0 stop
-		$0 start
-		if [ "$?" != "0" ]; then
-			exit 1
-		fi
+	restart|force-reload)
+		stop
+		start
 		;;
 	*)
 		echo "Usage: $0 {start|stop|restart|force-reload}"
 		exit 1
 esac
-
-exit 0
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Buildroot] [PATCH v2 7/8] package/dhcp/S80dhcp-server: support IPv6 lease file
  2015-10-13  9:35 [Buildroot] [PATCH v2 1/8] package/dhcp: fix SysV init scripts option passing Benoît Thébaudeau
@ 2015-10-13  9:35 ` Benoît Thébaudeau
  0 siblings, 0 replies; 10+ messages in thread
From: Benoît Thébaudeau @ 2015-10-13  9:35 UTC (permalink / raw)
  To: buildroot

The IPv6 lease file has a different name.

Signed-off-by: Beno?t Th?baudeau <benoit@wsystem.com>

---
Changes v1 -> v2:
 - Rebase.
---
 package/dhcp/S80dhcp-server | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/package/dhcp/S80dhcp-server b/package/dhcp/S80dhcp-server
index 1c2ff74..b6f76ee 100755
--- a/package/dhcp/S80dhcp-server
+++ b/package/dhcp/S80dhcp-server
@@ -25,7 +25,10 @@ case "$1" in
 	start)
 		printf "Starting DHCP server: "
 		test -d /var/lib/dhcp/ || mkdir -p /var/lib/dhcp/
-		test -f /var/lib/dhcp/dhcpd.leases || touch /var/lib/dhcp/dhcpd.leases
+		for lease_file in /var/lib/dhcp/dhcpd.leases \
+					/var/lib/dhcp/dhcpd6.leases; do
+			test -f "${lease_file}" || touch "${lease_file}"
+		done
 		start-stop-daemon -S -q -x /usr/sbin/dhcpd -- -q $OPTIONS $INTERFACES
 		[ $? = 0 ] && echo "OK" || echo "FAIL"
 		;;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-10-13  9:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-21 16:45 [Buildroot] [PATCH v2 0/8] package/dhcp: rework the SysV init scripts Benoît Thébaudeau
2015-08-21 16:45 ` [Buildroot] [PATCH v2 1/8] package/dhcp: fix SysV init scripts option passing Benoît Thébaudeau
2015-08-21 16:45 ` [Buildroot] [PATCH v2 2/8] package/dhcp/S80dhcp-server: support extra options Benoît Thébaudeau
2015-08-21 16:45 ` [Buildroot] [PATCH v2 3/8] package/dhcp/S80dhcp-server: allow empty INTERFACES Benoît Thébaudeau
2015-08-21 16:45 ` [Buildroot] [PATCH v2 4/8] package/dhcp: fix SysV init scripts output text Benoît Thébaudeau
2015-08-21 16:45 ` [Buildroot] [PATCH v2 5/8] package/dhcp: remove sleep from SysV init scripts restart Benoît Thébaudeau
2015-08-21 16:45 ` [Buildroot] [PATCH v2 6/8] package/dhcp: SysV init scripts: remove PID files after stop Benoît Thébaudeau
2015-08-21 16:45 ` [Buildroot] [PATCH v2 7/8] package/dhcp/S80dhcp-server: support IPv6 lease file Benoît Thébaudeau
2015-08-21 16:45 ` [Buildroot] [PATCH v2 8/8] package/dhcp: SysV init scripts: refactor using functions Benoît Thébaudeau
  -- strict thread matches above, loose matches on Subject: below --
2015-10-13  9:35 [Buildroot] [PATCH v2 1/8] package/dhcp: fix SysV init scripts option passing Benoît Thébaudeau
2015-10-13  9:35 ` [Buildroot] [PATCH v2 7/8] package/dhcp/S80dhcp-server: support IPv6 lease file Benoît Thébaudeau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox