[systemd-devel] Recommendation for "systemd.module" unit
Lennart Poettering
lennart at poettering.net
Thu Jan 24 16:03:47 PST 2013
On Thu, 24.01.13 14:08, Larry Baker (baker at usgs.gov) wrote:
> I am converting the init script (see below) for Linux DECnet (http://sourceforge.net/projects/linux-decnet). This is my first exposure to systemd. Naturally, my first try failed. So, now I am taking baby steps.
>
> The Linux DECnet init script can start either or both the dnetd or
> phoned daemons. (I do not use the phoned daemon.) I think the best
> thing to do with smartd is make them separate service units. I will
> create /etc/systemd/system/dnetd.service and .../phoned.service.
>
> Prior to starting the daemons, the init script verifies the
> /etc/decnet.conf configuration file exists. I will use the [Unit]
> option ConditionFileNotEmpty=/etc/decnet.conf to replicate that
> behavior.
>
> Then it looks for evidence that the decnet kernel module is loaded by
> testing for the file /proc/net/decnet. If necessary, it loads the
> decnet kernel module and checks again for /proc/net/decnet. I have
> already built the decnet kernel module and I can load it with
> modprobe. I do not wish to force an unconditional load of the decnet
> kernel module using /etc/modules-load.d/decnet.conf; I prefer the
> services that need it (dnetd and phoned) trigger the load. However, I
> find no mention of the standard systemd "load a kernel module"
> practice. I.e., there is no "systemd.module" unit. What is the
> recommended method in the systemd framework to trigger a unit that
> loads a kernel module? If the modprobe command fails, I presume that
> will cause the systemd start command to fail. I would also like the
> systemd start command to fail if /proc/net/decnet is not created (a
> sign that the module has not initialized itself correctly). Is there
> a syntax in a systemd unit for that as well?
Usually the best way to handle this is to make the module auto-loadable
by the kernel, which makes the whole thing entirely transparent to
userspace. The first process using a DECNET socket would implicitly load
the module, just by invoking socket() and the kernel would do the rest.
This is usually done via MODALIAS strings for "net-pf-xyz" in the kernel
modules. If the decnet module currently doesn't support this it should
be a single line change.
Currently, many other protocol families that are implemented in kernel
modules already do that, including bluetooth, atm, irda, nfc. For a
precise list, see:
grep net-pf /lib/modules/`uname -r`/modules.alias
You have a good chance that adding that one MODALIAS name to your kernel
module will already allow you to drop any explicit modprobes from your
init scripts/units.
A temporary hack to achieve the same is by adding an "alias" line to
/etc/modprobe.d/ for the same mapping. That said, ultimately this really
should be fixed in the kernel.
Lennart
--
Lennart Poettering - Red Hat, Inc.
More information about the systemd-devel
mailing list