modules: misc: Add a pattern for systemd daemon reload

It would be really nice if systemd actually had an API for getting
events on this.
This commit is contained in:
James Shubin
2025-05-14 21:21:27 -04:00
parent aa4320dd5f
commit 0847b27f6a

View File

@@ -30,6 +30,7 @@
import "golang" import "golang"
import "golang/strings" import "golang/strings"
import "iter" import "iter"
import "local"
import "net" import "net"
import "os" import "os"
import "world/collect" import "world/collect"
@@ -190,3 +191,33 @@ mac-address={{ .mac }}
svc "NetworkManager" { svc "NetworkManager" {
} }
} }
# systemd_daemon_reload creates an exec which runs a systemctl daemon-reload if
# one is needed. The exec resource uses the input name, to make it easy to
# attach an edge to it.
# TODO: can we use: systemctl show foo.service --property=NeedDaemonReload
class systemd_daemon_reload($name) {
$vardir = local.vardir("misc/")
$mtime_file = "${vardir}daemon-reload"
exec "${name}" {
cmd => "/usr/bin/systemctl",
args => [
"daemon-reload",
],
donecmd => "/usr/bin/date --utc > ${mtime_file}",
doneshell => "/usr/bin/bash",
watchfiles => [
"/lib/systemd/system/",
"/etc/systemd/system/",
"${mtime_file}",
],
# If we have any file that's newer than our mtime, the run.
# NOTE: We grep since find doesn't return a useful return code.
ifcmd => "/usr/bin/test ! -e '${mtime_file}' || /usr/bin/find /lib/systemd/system/ /etc/systemd/system/ -type f -name '*.service' -newer '${mtime_file}' | /usr/bin/grep -q .",
ifshell => "/usr/bin/bash",
}
}