blob: 6640c47cb751af378461c89d6e8c0fe33f9fe653 [file] [log] [blame]
Zbigniew Jędrzejewski-Szmek8b4408b2016-04-04 10:51:55 -04001# -*- 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%transfiletriggerin -P 900900 -p <lua> -- /usr/lib/systemd/system /etc/systemd/system
23-- This script will run after any package is initially installed or
24-- upgraded. We care about the case where a package is initially
25-- installed, because other cases are covered by the *un scriptlets,
26-- so sometimes we will reload needlessly.
27
28pid = posix.fork()
29if pid == 0 then
30 assert(posix.exec("%{_bindir}/systemctl", "daemon-reload"))
31elseif pid > 0 then
32 posix.wait(pid)
33end
34
35%transfiletriggerun -p <lua> -- /usr/lib/systemd/system /etc/systemd/system
36-- On removal, we need to run daemon-reload after any units have been
37-- removed. %transfiletriggerpostun would be ideal, but it does not get
38-- executed for some reason.
39-- On upgrade, we need to run daemon-reload after any new unit files
40-- have been installed, but before %postun scripts in packages get
41-- executed. %transfiletriggerun gets the right list of files
42-- but it is invoked too early (before changes happen).
43-- %filetriggerpostun happens at the right time, but it fires for
44-- every package.
45-- To execute the reload at the right time, we create a state
46-- file in %transfiletriggerun and execute the daemon-reload in
47-- the first %filetriggerpostun.
48
49posix.mkdir("%{_localstatedir}/lib")
50posix.mkdir("%{_localstatedir}/lib/rpm-state")
51posix.mkdir("%{_localstatedir}/lib/rpm-state/systemd")
52io.open("%{_localstatedir}/lib/rpm-state/systemd/needs-reload", "w")
53
54%filetriggerpostun -P 1000100 -p <lua> -- /usr/lib/systemd/system /etc/systemd/system
55if posix.access("%{_localstatedir}/lib/rpm-state/systemd/needs-reload") then
56 posix.unlink("%{_localstatedir}/lib/rpm-state/systemd/needs-reload")
57 posix.rmdir("%{_localstatedir}/lib/rpm-state/systemd")
58 pid = posix.fork()
59 if pid == 0 then
60 assert(posix.exec("%{_bindir}/systemctl", "daemon-reload"))
61 elseif pid > 0 then
62 posix.wait(pid)
63 end
64end