diff mbox series

[v2] ] radvd: improve startup script

Message ID 1506478569-8657-1-git-send-email-casantos@datacom.ind.br
State Superseded, archived
Headers show
Series [v2] ] radvd: improve startup script | expand

Commit Message

Carlos Santos Sept. 27, 2017, 2:16 a.m. UTC
Print an error message if /usr/sbin/radvd is missing.

Print an error message if the kernel does not support IPv6 forwarding,
which is required by radvd.

Ignore any start/stop/restart option if /etc/radvd.conf does not exist.
The previous script printed an error message in this case but is valid
to install radvd without a configuration file. The daemon may be started
later by another service with a configuration created at run-time.

This is a copy/paste/edit/fix of package/dnsmasq/S80dnsmasq.

Signed-off-by: Carlos Santos <casantos@datacom.ind.br>
---
Changes v1->v2
- Print error message is /usr/sbin/radvd is missing
- Print error message if /proc/sys/net/ipv6/conf/all/forwarding is
  missing (kernel does not support IPv6 forwarding)
- Echo "1" to /proc/sys/net/ipv6/conf/all/forwarding upon start
---
 package/radvd/S50radvd | 46 +++++++++++++++++++++++++++++++++-------------
 1 file changed, 33 insertions(+), 13 deletions(-)

Comments

Thomas Petazzoni Oct. 7, 2017, 9:31 p.m. UTC | #1
Hello,

On Tue, 26 Sep 2017 23:16:09 -0300, Carlos Santos wrote:
> Print an error message if /usr/sbin/radvd is missing.
> 
> Print an error message if the kernel does not support IPv6 forwarding,
> which is required by radvd.
> 
> Ignore any start/stop/restart option if /etc/radvd.conf does not exist.
> The previous script printed an error message in this case but is valid
> to install radvd without a configuration file. The daemon may be started
> later by another service with a configuration created at run-time.
> 
> This is a copy/paste/edit/fix of package/dnsmasq/S80dnsmasq.

Not quite true: since v1, you changed things and you're no longer doing
like S80dnsmasq anymore.

> +[ -x /usr/sbin/radvd ] || {
> +	echo "Error: /usr/sbin/radvd is missing."
>  	exit 1
> -fi
> +}

I think this test is useless. Why not let start-stop-daemon fail
is /usr/sbin/radvd is missing? It's unlikely to happen because
Buildroot installs both radvd and its init script as part of the same
package. But if it ever happens for some reason, the error message from
start-stop-daemon should be pretty clear.

Best regards,

Thomas
diff mbox series

Patch

diff --git a/package/radvd/S50radvd b/package/radvd/S50radvd
index 9f1407c..cc73f29 100755
--- a/package/radvd/S50radvd
+++ b/package/radvd/S50radvd
@@ -1,18 +1,38 @@ 
 #!/bin/sh
 
-RADVD=/usr/sbin/radvd
-
-echo "1" > /proc/sys/net/ipv6/conf/all/forwarding
-
-printf "Starting radvd: "
-if [ ! -x "${RADVD}" ]; then
-	echo "missing"
+[ -x /usr/sbin/radvd ] || {
+	echo "Error: /usr/sbin/radvd is missing."
 	exit 1
-fi
+}
 
-if ${RADVD} ; then
-	echo "done"
-else
-	echo "failed"
+[ -f /proc/sys/net/ipv6/conf/all/forwarding ] || {
+	echo "Error: radvd requires IPv6 forwarding support."
 	exit 1
-fi
+}
+
+[ -f /etc/radvd.conf ] || {
+	exit 0
+}
+
+case "$1" in
+	start)
+		printf "Starting radvd: "
+		echo "1" > /proc/sys/net/ipv6/conf/all/forwarding
+		start-stop-daemon -S -x /usr/sbin/radvd
+		[ $? = 0 ] && echo "OK" || echo "FAIL"
+		;;
+	stop)
+		printf "Stopping radvd: "
+		start-stop-daemon -K -q -x /usr/sbin/radvd
+		[ $? = 0 ] && echo "OK" || echo "FAIL"
+		;;
+	restart|reload)
+		$0 stop
+		$0 start
+		;;
+	*)
+		echo "Usage: $0 {start|stop|restart}"
+		exit 1
+esac
+
+exit 0