From 590f18a27c05524f5332819b9580afc327b95d84 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 21 Jun 2012 22:14:17 +0200 Subject: rpm: include RPM macro definition for .spec snippets Let's try to standardize a bit the RPM macros used for installing/uninstalling services. This only covers the non-SysV compat bits, since that tends to vary widely between the various distros. Usage: Add %{?systemd_requires} to the header of the spec file. And then: %post %systemd_post foobar.service %preun %systemd_preun foobar.service %postun %systemd_postun foobar.service And, instead of the latter, in case the service shall be restarted on updates: %postun %systemd_postun_restart foobar.service --- src/core/macros.systemd.in | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/core/macros.systemd.in (limited to 'src/core/macros.systemd.in') diff --git a/src/core/macros.systemd.in b/src/core/macros.systemd.in new file mode 100644 index 0000000000..86e869307c --- /dev/null +++ b/src/core/macros.systemd.in @@ -0,0 +1,55 @@ +# -*- Mode: makefile; indent-tabs-mode: t -*- */ +# +# This file is part of systemd. +# +# Copyright 2012 Lennart Poettering +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. +# +# systemd is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with systemd; If not, see . + +# RPM macros for packages installing systemd unit files + +%_unitdir @systemunitdir@ + +%systemd_requires \ +Requires(post): systemd \ +Requires(preun): systemd \ +Requires(postun): systemd \ +%{nil} + +%systemd_post() \ +if [ $1 -eq 1 ] ; then \ + # Initial installation \ + @rootbindir@/systemctl preset %{?*} >/dev/null 2>&1 || : \ +fi \ +%{nil} + +%systemd_preun() \ +if [ $1 -eq 0 ] ; then \ + # Package removal, not upgrade \ + @rootbindir@/systemctl --no-reload disable %{?*} > /dev/null 2>&1 || : \ + @rootbindir@/systemctl stop %{?*} > /dev/null 2>&1 || : \ +fi \ +%{nil} + +%systemd_postun() \ +@rootbindir@/systemctl daemon-reload >/dev/null 2>&1 || : \ +%{nil} + +%systemd_postun_with_restart() \ +@rootbindir@/systemctl daemon-reload >/dev/null 2>&1 || : \ +if [ $1 -ge 1 ] ; then \ + # Package upgrade, not uninstall \ + @rootbindir@/systemctl try-restart %{?*} >/dev/null 2>&1 || : \ +fi \ +%{nil} -- cgit v1.2.3-54-g00ecf From a1d41e17a5c3861becd66f1c9dba7eb39ae4c478 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 13 Sep 2012 22:17:46 +0200 Subject: rpm: expose preset dir as rpm macro and in systemd.pc --- Makefile.am | 4 ++++ src/core/macros.systemd.in | 1 + src/core/systemd.pc.in | 2 ++ 3 files changed, 7 insertions(+) (limited to 'src/core/macros.systemd.in') diff --git a/Makefile.am b/Makefile.am index be97193b45..5674f1019a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -65,6 +65,7 @@ rpmmacrosdir=$(sysconfdir)/rpm # Our own, non-special dirs pkgsysconfdir=$(sysconfdir)/systemd userunitdir=$(prefix)/lib/systemd/user +userpresetdir=$(prefix)/lib/systemd/user-preset tmpfilesdir=$(prefix)/lib/tmpfiles.d sysctldir=$(prefix)/lib/sysctl.d usergeneratordir=$(prefix)/lib/systemd/user-generators @@ -73,6 +74,7 @@ systemgeneratordir=$(rootlibexecdir)/system-generators systemshutdowndir=$(rootlibexecdir)/system-shutdown systemsleepdir=$(rootlibexecdir)/system-sleep systemunitdir=$(rootprefix)/lib/systemd/system +systempresetdir=$(rootprefix)/lib/systemd/system-preset udevlibexecdir=$(rootprefix)/lib/udev udevhomedir = $(udevlibexecdir) udevrulesdir = $(udevlibexecdir)/rules.d @@ -3450,6 +3452,8 @@ SED_PROCESS = \ -e 's,@pkgdatadir\@,$(pkgdatadir),g' \ -e 's,@systemunitdir\@,$(systemunitdir),g' \ -e 's,@userunitdir\@,$(userunitdir),g' \ + -e 's,@systempresetdir\@,$(systempresetdir),g' \ + -e 's,@userpresetdir\@,$(userpresetdir),g' \ -e 's,@PACKAGE_VERSION\@,$(PACKAGE_VERSION),g' \ -e 's,@PACKAGE_NAME\@,$(PACKAGE_NAME),g' \ -e 's,@PACKAGE_URL\@,$(PACKAGE_URL),g' \ diff --git a/src/core/macros.systemd.in b/src/core/macros.systemd.in index 86e869307c..e521df337d 100644 --- a/src/core/macros.systemd.in +++ b/src/core/macros.systemd.in @@ -20,6 +20,7 @@ # RPM macros for packages installing systemd unit files %_unitdir @systemunitdir@ +%_presetdir @systempresetdir@ %systemd_requires \ Requires(post): systemd \ diff --git a/src/core/systemd.pc.in b/src/core/systemd.pc.in index 49f65b2a65..2f49d5df52 100644 --- a/src/core/systemd.pc.in +++ b/src/core/systemd.pc.in @@ -9,7 +9,9 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ systemdutildir=@rootlibexecdir@ systemdsystemunitdir=@systemunitdir@ +systemdsystempresetdir=@systempresetdir@ systemduserunitdir=@userunitdir@ +systemduserpresetdir=@userpresetdir@ systemdsystemconfdir=@pkgsysconfdir@/system systemduserconfdir=@pkgsysconfdir@/user systemdsystemunitpath=${systemdsystemconfdir}:/etc/systemd/system:/run/systemd/system:/usr/local/lib/systemd/system:${systemdsystemunitdir}:/usr/lib/systemd/system:/lib/systemd/system -- cgit v1.2.3-54-g00ecf