]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/triggers.systemd.in
Merge pull request #5069 from keszybz/fixlets
[thirdparty/systemd.git] / src / core / triggers.systemd.in
1 # -*- Mode: rpm-spec; indent-tabs-mode: nil -*- */
2 #
3 # This file is part of systemd.
4 #
5 # Copyright 2015 Zbigniew Jędrzejewski-Szmek
6 #
7 # systemd is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation; either version 2.1 of the License, or
10 # (at your option) any later version.
11 #
12 # systemd is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
19
20 # The contents of this are an example to be copied into systemd.spec.
21 #
22 # Minimum rpm version supported: 4.13.0
23
24 %transfiletriggerin -P 900900 -p <lua> -- @systemunitdir@ /etc/systemd/system
25 -- This script will run after any package is initially installed or
26 -- upgraded. We care about the case where a package is initially
27 -- installed, because other cases are covered by the *un scriptlets,
28 -- so sometimes we will reload needlessly.
29
30 if posix.access("/run/systemd/system") then
31 pid = posix.fork()
32 if pid == 0 then
33 assert(posix.exec("%{_bindir}/systemctl", "daemon-reload"))
34 elseif pid > 0 then
35 posix.wait(pid)
36 end
37 end
38
39 %transfiletriggerun -p <lua> -- @systemunitdir@ /etc/systemd/system
40 -- On removal, we need to run daemon-reload after any units have been
41 -- removed. %transfiletriggerpostun would be ideal, but it does not get
42 -- executed for some reason.
43 -- On upgrade, we need to run daemon-reload after any new unit files
44 -- have been installed, but before %postun scripts in packages get
45 -- executed. %transfiletriggerun gets the right list of files
46 -- but it is invoked too early (before changes happen).
47 -- %filetriggerpostun happens at the right time, but it fires for
48 -- every package.
49 -- To execute the reload at the right time, we create a state
50 -- file in %transfiletriggerun and execute the daemon-reload in
51 -- the first %filetriggerpostun.
52
53 if posix.access("/run/systemd/system") then
54 posix.mkdir("%{_localstatedir}/lib")
55 posix.mkdir("%{_localstatedir}/lib/rpm-state")
56 posix.mkdir("%{_localstatedir}/lib/rpm-state/systemd")
57 io.open("%{_localstatedir}/lib/rpm-state/systemd/needs-reload", "w")
58 end
59
60 %filetriggerpostun -P 1000100 -p <lua> -- @systemunitdir@ /etc/systemd/system
61 if posix.access("%{_localstatedir}/lib/rpm-state/systemd/needs-reload") then
62 posix.unlink("%{_localstatedir}/lib/rpm-state/systemd/needs-reload")
63 posix.rmdir("%{_localstatedir}/lib/rpm-state/systemd")
64 pid = posix.fork()
65 if pid == 0 then
66 assert(posix.exec("%{_bindir}/systemctl", "daemon-reload"))
67 elseif pid > 0 then
68 posix.wait(pid)
69 end
70 end