Score:0

How to run service after kernel module is loaded

in flag

I have been breaking my head over this the last few hours. On one of my machines the intel-rapl-msr driver is buggy and reloading it fixes the issue. I thought I could trivially create a service that does this on boot. But I can't get the service to load after the driver has loaded.

[Unit]
Description=Reload intel-rapl-msr
Requires=systemd-modules-load.target
WantedBy=multi-user.target

ExecStart=/nix/store/wqjkhyyffqdbx767vlqklzi12ln8j3pv-unit-script-cpu-script-start/bin/cpu-script-start

Where the script in ExecStart simply contains:

rmmod intel_rapl_msr
modprobe intel_rapl_msr

This way the service fails on boot with the message:

mmod: ERROR: Module intel_rapl_msr is not currently loaded

So is it possible to force a service to run after this kernel module is loaded?

Any help is appreciated!

stark avatar
mu flag
Remove rmmod from your script and add to conf: `ExecStartPre=-rmmod intel_rapl_msr` The "-" means ignore failure.
John Smith avatar
in flag
@stark But I don't want to ignore failure. The driver is always loaded on boot.
Score:0
in flag

So now I just poll with lsmod it works but it's kind of dirty:

while ! lsmod | grep -q intel_rapl_msr;
do
  echo "intel_rapl_msr not loaded yet... sleeping for 5 seconds"
  sleep 5
done
echo "found intel_rapl_msr"
rmmod intel_rapl_msr
modprobe intel_rapl_msr
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.