From patchwork Sun Oct 25 00:59:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Beno=C3=AEt_Th=C3=A9baudeau?= X-Patchwork-Id: 535525 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ozlabs.org (Postfix) with ESMTP id 9F76414131D for ; Sun, 25 Oct 2015 12:01:05 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=rBTG5WNd; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id D922E31651; Sun, 25 Oct 2015 01:01:04 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rOXaNz6QzOK2; Sun, 25 Oct 2015 01:00:59 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 1088631A06; Sun, 25 Oct 2015 01:00:25 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 2C96D1C108E for ; Sun, 25 Oct 2015 01:00:14 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 1F32D30C64 for ; Sun, 25 Oct 2015 01:00:14 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tfgncR3tyuVC for ; Sun, 25 Oct 2015 01:00:06 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com [209.85.212.171]) by silver.osuosl.org (Postfix) with ESMTPS id 71606316FB for ; Sun, 25 Oct 2015 00:59:59 +0000 (UTC) Received: by wijp11 with SMTP id p11so121393691wij.0 for ; Sat, 24 Oct 2015 17:59:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=3TrcXnn52w49hep5eQaZqx7KcM7R0ADm7onr8XkyHNs=; b=rBTG5WNdpihhzBv3ZehW4K+j6qwBnkSilm7LcUqCDihBMbnWt0lAMMTTgwTkRYbARK oW2L0uLstCcVIyQu6VjvkH9/wTJ/wqnGe2KH5qiAUUjexFzz83f3mDYykmNPvz5Iap7a m7fq+xmez8zFnCOIhPvf7lc+ppWbGEkqNRQULdFNS5YmVp1V9UtZPZIar5EFCWrMqV8Z Z/LcFCYV998efTK7DhkARBM7k5QPCVUrDb3v5e6V5fIUghSaZ9ipr+npL1CTTX1FC45a O7UiAj0Nk0EJsJf38CSXTVzp6k1ieqZD8F7FFKjwA7PTGVIRZYGVX2BrCQfUBsFG3e6p wfRA== X-Received: by 10.194.122.42 with SMTP id lp10mr14961497wjb.51.1445734798176; Sat, 24 Oct 2015 17:59:58 -0700 (PDT) Received: from localhost.localdomain (vno44-1-88-172-188-148.fbx.proxad.net. [88.172.188.148]) by smtp.gmail.com with ESMTPSA id jd9sm8406757wic.0.2015.10.24.17.59.57 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 24 Oct 2015 17:59:57 -0700 (PDT) From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= To: Date: Sun, 25 Oct 2015 02:59:38 +0200 Message-Id: <1445734779-7212-12-git-send-email-benoit.thebaudeau.dev@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1445734779-7212-1-git-send-email-benoit.thebaudeau.dev@gmail.com> References: <1445734779-7212-1-git-send-email-benoit.thebaudeau.dev@gmail.com> MIME-Version: 1.0 Cc: Thomas Petazzoni , =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Subject: [Buildroot] [PATCH v3 12/13] package/dhcp: SysV init scripts: refactor using functions X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" From: Benoît Thébaudeau 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 --- Changes v2 -> v3: none. Changes v1 -> v2: - Rebase. - Use 'printf' instead of 'echo -n' following 0f75b2635ee564fbbdb9ea631cf39fa8731d6d6c. --- 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 9b8d65f..b48f72c 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 $ -# -# What servers should the DHCP relay forward requests to? -# e.g: SERVERS="192.168.0.1" -SERVERS="" +NAME="dhcrelay" +DESC="DHCP relay" +DAEMON="/usr/sbin/${NAME}" -# On what interfaces should the DHCP relay (dhrelay) serve DHCP requests? +# 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" +SERVERS="" + # 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() +{ + printf "Starting ${DESC}: " + start-stop-daemon -S -q -x "${DAEMON}" -- -q $OPTIONS $IFCMD $SERVERS && + echo "OK" || echo "FAIL" +} + +stop() +{ + printf "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) - printf "Starting DHCP relay: " - start-stop-daemon -S -q -x /usr/sbin/dhcrelay -- -q $OPTIONS $IFCMD $SERVERS - [ $? = 0 ] && echo "OK" || echo "FAIL" + start ;; stop) - printf "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 b6f76ee..607f1ca 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() +{ + printf "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() +{ + printf "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) - printf "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) - printf "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