Skip to content

Commit 32a00a9

Browse files
Conan-Kudokeszybz
authored andcommitted
Add more file triggers to handle more aspects of systemd (systemd#8090)
For quite a while now, there have been file triggers to handle automatically setting up service units in upstream systemd. However, most of the actions being done by these macros upon files can be set up as RPM file triggers. In fact, in Mageia, we had been doing this for most of these. In particular, we have file triggers in place for sysusers, tmpfiles, hwdb, and the journal. This change adds Lua versions of the original file triggers used in Mageia, based on the existing Lua-based file triggers for service units. In addition, we can also have useful file triggers for udev rules, sysctl directives, and binfmt directives. These are based on the other existing file triggers.
1 parent 9207564 commit 32a00a9

File tree

2 files changed

+90
-9
lines changed

2 files changed

+90
-9
lines changed

src/core/macros.systemd.in

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,11 @@ fi \
8484

8585
%systemd_user_postun_with_restart() %{nil}
8686

87-
%udev_hwdb_update() \
88-
systemd-hwdb update >/dev/null 2>&1 || : \
89-
%{nil}
87+
%udev_hwdb_update() %{nil}
9088

91-
%udev_rules_update() \
92-
udevadm control --reload >/dev/null 2>&1 || : \
93-
%{nil}
89+
%udev_rules_update() %{nil}
9490

95-
%journal_catalog_update() \
96-
journalctl --update-catalog >/dev/null 2>&1 || : \
97-
%{nil}
91+
%journal_catalog_update() %{nil}
9892

9993
%tmpfiles_create() \
10094
systemd-tmpfiles --create %{?*} >/dev/null 2>&1 || : \

src/core/triggers.systemd.in

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# This file is part of systemd.
55
#
66
# Copyright 2015 Zbigniew Jędrzejewski-Szmek
7+
# Copyright 2018 Neal Gompa
78
#
89
# systemd is free software; you can redistribute it and/or modify it
910
# under the terms of the GNU Lesser General Public License as published by
@@ -69,3 +70,89 @@ if posix.access("%{_localstatedir}/lib/rpm-state/systemd/needs-reload") then
6970
posix.wait(pid)
7071
end
7172
end
73+
74+
%transfiletriggerin -P 100700 -p <lua> -- @sysusersdir@
75+
-- This script will process files installed in @sysusersdir@ to create
76+
-- specified users automatically. The priority is set such that it
77+
-- will run before the tmpfiles file trigger.
78+
if posix.access("/run/systemd/system") then
79+
pid = posix.fork()
80+
if pid == 0 then
81+
assert(posix.exec("%{_bindir}/systemd-sysusers"))
82+
elseif pid > 0 then
83+
posix.wait(pid)
84+
end
85+
end
86+
87+
%transfiletriggerin -P 100500 -- @tmpfilesdir@
88+
-- This script will process files installed in @tmpfilesdir@ to create
89+
-- tmpfiles automatically. The priority is set such that it will run
90+
-- after the sysusers file trigger, but before any other triggers.
91+
if posix.access("/run/systemd/system") then
92+
pid = posix.fork()
93+
if pid == 0 then
94+
assert(posix.exec("%{_bindir}/systemd-tmpfiles", "--create"))
95+
elseif pid > 0 then
96+
posix.wait(pid)
97+
end
98+
end
99+
100+
%transfiletriggerin -- @udevhwdbdir@
101+
-- This script will automatically invoke hwdb update if files have been
102+
-- installed or updated in @udevhwdbdir@.
103+
if posix.access("/run/systemd/system") then
104+
pid = posix.fork()
105+
if pid == 0 then
106+
assert(posix.exec("%{_bindir}/systemd-hwdb", "update"))
107+
elseif pid > 0 then
108+
posix.wait(pid)
109+
end
110+
end
111+
112+
%transfiletriggerin -- @catalogdir@
113+
-- This script will automatically invoke journal catalog update if files
114+
-- have been installed or updated in @catalogdir@.
115+
if posix.access("/run/systemd/system") then
116+
pid = posix.fork()
117+
if pid == 0 then
118+
assert(posix.exec("%{_bindir}/journalctl", "--update-catalog"))
119+
elseif pid > 0 then
120+
posix.wait(pid)
121+
end
122+
end
123+
124+
%transfiletriggerin -- @udevrulesdir@
125+
-- This script will automatically update udev with new rules if files
126+
-- have been installed or updated in @udevrulesdir@.
127+
if posix.access("/run/systemd/system") then
128+
pid = posix.fork()
129+
if pid == 0 then
130+
assert(posix.exec("%{_bindir}/udevadm", "control", "--reload"))
131+
elseif pid > 0 then
132+
posix.wait(pid)
133+
end
134+
end
135+
136+
%transfiletriggerin -- @sysctldir@
137+
-- This script will automatically apply sysctl rules if files have been
138+
-- installed or updated in @sysctldir@.
139+
if posix.access("/run/systemd/system") then
140+
pid = posix.fork()
141+
if pid == 0 then
142+
assert(posix.exec("@rootlibexecdir@/systemd-sysctl"))
143+
elseif pid > 0 then
144+
posix.wait(pid)
145+
end
146+
end
147+
148+
%transfiletriggerin -- @binfmtdir@
149+
-- This script will automatically apply binfmt rules if files have been
150+
-- installed or updated in @binfmtdir@.
151+
if posix.access("/run/systemd/system") then
152+
pid = posix.fork()
153+
if pid == 0 then
154+
assert(posix.exec("@rootlibexecdir@/systemd-binfmt"))
155+
elseif pid > 0 then
156+
posix.wait(pid)
157+
end
158+
end

0 commit comments

Comments
 (0)