From 035f496978eafd822115a176f4aeb7e281c91717 Mon Sep 17 00:00:00 2001 From: Angelo Compagnucci Date: Sat, 7 Oct 2023 22:36:33 +0200 Subject: [PATCH] package/initscripts: add service to load kernel modules at boot In cases where no hotplug is available (by choice or by the lack of a proper hotplug method for a device), this service can be used to load kernel module drivers by reading the /etc/modules-load.d/*.conf files. The modules files matches the one used by systemd, which in turn has a builtin mechanism to load a module at boot, therefore making systemv init on par with systemd features. Signed-off-by: Angelo Compagnucci [Arnout: - add exception for missing DAEMON variable; - fix shellcheck warnings ] Signed-off-by: Arnout Vandecappelle Signed-off-by: Arnout Vandecappelle --- package/initscripts/init.d/S11modules | 62 +++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 package/initscripts/init.d/S11modules diff --git a/package/initscripts/init.d/S11modules b/package/initscripts/init.d/S11modules new file mode 100644 index 0000000000..ab9b93dae3 --- /dev/null +++ b/package/initscripts/init.d/S11modules @@ -0,0 +1,62 @@ +#!/bin/sh + +MODULES_DIR="/etc/modules-load.d/" + +[ -z "$(ls -A ${MODULES_DIR} 2> /dev/null)" ] && exit 0 + +load_unload() { + for module_file in "${MODULES_DIR}"/*.conf; do + while read -r module args; do + + case "$module" in + ""|"#"*) continue ;; + esac + + if [ "$1" = "load" ]; then + # shellcheck disable=SC2086 # We need word splitting for args + modprobe -q "${module}" ${args} >/dev/null && \ + printf '%s ' "$module" || RET='FAIL' + else + rmmod "${module}" >/dev/null + fi + + done < "${module_file}" + done + + RET='OK' +} + +start() { + printf 'Starting modules: ' + + load_unload load + + echo $RET +} + +stop() { + printf 'Stopping modules: ' + + load_unload unload + + echo $RET +} + +restart() { + stop + sleep 1 + 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 + +# check-package Ignore missing DAEMON Variables