diff mbox series

[v3,5/5] package/initscripts: add service to load kernel modules at boot

Message ID 20220705073206.1442280-6-angelo@amarulasolutions.com
State Superseded
Headers show
Series Configure default wifi through kconfig | expand

Commit Message

Angelo Compagnucci July 5, 2022, 7:32 a.m. UTC
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 file.
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 <angelo@amarulasolutions.com>
---
Changes

v2:
* Moved script to initscripts (Arnout)
* Moved script to S11modules, after S10[mu]dev (Andreas)
* Use /etc/modules-load.d/ to share the same setup with systemd (me)

 package/initscripts/init.d/S11modules | 59 +++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 package/initscripts/init.d/S11modules

Comments

Peter Korsgaard Sept. 18, 2022, 10:10 a.m. UTC | #1
>>>>> "Angelo" == Angelo Compagnucci <angelo@amarulasolutions.com> writes:

 > 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 file.
 > 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 <angelo@amarulasolutions.com>
 > ---
 > Changes

 > v2:
 > * Moved script to initscripts (Arnout)
 > * Moved script to S11modules, after S10[mu]dev (Andreas)
 > * Use /etc/modules-load.d/ to share the same setup with systemd (me)

 >  package/initscripts/init.d/S11modules | 59 +++++++++++++++++++++++++++
 >  1 file changed, 59 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..3937945596
 > --- /dev/null
 > +++ b/package/initscripts/init.d/S11modules
 > @@ -0,0 +1,59 @@
 > +#!/bin/sh
 > +
 > +MODULES="*.conf"
 > +MODULES_DIR="/etc/modules-load.d"
 > +
 > +[ -z "$(ls -A ${MODULES_DIR}/${MODULES} 2> /dev/null)" ] && exit 0

The commit message talks about /etc/modules, but you are reading from
/etc/modules-load.d/*.conf?

How about supporting both /etc/modules and this directory instead?


 > +
 > +load_unload() {
 > +	for module_file in $(ls -1 ${MODULES_DIR}); do

And here you take all files in /etc/modules-load.d, even if they don't
have a .conf extension?


> +			esac
 > +
 > +			if [ "$1" = "load" ]; then
 > +				modprobe -q ${module} ${args} >/dev/null && \
 > +					printf ' %s success,' "$module" ||
 > +					printf ' %s failed,' "$module"

success/failed are quite long strings, how about only printing the
module name on success and a big scary FAIL like we do elsewhere on
failures?
Angelo Compagnucci Oct. 3, 2022, 3:53 p.m. UTC | #2
On Sun, Sep 18, 2022 at 12:10 PM Peter Korsgaard <peter@korsgaard.com>
wrote:

> >>>>> "Angelo" == Angelo Compagnucci <angelo@amarulasolutions.com> writes:
>
>  > 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 file.
>  > 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 <angelo@amarulasolutions.com>
>  > ---
>  > Changes
>
>  > v2:
>  > * Moved script to initscripts (Arnout)
>  > * Moved script to S11modules, after S10[mu]dev (Andreas)
>  > * Use /etc/modules-load.d/ to share the same setup with systemd (me)
>
>  >  package/initscripts/init.d/S11modules | 59 +++++++++++++++++++++++++++
>  >  1 file changed, 59 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..3937945596
>  > --- /dev/null
>  > +++ b/package/initscripts/init.d/S11modules
>  > @@ -0,0 +1,59 @@
>  > +#!/bin/sh
>  > +
>  > +MODULES="*.conf"
>  > +MODULES_DIR="/etc/modules-load.d"
>  > +
>  > +[ -z "$(ls -A ${MODULES_DIR}/${MODULES} 2> /dev/null)" ] && exit 0
>
> The commit message talks about /etc/modules, but you are reading from
> /etc/modules-load.d/*.conf?
>

Yes, right, commit message must be fixed.


> How about supporting both /etc/modules and this directory instead?
>

It is doable, but if we are on par with systemd I cannot see why adding
/etc/modules. The same goal can be obtained easily dropping a file in
/etc/modules-load.d/ .


>
>
>  > +
>  > +load_unload() {
>  > +    for module_file in $(ls -1 ${MODULES_DIR}); do
>
> And here you take all files in /etc/modules-load.d, even if they don't
> have a .conf extension?
>

Nice catch.


>
> > +                     esac
>  > +
>  > +                    if [ "$1" = "load" ]; then
>  > +                            modprobe -q ${module} ${args} >/dev/null
> && \
>  > +                                    printf ' %s success,' "$module" ||
>  > +                                    printf ' %s failed,' "$module"
>
> success/failed are quite long strings, how about only printing the
> module name on success and a big scary FAIL like we do elsewhere on
> failures?
>

Nice suggestion.


>
> --
> Bye, Peter Korsgaard
>
diff mbox series

Patch

diff --git a/package/initscripts/init.d/S11modules b/package/initscripts/init.d/S11modules
new file mode 100644
index 0000000000..3937945596
--- /dev/null
+++ b/package/initscripts/init.d/S11modules
@@ -0,0 +1,59 @@ 
+#!/bin/sh
+
+MODULES="*.conf"
+MODULES_DIR="/etc/modules-load.d"
+
+[ -z "$(ls -A ${MODULES_DIR}/${MODULES} 2> /dev/null)" ] && exit 0
+
+load_unload() {
+	for module_file in $(ls -1 ${MODULES_DIR}); do
+		while read module args; do
+
+			case "$module" in
+				""|"#"*) continue ;;
+			esac
+
+			if [ "$1" = "load" ]; then
+				modprobe -q ${module} ${args} >/dev/null && \
+					printf ' %s success,' "$module" ||
+					printf ' %s failed,' "$module"
+			else
+				rmmod ${module} >/dev/null
+			fi
+
+		done < ${MODULES_DIR}/${module_file}
+	done
+}
+
+start() {
+	printf 'Starting modules:'
+
+	load_unload load
+
+	echo ' OK'
+}
+
+stop() {
+	printf 'Stopping modules:'
+
+	load_unload unload
+
+	echo 'OK'
+}
+
+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