]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/triggers.systemd.in
Rework file trigger scripts to fire at the right time
[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 # This will run after any package is initially installed or
23 # upgraded. We care about the case where a package is initially
24 # installed, because other cases are covered by the scriptlets below,
25 # so sometimes we will reload needlessly.
26
27 %transfiletriggerin -- @systemunitdir@ /etc/systemd/system
28 systemctl daemon-reload &>/dev/null || :
29
30 # On removal, we need to run daemon-reload after any units have been
31 # removed. %transfiletriggerpostun would be ideal, but it does not get
32 # executed for some reason.
33 # On upgrade, we need to run daemon-reload after any new unit files
34 # have been installed, but before %postun scripts in packages get
35 # executed. %transfiletriggerun gets the right list of files
36 # but it is invoked too early (before changes happen).
37 # %filetriggerpostun happens at the right time, but it fires for
38 # every package.
39 # To execute the reload at the right time, we create a state
40 # file in %transfiletriggerun and execute the daemon-reload in
41 # the first %filetriggerpostun.
42
43 %transfiletriggerun -- @systemunitdir@ /etc/systemd/system
44 mkdir -p %{_localstatedir}/lib/rpm-state/systemd
45 touch %{_localstatedir}/lib/rpm-state/systemd/needs-reload
46
47 %filetriggerpostun -- @systemunitdir@ /etc/systemd/system
48 if [ -e %{_localstatedir}/lib/rpm-state/systemd/needs-reload ]; then
49 rm %{_localstatedir}/lib/rpm-state/systemd/needs-reload || :
50 rmdir %{_localstatedir}/lib/rpm-state/systemd || :
51 systemctl daemon-reload || :
52 fi