From 8841eb005d90e7e49bc0c9bb64a48fa468f2b1db Mon Sep 17 00:00:00 2001 From: Fiona Klute Date: Wed, 5 Jun 2024 13:13:47 +0200 Subject: [PATCH] package/busybox: add ifplugd init script The init script will be installed only if no other package provides ifplugd (currently that could be package/ifplugd). Users can configure the interface(s) which ifplugd should watch either using /etc/default/ifplugd (for one interface) or using per-interface symlinks to the script in /etc/init.d (for any number of interfaces). The action script that ifplugd runs when a link change is detected must be supplied separately. Signed-off-by: Fiona Klute Signed-off-by: Thomas Petazzoni --- package/busybox/S41ifplugd | 85 ++++++++++++++++++++++++++++++++++++++ package/busybox/busybox.mk | 13 ++++++ 2 files changed, 98 insertions(+) create mode 100644 package/busybox/S41ifplugd diff --git a/package/busybox/S41ifplugd b/package/busybox/S41ifplugd new file mode 100644 index 0000000000..8c2c1a5038 --- /dev/null +++ b/package/busybox/S41ifplugd @@ -0,0 +1,85 @@ +#!/bin/sh + +DAEMON="ifplugd" + +# Each ifplugd instance handles only one interface, so this script is +# designed to be symlinked per interface. For each interface create a +# symlink with .IFACE appended to the name. E.g. to launch ifplugd for +# eth1 create a symlink from /etc/init.d/S41ifplugd.eth1 to this +# script. DEFAULT_IFACE sets the interface the non-symlink script will +# use, set it to empty in /etc/default/ifplugd to disable the default +# instance and use symlinked instances only. +DEFAULT_IFACE="eth0" +# If your action script is not in the default location +# /etc/ifplugd/ifplugd.action, use the "-r" option to set the +# location. +IFPLUGD_ARGS="-M" + +# shellcheck source=/dev/null +[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON" + +NAME_IFACE="$(basename "$0" | cut -s -d. -f2)" +if [ -n "$NAME_IFACE" ]; then + IFACE="${NAME_IFACE}" +elif [ -n "$DEFAULT_IFACE" ]; then + IFACE="${DEFAULT_IFACE}" +else + # no interface configured + exit 0 +fi + +# check-package disable Variables +PIDFILE="/var/run/${DAEMON}.${IFACE}.pid" +IFPLUGD_ARGS="${IFPLUGD_ARGS} -i ${IFACE}" + +# BusyBox' ifplugd does not create a pidfile, so pass "-n" in the +# command line and use "--make-pidfile" to instruct start-stop-daemon +# to create one. +start() { + printf 'Starting %s for %s: ' "$DAEMON" "$IFACE" + # shellcheck disable=SC2086 # we need the word splitting + start-stop-daemon --start --background --make-pidfile \ + --pidfile "$PIDFILE" --exec "/usr/sbin/$DAEMON" \ + -- -n $IFPLUGD_ARGS + status=$? + if [ "$status" -eq 0 ]; then + echo "OK" + else + echo "FAIL" + fi + return "$status" +} + +stop() { + printf 'Stopping %s for %s: ' "$DAEMON" "$IFACE" + start-stop-daemon --stop --pidfile "$PIDFILE" --exec "/usr/sbin/$DAEMON" + status=$? + if [ "$status" -eq 0 ]; then + echo "OK" + else + echo "FAIL" + return "$status" + fi + while start-stop-daemon --stop --test --quiet --pidfile "$PIDFILE" \ + --exec "/sbin/$DAEMON"; do + sleep 0.1 + done + rm -f "$PIDFILE" + return "$status" +} + +restart() { + stop + start +} + +case "$1" in + start|stop|restart) + "$1";; + reload) + # Restart, since there is no true "reload" feature. + restart;; + *) + echo "Usage: $0 {start|stop|restart|reload}" + exit 1 +esac diff --git a/package/busybox/busybox.mk b/package/busybox/busybox.mk index f1e0a7e6da..6c20a98d2d 100644 --- a/package/busybox/busybox.mk +++ b/package/busybox/busybox.mk @@ -324,6 +324,17 @@ define BUSYBOX_INSTALL_CROND_SCRIPT endef endif +# Only install our ifplugd script if no other package does it. +ifeq ($(BR2_PACKAGE_IFPLUGD),) +define BUSYBOX_INSTALL_IFPLUGD_SCRIPT + if grep -q CONFIG_IFPLUGD=y $(@D)/.config; \ + then \ + $(INSTALL) -m 0755 -D package/busybox/S41ifplugd \ + $(TARGET_DIR)/etc/init.d/S41ifplugd; \ + fi; +endef +endif + ifeq ($(BR2_INIT_BUSYBOX),y) define BUSYBOX_INSTALL_INITTAB if test ! -e $(TARGET_DIR)/etc/inittab; then \ @@ -419,6 +430,7 @@ define BUSYBOX_INSTALL_INIT_OPENRC $(BUSYBOX_INSTALL_MDEV_SCRIPT) $(BUSYBOX_INSTALL_LOGGING_SCRIPT) $(BUSYBOX_INSTALL_WATCHDOG_SCRIPT) + $(BUSYBOX_INSTALL_IFPLUGD_SCRIPT) $(BUSYBOX_INSTALL_CROND_SCRIPT) $(BUSYBOX_INSTALL_TELNET_SCRIPT) endef @@ -432,6 +444,7 @@ define BUSYBOX_INSTALL_INIT_SYSV $(BUSYBOX_INSTALL_LOGGING_SCRIPT) $(BUSYBOX_INSTALL_WATCHDOG_SCRIPT) $(BUSYBOX_INSTALL_SYSCTL_SCRIPT) + $(BUSYBOX_INSTALL_IFPLUGD_SCRIPT) $(BUSYBOX_INSTALL_CROND_SCRIPT) $(BUSYBOX_INSTALL_TELNET_SCRIPT) endef