>From 7de5bac5a0e87888455e756f5ff4023c02a7085d Mon Sep 17 00:00:00 2001
From: Jiri Moskovcak <jmoskovc@redhat.com>
Date: Fri, 6 Aug 2010 18:52:20 +0200
Subject: [PATCH] added native systemd init file rhbz#617316

---
 Makefile.am              |    3 ++
 abrt.spec                |   54 ++++++++++++++++++++++++++++++++++++++++------
 configure.ac             |    7 ++++++
 src/Daemon/Makefile.am   |    5 ++++
 src/Daemon/abrtd.service |   11 +++++++++
 5 files changed, 73 insertions(+), 7 deletions(-)
 create mode 100644 src/Daemon/abrtd.service

diff --git a/Makefile.am b/Makefile.am
index fb4ba70..6303e73 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,9 @@
 ACLOCAL_AMFLAGS = -I m4
 SUBDIRS = lib src inc po icons
 
+DISTCHECK_CONFIGURE_FLAGS = \
+        --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)
+
 EXTRA_DIST = doc/coding-style abrt.spec abrt.pc.in doc/abrt-plugin/ doc/howto-write-reporter
 
 pkgconfigdir = $(libdir)/pkgconfig
diff --git a/abrt.spec b/abrt.spec
index 12466c3..8a7edad 100644
--- a/abrt.spec
+++ b/abrt.spec
@@ -1,7 +1,8 @@
 %{!?python_site: %define python_site %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(0)")}
 # platform-dependent
 %{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
-
+# change this value to 1 for Fedora release >= 14
+%define with_systemd 0
 # please modify the "_buildid" define in a way that identifies
 # that the built package isn't the stock distribution package,
 # for example, by setting the define to ".local" or ".bz123456"
@@ -41,6 +42,9 @@ BuildRequires: polkit-devel
 BuildRequires: libtar-devel, bzip2-devel, zlib-devel
 BuildRequires: intltool
 BuildRequires: bison
+%if %{?with_systemd}
+Requires: systemd-units
+%endif
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 Requires: %{name}-libs = %{version}-%{release}
 Requires(pre): shadow-utils
@@ -270,7 +274,38 @@ getent passwd abrt >/dev/null || useradd --system -g abrt -d /etc/abrt -s /sbin/
 exit 0
 
 %post
+if [ $1 -eq 1 ]; then
 /sbin/chkconfig --add %{name}d
+fi
+#systemd
+%if %{?with_systemd}
+#if [ $1 -eq 1 ]; then
+# Enable (but don't start) the units by default
+  /bin/systemctl enable %{name}d.service >/dev/null 2>&1 || :
+#fi
+%endif
+
+%preun
+if [ "$1" -eq "0" ] ; then
+  service %{name}d stop >/dev/null 2>&1
+  /sbin/chkconfig --del %{name}d
+fi
+#systemd
+%if %{?with_systemd}
+if [ "$1" -eq "0" ] ; then
+  /bin/systemctl stop %{name}d.service >/dev/null 2>&1 || :
+  /bin/systemctl disable %{name}d.service >/dev/null 2>&1 || :
+fi
+%endif
+
+%postun
+#systemd
+%if %{?with_systemd}
+if [ $1 -ge 1 ] ; then
+# On upgrade, reload init system configuration if we changed unit files
+  /bin/systemctl daemon-reload >/dev/null 2>&1 || :
+fi
+%endif
 
 %post gui
 # update icon cache
@@ -281,12 +316,6 @@ fi
 
 %post libs -p /sbin/ldconfig
 
-%preun
-if [ "$1" -eq "0" ] ; then
-  service %{name}d stop >/dev/null 2>&1
-  /sbin/chkconfig --del %{name}d
-fi
-
 %postun libs -p /sbin/ldconfig
 
 %postun gui
@@ -299,10 +328,21 @@ fi
 if [ "$1" -eq "0" ]; then
     service %{name}d condrestart >/dev/null 2>&1 || :
 fi
+#systemd
+%if %{?with_systemd}
+if [ "$1" -eq "0" ]; then
+    /bin/systemctl try-restart %{name}d.service >/dev/null 2>&1 || :
+fi
+%endif
+
 
 %files -f %{name}.lang
 %defattr(-,root,root,-)
 %doc README COPYING
+#systemd
+%if %{?with_systemd}
+/lib/systemd/system/%{name}d.service
+%endif
 %{_sbindir}/%{name}d
 %{_bindir}/%{name}-debuginfo-install
 %{_bindir}/%{name}-handle-upload
diff --git a/configure.ac b/configure.ac
index 5a3addb..e48ee0d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -56,6 +56,13 @@ PKG_CHECK_MODULES([XMLRPC], [xmlrpc])
 PKG_CHECK_MODULES([XMLRPC_CLIENT], [xmlrpc_client])
 PKG_CHECK_MODULES([POLKIT],[polkit-gobject-1])
 
+PKG_PROG_PKG_CONFIG
+AC_ARG_WITH([systemdsystemunitdir],
+        AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]),
+        [], [with_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)])
+AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
+AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$with_systemdsystemunitdir"])
+
 AC_CHECK_HEADER([libtar.h], [],
    [AC_MSG_ERROR([libtar.h is needed to build abrt])])
 
diff --git a/src/Daemon/Makefile.am b/src/Daemon/Makefile.am
index 34243b1..ef67726 100644
--- a/src/Daemon/Makefile.am
+++ b/src/Daemon/Makefile.am
@@ -54,6 +54,11 @@ man_MANS = abrtd.8 abrt.conf.5
 
 EXTRA_DIST = $(man_MANS) abrt-debuginfo-install abrt-handle-upload
 
+if HAVE_SYSTEMD
+dist_systemdsystemunit_DATA = \
+        abrtd.service
+endif
+
 DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
 
 install-data-local:
diff --git a/src/Daemon/abrtd.service b/src/Daemon/abrtd.service
new file mode 100644
index 0000000..e170e32
--- /dev/null
+++ b/src/Daemon/abrtd.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=ABRT Automated Bug Reporting Tool
+After=syslog.target
+
+[Service]
+Type=dbus
+BusName=com.redhat.abrt
+ExecStart=/usr/sbin/abrtd -d -s
+
+[Install]
+WantedBy=multi-user.target
-- 
1.7.2.1

