8b4408b
#  -*- Mode: rpm-spec; indent-tabs-mode: nil -*- */
8b4408b
#
8b4408b
#  This file is part of systemd.
8b4408b
#
8b4408b
#  Copyright 2015 Zbigniew Jędrzejewski-Szmek
8b4408b
#
8b4408b
#  systemd is free software; you can redistribute it and/or modify it
8b4408b
#  under the terms of the GNU Lesser General Public License as published by
8b4408b
#  the Free Software Foundation; either version 2.1 of the License, or
8b4408b
#  (at your option) any later version.
8b4408b
#
8b4408b
#  systemd is distributed in the hope that it will be useful, but
8b4408b
#  WITHOUT ANY WARRANTY; without even the implied warranty of
8b4408b
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8b4408b
#  Lesser General Public License for more details.
8b4408b
#
8b4408b
#  You should have received a copy of the GNU Lesser General Public License
8b4408b
#  along with systemd; If not, see <http://www.gnu.org/licenses/>.
8b4408b
8b4408b
# The contents of this are an example to be copied into systemd.spec.
8b4408b
8b4408b
%transfiletriggerin -P 900900 -p <lua> -- /usr/lib/systemd/system /etc/systemd/system
8b4408b
-- This script will run after any package is initially installed or
8b4408b
-- upgraded. We care about the case where a package is initially
8b4408b
-- installed, because other cases are covered by the *un scriptlets,
8b4408b
-- so sometimes we will reload needlessly.
8b4408b
8b4408b
pid = posix.fork()
8b4408b
if pid == 0 then
8b4408b
    assert(posix.exec("%{_bindir}/systemctl", "daemon-reload"))
8b4408b
elseif pid > 0 then
8b4408b
    posix.wait(pid)
8b4408b
end
8b4408b
8b4408b
%transfiletriggerun -p <lua> -- /usr/lib/systemd/system /etc/systemd/system
8b4408b
-- On removal, we need to run daemon-reload after any units have been
8b4408b
-- removed. %transfiletriggerpostun would be ideal, but it does not get
8b4408b
-- executed for some reason.
8b4408b
-- On upgrade, we need to run daemon-reload after any new unit files
8b4408b
-- have been installed, but before %postun scripts in packages get
8b4408b
-- executed. %transfiletriggerun gets the right list of files
8b4408b
-- but it is invoked too early (before changes happen).
8b4408b
-- %filetriggerpostun happens at the right time, but it fires for
8b4408b
-- every package.
8b4408b
-- To execute the reload at the right time, we create a state
8b4408b
-- file in %transfiletriggerun and execute the daemon-reload in
8b4408b
-- the first %filetriggerpostun.
8b4408b
8b4408b
posix.mkdir("%{_localstatedir}/lib")
8b4408b
posix.mkdir("%{_localstatedir}/lib/rpm-state")
8b4408b
posix.mkdir("%{_localstatedir}/lib/rpm-state/systemd")
8b4408b
io.open("%{_localstatedir}/lib/rpm-state/systemd/needs-reload", "w")
8b4408b
8b4408b
%filetriggerpostun -P 1000100 -p <lua> -- /usr/lib/systemd/system /etc/systemd/system
8b4408b
if posix.access("%{_localstatedir}/lib/rpm-state/systemd/needs-reload") then
8b4408b
    posix.unlink("%{_localstatedir}/lib/rpm-state/systemd/needs-reload")
8b4408b
    posix.rmdir("%{_localstatedir}/lib/rpm-state/systemd")
8b4408b
    pid = posix.fork()
8b4408b
    if pid == 0 then
8b4408b
        assert(posix.exec("%{_bindir}/systemctl", "daemon-reload"))
8b4408b
    elseif pid > 0 then
8b4408b
        posix.wait(pid)
8b4408b
    end
8b4408b
end