커널 모듈이 로드된 후 서비스를 실행하는 방법

커널 모듈이 로드된 후 서비스를 실행하는 방법

나는 지난 몇 시간 동안 이 문제 때문에 머리가 아팠습니다. 내 컴퓨터 중 하나에서 intel-rapl-msr드라이버에 버그가 있어서 다시 로드하면 문제가 해결됩니다. 부팅 시 이 작업을 수행하는 서비스를 간단하게 만들 수 있다고 생각했습니다. 하지만 드라이버가 로드된 후에는 서비스를 로드할 수 없습니다.

[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

의 스크립트에는 ExecStart다음이 포함됩니다.

rmmod intel_rapl_msr
modprobe intel_rapl_msr

이렇게 하면 부팅 시 다음 메시지와 함께 서비스가 실패합니다.

mmod: ERROR: Module intel_rapl_msr is not currently loaded

그렇다면 이 커널 모듈이 로드된 후에 서비스를 강제로 실행하는 것이 가능합니까?

도움을 주시면 감사하겠습니다!

답변1

systemd-modules-load.service를 사용하여 이러한 모듈을 로드하기 시작한 서비스의 모듈 종속성을 해결했습니다.

실제로는 다음 위치에 모듈을 추가하세요: /etc/modules-load.d/modules.conf

https://www.freedesktop.org/software/systemd/man/modules-load.d.html#

답변2

이제 나는 lsmod그것이 작동하는지 폴링하지만 그것은 좀 더러워집니다.

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

관련 정보