From patchwork Mon Apr 16 02:10:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Santos X-Patchwork-Id: 898406 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=datacom.ind.br Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40PX1153Wjz9s1R for ; Mon, 16 Apr 2018 12:11:00 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id A7617875FD; Mon, 16 Apr 2018 02:10:56 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jBk5+RlqIcDn; Mon, 16 Apr 2018 02:10:54 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 85BF186E55; Mon, 16 Apr 2018 02:10:54 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id 0E7661C09A7 for ; Mon, 16 Apr 2018 02:10:53 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 0A4A486BBB for ; Mon, 16 Apr 2018 02:10:53 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id x7hVlZjhcmIh for ; Mon, 16 Apr 2018 02:10:51 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.datacom.ind.br (mx.datacom.ind.br [177.66.5.10]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 444428499A for ; Mon, 16 Apr 2018 02:10:51 +0000 (UTC) Received: from mail.datacom.ind.br (localhost [127.0.0.1]) by mail.datacom.ind.br (Postfix) with ESMTPS id AECCF1BA015F for ; Sun, 15 Apr 2018 23:10:46 -0300 (-03) Received: from localhost (localhost [127.0.0.1]) by mail.datacom.ind.br (Postfix) with ESMTP id A016F1BA015D for ; Sun, 15 Apr 2018 23:10:46 -0300 (-03) Received: from mail.datacom.ind.br ([127.0.0.1]) by localhost (mail.datacom.ind.br [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id mAdGzUENTYLk for ; Sun, 15 Apr 2018 23:10:46 -0300 (-03) Received: from p7-1130br.casantos.org (unknown [177.18.78.240]) by mail.datacom.ind.br (Postfix) with ESMTPSA id 59D3D1BA0135 for ; Sun, 15 Apr 2018 23:10:46 -0300 (-03) From: Carlos Santos To: buildroot@buildroot.org Date: Sun, 15 Apr 2018 23:10:37 -0300 Message-Id: <20180416021037.13345-1-casantos@datacom.ind.br> X-Mailer: git-send-email 2.14.3 In-Reply-To: <1506478569-8657-1-git-send-email-casantos@datacom.ind.br> References: <1506478569-8657-1-git-send-email-casantos@datacom.ind.br> Subject: [Buildroot] [PATCH v3] radvd: improve startup script X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.24 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" - Add start, stop and restart/reload options. - Do nothing if /etc/radvd.conf does not exist instead of printing an error message. It 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. - Print an error message if the kernel does not support IPv6 forwarding, which is required by radvd. Signed-off-by: Carlos Santos --- Changes v2->v3 - Don't the test if the binary is executable. 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 (Thomas Petazzoni). - Move start and stop to functions and rewrite the error handling code to improve its readability. - Add a one second sleep between stop and start, in restart, as made in several other scripts. 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 | 54 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/package/radvd/S50radvd b/package/radvd/S50radvd index 9f1407c95a..c27ac4302e 100755 --- a/package/radvd/S50radvd +++ b/package/radvd/S50radvd @@ -1,18 +1,46 @@ #!/bin/sh -RADVD=/usr/sbin/radvd +test -f /etc/radvd.conf || exit 0 -echo "1" > /proc/sys/net/ipv6/conf/all/forwarding - -printf "Starting radvd: " -if [ ! -x "${RADVD}" ]; then - echo "missing" +test -f /proc/sys/net/ipv6/conf/all/forwarding || { + echo "Error: radvd requires IPv6 forwarding support." exit 1 -fi +} -if ${RADVD} ; then - echo "done" -else - echo "failed" - exit 1 -fi +start() { + printf "Starting radvd: " + echo "1" > /proc/sys/net/ipv6/conf/all/forwarding + start-stop-daemon -S -x /usr/sbin/radvd || { + echo "FAIL" + exit 1 + } + echo "OK" +} + +stop() { + printf "Stopping radvd: " + start-stop-daemon -K -q -x /usr/sbin/radvd || { + echo "FAIL" + exit 1 + } + echo "OK" +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart|reload) + stop + sleep 1 + start + ;; + *) + echo "Usage: $0 {start|stop|restart}" + exit 1 +esac + +exit 0