mirror of
https://gitlab.com/buildroot.org/buildroot.git
synced 2026-08-08 00:20:38 -09:00
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 <fiona.klute+wiwa@gmx.de> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
committed by
Thomas Petazzoni
parent
b341023981
commit
8841eb005d
85
package/busybox/S41ifplugd
Normal file
85
package/busybox/S41ifplugd
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user