[lcgdm/el5: 2/2] Convert to systemd (Fedora 17+)

Mattias Ellert ellert at fedoraproject.org
Fri Mar 2 19:00:32 UTC 2012


commit feb7b8f49289c31e5a5ebe6295057167886b6fb4
Author: Mattias Ellert <mattias.ellert at fysast.uu.se>
Date:   Fri Mar 2 19:58:58 2012 +0100

    Convert to systemd (Fedora 17+)
    
    - Rebuild for new gsoap (Fedora 17+)
    - Update obsolete sql scripts

 lcgdm-dbengine.patch |  304 ++++++++++++++
 lcgdm.spec           | 1108 +++++++++++++++++++++++++++++++++++++++++---------
 sources              |    1 +
 3 files changed, 1226 insertions(+), 187 deletions(-)
---
diff --git a/lcgdm-dbengine.patch b/lcgdm-dbengine.patch
new file mode 100644
index 0000000..9adfe00
--- /dev/null
+++ b/lcgdm-dbengine.patch
@@ -0,0 +1,304 @@
+diff -ur lcgdm-1.8.2.orig/dicomcopy/dicomcopy_mysql_tbl.sql lcgdm-1.8.2/dicomcopy/dicomcopy_mysql_tbl.sql
+--- lcgdm-1.8.2.orig/dicomcopy/dicomcopy_mysql_tbl.sql	2011-12-06 14:35:17.000000000 +0100
++++ lcgdm-1.8.2/dicomcopy/dicomcopy_mysql_tbl.sql	2012-03-02 07:23:40.212240388 +0100
+@@ -24,7 +24,7 @@
+        nbreqfiles INTEGER,
+        ctime INTEGER,
+        status INTEGER)
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE dpm_dicom_filereq (
+        rowid BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+@@ -33,7 +33,7 @@
+        surl BLOB,
+        dicom_fn VARCHAR(255),
+        status INTEGER)
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ ALTER TABLE dpm_dicom_req
+        ADD UNIQUE (r_token);
+diff -ur lcgdm-1.8.2.orig/dpm/dpm_mysql_tbl.sql lcgdm-1.8.2/dpm/dpm_mysql_tbl.sql
+--- lcgdm-1.8.2.orig/dpm/dpm_mysql_tbl.sql	2011-12-06 14:35:16.000000000 +0100
++++ lcgdm-1.8.2/dpm/dpm_mysql_tbl.sql	2012-03-02 07:23:40.208240388 +0100
+@@ -25,7 +25,7 @@
+        groups VARCHAR(255) BINARY,
+        ret_policy CHAR(1),
+        s_type CHAR(1))
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE dpm_fs (
+        rowid BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+@@ -34,7 +34,7 @@
+        fs VARCHAR(79) BINARY,
+        status INTEGER,
+        weight INTEGER)
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE dpm_pending_req (
+        rowid BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+@@ -55,7 +55,7 @@
+        status INTEGER,
+        errstring VARCHAR(255) BINARY,
+        groups VARCHAR(255))
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE dpm_req (
+        rowid BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+@@ -76,7 +76,7 @@
+        status INTEGER,
+        errstring VARCHAR(255) BINARY,
+        groups VARCHAR(255))
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE dpm_get_filereq (
+        rowid BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+@@ -95,7 +95,7 @@
+        actual_size BIGINT UNSIGNED,
+        status INTEGER,
+        errstring VARCHAR(255) BINARY)
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE dpm_put_filereq (
+        rowid BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+@@ -115,7 +115,7 @@
+        actual_size BIGINT UNSIGNED,
+        status INTEGER,
+        errstring VARCHAR(255) BINARY)
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE dpm_copy_filereq (
+        rowid BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+@@ -132,7 +132,7 @@
+        actual_size BIGINT UNSIGNED,
+        status INTEGER,
+        errstring VARCHAR(255) BINARY)
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE dpm_space_reserv (
+        rowid BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+@@ -151,11 +151,11 @@
+        assign_time INTEGER,
+        expire_time INTEGER,
+        groups VARCHAR(255) BINARY)
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE dpm_unique_id (
+        id BIGINT UNSIGNED)
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ ALTER TABLE dpm_pool
+        ADD UNIQUE (poolname);
+@@ -193,7 +193,7 @@
+   major INTEGER NOT NULL,
+   minor INTEGER NOT NULL,
+   patch INTEGER NOT NULL
+-) TYPE=INNODB;
++) ENGINE = InnoDB;
+ 
+ INSERT INTO schema_version_dpm (major, minor, patch)
+   VALUES (3, 3, 0);
+diff -ur lcgdm-1.8.2.orig/ns/Cns_mysql_tbl.sql lcgdm-1.8.2/ns/Cns_mysql_tbl.sql
+--- lcgdm-1.8.2.orig/ns/Cns_mysql_tbl.sql	2011-12-06 14:35:17.000000000 +0100
++++ lcgdm-1.8.2/ns/Cns_mysql_tbl.sql	2012-03-02 07:23:40.217240388 +0100
+@@ -24,7 +24,7 @@
+        nbcopies INTEGER,
+        nbdirs_using_class INTEGER,
+        retenp_on_disk INTEGER)
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE Cns_file_metadata (
+        rowid BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+@@ -45,19 +45,19 @@
+        csumtype VARCHAR(2) BINARY,
+        csumvalue VARCHAR(32) BINARY,
+        acl BLOB)
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE Cns_user_metadata (
+        rowid BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+        u_fileid BIGINT UNSIGNED,
+        comments VARCHAR(255) BINARY)
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE Cns_symlinks (
+        rowid BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+        fileid BIGINT UNSIGNED,
+        linkname BLOB)
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE Cns_file_replica (
+        rowid BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+@@ -75,14 +75,14 @@
+        host VARCHAR(63) BINARY,
+        fs VARCHAR(79) BINARY,
+        sfn BLOB)
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE Cns_groupinfo (
+        rowid INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+        gid INTEGER,
+        groupname VARCHAR(255) BINARY,
+        banned INTEGER)
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE Cns_userinfo (
+        rowid INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+@@ -90,19 +90,19 @@
+        username VARCHAR(255) BINARY,
+        user_ca VARCHAR(255) BINARY,
+        banned INTEGER)
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE Cns_unique_id (
+        id BIGINT UNSIGNED)
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE Cns_unique_gid (
+        id INTEGER UNSIGNED)
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE Cns_unique_uid (
+        id INTEGER UNSIGNED)
+-	TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ ALTER TABLE Cns_class_metadata
+        ADD UNIQUE (classid),
+@@ -141,7 +141,7 @@
+   major INTEGER NOT NULL,
+   minor INTEGER NOT NULL,
+   patch INTEGER NOT NULL
+-) TYPE=INNODB;
++) ENGINE = InnoDB;
+ 
+ INSERT INTO schema_version (major, minor, patch) 
+   VALUES (3, 1, 0);
+diff -ur lcgdm-1.8.2.orig/scripts/DPM-migration/migrate-mysql-schema-to-2-1-0.sql lcgdm-1.8.2/scripts/DPM-migration/migrate-mysql-schema-to-2-1-0.sql
+--- lcgdm-1.8.2.orig/scripts/DPM-migration/migrate-mysql-schema-to-2-1-0.sql	2011-12-06 14:35:16.000000000 +0100
++++ lcgdm-1.8.2/scripts/DPM-migration/migrate-mysql-schema-to-2-1-0.sql	2012-03-02 07:23:40.217240388 +0100
+@@ -20,7 +20,7 @@
+   major INTEGER NOT NULL,
+   minor INTEGER NOT NULL,
+   patch INTEGER NOT NULL
+-) TYPE=INNODB;
++) ENGINE = InnoDB;
+ 
+ INSERT INTO schema_version (major, minor, patch)
+   VALUES (2, 1, 0);
+diff -ur lcgdm-1.8.2.orig/scripts/DPM-migration/virtualIds/migrate-mysql-schema-to-2-2-0.sql lcgdm-1.8.2/scripts/DPM-migration/virtualIds/migrate-mysql-schema-to-2-2-0.sql
+--- lcgdm-1.8.2.orig/scripts/DPM-migration/virtualIds/migrate-mysql-schema-to-2-2-0.sql	2011-12-06 14:35:16.000000000 +0100
++++ lcgdm-1.8.2/scripts/DPM-migration/virtualIds/migrate-mysql-schema-to-2-2-0.sql	2012-03-02 07:25:23.671243254 +0100
+@@ -17,21 +17,21 @@
+        rowid INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+        gid INTEGER,
+        groupname VARCHAR(255) BINARY)
+-      TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE Cns_userinfo (
+        rowid INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+        userid INTEGER,
+        username VARCHAR(255) BINARY)
+-      TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE Cns_unique_gid (
+        id INTEGER UNSIGNED)
+-      TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE Cns_unique_uid (
+        id INTEGER UNSIGNED)
+-       TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ ALTER TABLE Cns_groupinfo
+        ADD UNIQUE (groupname);
+@@ -46,7 +46,7 @@
+   major INTEGER NOT NULL,
+   minor INTEGER NOT NULL,
+   patch INTEGER NOT NULL
+-) TYPE=INNODB;
++) ENGINE = InnoDB;
+ 
+ INSERT INTO schema_version (major, minor, patch)
+   VALUES (2, 2, 0);
+@@ -58,7 +58,7 @@
+   major INTEGER NOT NULL,
+   minor INTEGER NOT NULL,
+   patch INTEGER NOT NULL
+-) TYPE=INNODB;
++) ENGINE = InnoDB;
+ 
+ INSERT INTO schema_version (major, minor, patch)
+   VALUES (2, 2, 0);
+diff -ur lcgdm-1.8.2.orig/scripts/LFC-migration-1.4.0/migrate-mysql-schema-to-2-0-0.sql lcgdm-1.8.2/scripts/LFC-migration-1.4.0/migrate-mysql-schema-to-2-0-0.sql
+--- lcgdm-1.8.2.orig/scripts/LFC-migration-1.4.0/migrate-mysql-schema-to-2-0-0.sql	2011-12-06 14:35:16.000000000 +0100
++++ lcgdm-1.8.2/scripts/LFC-migration-1.4.0/migrate-mysql-schema-to-2-0-0.sql	2012-03-02 07:31:32.114253550 +0100
+@@ -13,21 +13,21 @@
+        rowid INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+        gid INTEGER,
+        groupname VARCHAR(255) BINARY)
+-      TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE Cns_userinfo (
+        rowid INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+        userid INTEGER,
+        username VARCHAR(255) BINARY)
+-      TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE Cns_unique_gid (
+        id INTEGER UNSIGNED)
+-      TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ CREATE TABLE Cns_unique_uid (
+        id INTEGER UNSIGNED)
+-       TYPE = InnoDB;
++       ENGINE = InnoDB;
+ 
+ ALTER TABLE Cns_groupinfo
+        ADD UNIQUE (groupname);
+@@ -42,7 +42,7 @@
+   major INTEGER NOT NULL,
+   minor INTEGER NOT NULL,
+   patch INTEGER NOT NULL
+-) TYPE=INNODB;
++) ENGINE = InnoDB;
+ 
+ INSERT INTO schema_version (major, minor, patch)
+   VALUES (2, 1, 0);
+diff -ur lcgdm-1.8.2.orig/scripts/migrate-mysql-schema-to-1-1-1.sql lcgdm-1.8.2/scripts/migrate-mysql-schema-to-1-1-1.sql
+--- lcgdm-1.8.2.orig/scripts/migrate-mysql-schema-to-1-1-1.sql	2011-12-06 14:35:16.000000000 +0100
++++ lcgdm-1.8.2/scripts/migrate-mysql-schema-to-1-1-1.sql	2012-03-02 07:23:40.221240388 +0100
+@@ -28,7 +28,7 @@
+   major INTEGER NOT NULL,
+   minor INTEGER NOT NULL,
+   patch INTEGER NOT NULL
+-) TYPE=INNODB;
++) ENGINE = InnoDB;
+ 
+ INSERT INTO schema_version (major, minor, patch)
+   VALUES (1, 1, 1);
diff --git a/lcgdm.spec b/lcgdm.spec
index a9a17c8..a908d84 100644
--- a/lcgdm.spec
+++ b/lcgdm.spec
@@ -27,9 +27,15 @@
 %filter_setup
 %endif
 
+%if %{?fedora}%{!?fedora:0} >= 17 || %{?rhel}%{!?rhel:0} >= 7
+%global systemd 1
+%else
+%global systemd 0
+%endif
+
 Name:		lcgdm
 Version:	1.8.2
-Release:	2%{?dist}
+Release:	3%{?dist}
 Summary:	LHC Computing Grid Data Management
 
 Group:		Applications/Internet
@@ -44,6 +50,8 @@ Source3:	README.Fedora.dpm-mysql
 Source4:	README.Fedora.dpns-mysql
 Source5:	README.Fedora.dpm-postgres
 Source6:	README.Fedora.dpns-postgres
+#		Systemd unit files
+Source7:	%{name}-unitfiles.tar.gz
 #		Link binaries using shared libraries
 #		https://savannah.cern.ch/bugs/?57529
 Patch0:		%{name}-shliblink.patch
@@ -69,6 +77,8 @@ Patch7:		%{name}-paths.patch
 Patch8:		%{name}-dlopen.patch
 #		Use Fedora's imake instead of bundled version
 Patch9:		%{name}-imake.patch
+#		Update sql scripts
+Patch10:	%{name}-dbengine.patch
 BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
 %if %{?fedora}%{!?fedora:0} >= 5 || %{?rhel}%{!?rhel:0} >= 5
@@ -103,6 +113,9 @@ BuildRequires:	python-devel%{?_isa}
 %if %{?altpython:1}%{!?altpython:0}
 BuildRequires:	%{altpython}-devel%{?_isa}
 %endif
+%if %systemd
+BuildRequires:	systemd-units
+%endif
 
 %description
 The lcgdm package provides the LCG Data Management components: the LFC
@@ -206,10 +219,16 @@ Obsoletes:	lfc-mysql < 1.8.1.2-2
 
 Requires(pre):		shadow-utils
 Requires(post):		mysql
+%if %systemd
+Requires(post):		systemd-units
+Requires(preun):	systemd-units
+Requires(postun):	systemd-units
+%else
 Requires(post):		chkconfig
 Requires(preun):	chkconfig
 Requires(preun):	initscripts
 Requires(postun):	initscripts
+%endif
 
 %description -n lfc-server-mysql
 The LCG File Catalog (LFC) keeps track of the locations of the physical
@@ -226,10 +245,16 @@ Obsoletes:	lfc-postgres < 1.8.1.2-2
 
 Requires(pre):		shadow-utils
 Requires(post):		postgresql
+%if %systemd
+Requires(post):		systemd-units
+Requires(preun):	systemd-units
+Requires(postun):	systemd-units
+%else
 Requires(post):		chkconfig
 Requires(preun):	chkconfig
 Requires(preun):	initscripts
 Requires(postun):	initscripts
+%endif
 
 %description -n lfc-server-postgres
 The LCG File Catalog (LFC) keeps track of the locations of the physical
@@ -243,10 +268,16 @@ Group:		Applications/Internet
 Requires:	lfc-libs%{?_isa} = %{version}-%{release}
 
 Requires(pre):		shadow-utils
+%if %systemd
+Requires(post):		systemd-units
+Requires(preun):	systemd-units
+Requires(postun):	systemd-units
+%else
 Requires(post):		chkconfig
 Requires(preun):	chkconfig
 Requires(preun):	initscripts
 Requires(postun):	initscripts
+%endif
 
 %description -n lfc-dli
 The LCG File Catalog (LFC) keeps track of the locations of the physical
@@ -337,10 +368,16 @@ Provides:	dpm-mysql = %{version}-%{release}
 Obsoletes:	dpm-mysql < 1.8.1.2-2
 
 Requires(pre):		shadow-utils
+%if %systemd
+Requires(post):		systemd-units
+Requires(preun):	systemd-units
+Requires(postun):	systemd-units
+%else
 Requires(post):		chkconfig
 Requires(preun):	chkconfig
 Requires(preun):	initscripts
 Requires(postun):	initscripts
+%endif
 
 %description -n dpm-server-mysql
 The LCG Disk Pool Manager (DPM) creates a storage element from a set
@@ -357,10 +394,16 @@ Provides:	dpm-postgres = %{version}-%{release}
 Obsoletes:	dpm-postgres < 1.8.1.2-2
 
 Requires(pre):		shadow-utils
+%if %systemd
+Requires(post):		systemd-units
+Requires(preun):	systemd-units
+Requires(postun):	systemd-units
+%else
 Requires(post):		chkconfig
 Requires(preun):	chkconfig
 Requires(preun):	initscripts
 Requires(postun):	initscripts
+%endif
 
 %description -n dpm-server-postgres
 The LCG Disk Pool Manager (DPM) creates a storage element from a set
@@ -378,10 +421,16 @@ Obsoletes:	dpm-mysql-nameserver < 1.8.1.2-2
 
 Requires(pre):		shadow-utils
 Requires(post):		mysql
+%if %systemd
+Requires(post):		systemd-units
+Requires(preun):	systemd-units
+Requires(postun):	systemd-units
+%else
 Requires(post):		chkconfig
 Requires(preun):	chkconfig
 Requires(preun):	initscripts
 Requires(postun):	initscripts
+%endif
 
 %description -n dpm-name-server-mysql
 The LCG Disk Pool Manager (DPM) creates a storage element from a set
@@ -399,10 +448,16 @@ Obsoletes:	dpm-postgres-nameserver < 1.8.1.2-2
 
 Requires(pre):		shadow-utils
 Requires(post):		postgresql
+%if %systemd
+Requires(post):		systemd-units
+Requires(preun):	systemd-units
+Requires(postun):	systemd-units
+%else
 Requires(post):		chkconfig
 Requires(preun):	chkconfig
 Requires(preun):	initscripts
 Requires(postun):	initscripts
+%endif
 
 %description -n dpm-name-server-postgres
 The LCG Disk Pool Manager (DPM) creates a storage element from a set
@@ -419,10 +474,16 @@ Provides:	dpm-mysql-copyd = %{version}-%{release}
 Obsoletes:	dpm-mysql-copyd < 1.8.1.2-2
 
 Requires(pre):		shadow-utils
+%if %systemd
+Requires(post):		systemd-units
+Requires(preun):	systemd-units
+Requires(postun):	systemd-units
+%else
 Requires(post):		chkconfig
 Requires(preun):	chkconfig
 Requires(preun):	initscripts
 Requires(postun):	initscripts
+%endif
 
 %description -n dpm-copy-server-mysql
 The LCG Disk Pool Manager (DPM) creates a storage element from a set
@@ -439,10 +500,16 @@ Provides:	dpm-postgres-copyd = %{version}-%{release}
 Obsoletes:	dpm-postgres-copyd < 1.8.1.2-2
 
 Requires(pre):		shadow-utils
+%if %systemd
+Requires(post):		systemd-units
+Requires(preun):	systemd-units
+Requires(postun):	systemd-units
+%else
 Requires(post):		chkconfig
 Requires(preun):	chkconfig
 Requires(preun):	initscripts
 Requires(postun):	initscripts
+%endif
 
 %description -n dpm-copy-server-postgres
 The LCG Disk Pool Manager (DPM) creates a storage element from a set
@@ -463,10 +530,16 @@ Provides:	dpm-mysql-srmv22 = %{version}-%{release}
 Obsoletes:	dpm-mysql-srmv22 < 1.8.1.2-2
 
 Requires(pre):		shadow-utils
+%if %systemd
+Requires(post):		systemd-units
+Requires(preun):	systemd-units
+Requires(postun):	systemd-units
+%else
 Requires(post):		chkconfig
 Requires(preun):	chkconfig
 Requires(preun):	initscripts
 Requires(postun):	initscripts
+%endif
 
 %description -n dpm-srm-server-mysql
 The LCG Disk Pool Manager (DPM) creates a storage element from a set
@@ -487,10 +560,16 @@ Provides:	dpm-postgres-srmv22 = %{version}-%{release}
 Obsoletes:	dpm-postgres-srmv22 < 1.8.1.2-2
 
 Requires(pre):		shadow-utils
+%if %systemd
+Requires(post):		systemd-units
+Requires(preun):	systemd-units
+Requires(postun):	systemd-units
+%else
 Requires(post):		chkconfig
 Requires(preun):	chkconfig
 Requires(preun):	initscripts
 Requires(postun):	initscripts
+%endif
 
 %description -n dpm-srm-server-postgres
 The LCG Disk Pool Manager (DPM) creates a storage element from a set
@@ -506,10 +585,16 @@ Requires:	dpm-libs%{?_isa} = %{version}-%{release}
 Provides:	dpm-rfiod = %{version}-%{release}
 Obsoletes:	dpm-rfiod < 1.8.1.2-2
 
+%if %systemd
+Requires(post):		systemd-units
+Requires(preun):	systemd-units
+Requires(postun):	systemd-units
+%else
 Requires(post):		chkconfig
 Requires(preun):	chkconfig
 Requires(preun):	initscripts
 Requires(postun):	initscripts
+%endif
 
 %description -n dpm-rfio-server
 The LCG Disk Pool Manager (DPM) creates a storage element from a set
@@ -523,6 +608,7 @@ This package provides a Remote File IO (RFIO) server for DPM.
 %setup -q -c -n %{name}-%{version}/lfc-postgres
 %setup -q -c -n %{name}-%{version}/dpm-mysql
 %setup -q -c -n %{name}-%{version}/dpm-postgres
+%setup -D -T -q -a 7
 %setup -D -T -q
 
 for d in lfc-mysql lfc-postgres dpm-mysql dpm-postgres ; do
@@ -539,6 +625,7 @@ pushd $d/%{name}-%{version}
 %patch7 -p1
 %patch8 -p1
 %patch9 -p1
+%patch10 -p1
 
 chmod 644 security/globus_gsi_gss_constants.h \
 	  security/globus_i_gsi_credential.h \
@@ -728,8 +815,12 @@ popd
 %install
 rm -rf ${RPM_BUILD_ROOT}
 
+%if %systemd
+mkdir -p ${RPM_BUILD_ROOT}%{_unitdir}
+%else
 mkdir -p ${RPM_BUILD_ROOT}%{_initrddir}
 mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig
+%endif
 mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/logrotate.d
 mkdir -p ${RPM_BUILD_ROOT}%{_sbindir}
 mkdir -p ${RPM_BUILD_ROOT}%{_mandir}/man8
@@ -747,8 +838,16 @@ rmdir ${RPM_BUILD_ROOT}%{_datadir}/LFC
 
 mkdir -p ${RPM_BUILD_ROOT}%{_libdir}/lfc-mysql
 mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/lfc-mysql
+mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/lfc-mysql
 
-# lfcdaemon startup script
+# lfcdaemon unit file / startup script
+%if %systemd
+rm ${RPM_BUILD_ROOT}%{_datadir}/lfc/rc.lfcdaemon
+rm ${RPM_BUILD_ROOT}%{_sysconfdir}/lfcdaemon.conf.templ
+install -m 644 -p ../../lcgdm-unitfiles/mysql/lfcdaemon.service \
+    ${RPM_BUILD_ROOT}%{_datadir}/lfc-mysql
+touch ${RPM_BUILD_ROOT}%{_unitdir}/lfcdaemon.service
+%else
 sed -e 's/LD_LIBRARY_PATH=$LD_LIBRARY_PATH //' \
     -e '/LD_LIBRARY_PATH/d' \
     -e 's!\$PREFIX/bin!\$PREFIX/sbin!' \
@@ -759,13 +858,12 @@ chmod 755 ${RPM_BUILD_ROOT}%{_sysconfdir}/lfc-mysql/lfcdaemon.init
 rm ${RPM_BUILD_ROOT}%{_datadir}/lfc/rc.lfcdaemon
 touch ${RPM_BUILD_ROOT}%{_initrddir}/lfcdaemon
 chmod 755 ${RPM_BUILD_ROOT}%{_initrddir}/lfcdaemon
-
-# lfcdaemon configuration file
 sed -e 's!/opt/lcg!!' -e 's!export SEMSGCONFIGFILE!#&!' \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/lfcdaemon.conf.templ > \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/lfc-mysql/lfcdaemon.conf
 rm ${RPM_BUILD_ROOT}%{_sysconfdir}/lfcdaemon.conf.templ
 touch ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig/lfcdaemon
+%endif
 
 # lfcdaemon log directory and log rotation configuration
 mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/lfc
@@ -787,7 +885,7 @@ rm ${RPM_BUILD_ROOT}%{_mandir}/man1/lfcdaemon.1
 touch ${RPM_BUILD_ROOT}%{_mandir}/man8/lfcdaemon.8
 
 mv ${RPM_BUILD_ROOT}%{_sysconfdir}/NSCONFIG.templ \
-   ${RPM_BUILD_ROOT}%{_libdir}/lfc-mysql/NSCONFIG.templ
+   ${RPM_BUILD_ROOT}%{_datadir}/lfc-mysql/NSCONFIG.templ
 touch ${RPM_BUILD_ROOT}%{_datadir}/lfc/NSCONFIG.templ
 
 # lfc-shutdown binary and man page
@@ -801,7 +899,13 @@ sed -e 's/\(\.TH [^ ]* \)1/\18/' \
 rm ${RPM_BUILD_ROOT}%{_mandir}/man1/lfc-shutdown.1
 touch ${RPM_BUILD_ROOT}%{_mandir}/man8/lfc-shutdown.8
 
-# lfc-dli startup script
+# lfc-dli unit file / startup script
+%if %systemd
+rm ${RPM_BUILD_ROOT}%{_datadir}/lfc/rc.lfc-dli
+rm ${RPM_BUILD_ROOT}%{_sysconfdir}/lfc-dli.conf.templ
+install -m 644 -p ../../lcgdm-unitfiles/lfc-dli.service \
+    ${RPM_BUILD_ROOT}%{_unitdir}
+%else
 sed -e 's/LD_LIBRARY_PATH=$LD_LIBRARY_PATH //' \
     -e '/LD_LIBRARY_PATH/d' \
     -e 's!\$PREFIX/bin!\$PREFIX/sbin!' \
@@ -811,13 +915,12 @@ sed -e 's/LD_LIBRARY_PATH=$LD_LIBRARY_PATH //' \
     ${RPM_BUILD_ROOT}%{_initrddir}/lfc-dli
 chmod 755 ${RPM_BUILD_ROOT}%{_initrddir}/lfc-dli
 rm ${RPM_BUILD_ROOT}%{_datadir}/lfc/rc.lfc-dli
-
-# lfc-dli configuration file
 sed -e 's!/var/log/dli!/var/log/lfc-dli!g' \
     -e 's/\(LFC_HOST=\).*/\1`hostname -f`/' \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/lfc-dli.conf.templ > \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig/lfc-dli
 rm ${RPM_BUILD_ROOT}%{_sysconfdir}/lfc-dli.conf.templ
+%endif
 
 # lfc-dli log directory and log rotation configuration
 mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/lfc-dli
@@ -848,12 +951,14 @@ rm ${RPM_BUILD_ROOT}%{_mandir}/man3/log.3*
 rm ${RPM_BUILD_ROOT}%{_libdir}/liblfc.a
 rm ${RPM_BUILD_ROOT}%{_libdir}/liblcgdm.a
 
+%if %systemd == 0
 # Turn off services by default
 sed -e 's/\(chkconfig: \)\w*/\1-/' \
     -e '/Default-Start/d' \
     -e 's/\(Default-Stop: *\).*/\10 1 2 3 4 5 6/' \
     -i ${RPM_BUILD_ROOT}%{_sysconfdir}/lfc-mysql/lfcdaemon.init \
        ${RPM_BUILD_ROOT}%{_initrddir}/lfc-dli
+%endif
 
 popd
 
@@ -870,8 +975,16 @@ rmdir ${RPM_BUILD_ROOT}%{_datadir}/LFC
 
 mkdir -p ${RPM_BUILD_ROOT}%{_libdir}/lfc-postgres
 mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/lfc-postgres
+mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/lfc-postgres
 
-# lfcdaemon startup script
+# lfcdaemon unit file / startup script
+%if %systemd
+rm ${RPM_BUILD_ROOT}%{_datadir}/lfc/rc.lfcdaemon
+rm ${RPM_BUILD_ROOT}%{_sysconfdir}/lfcdaemon.conf.templ
+install -m 644 -p ../../lcgdm-unitfiles/postgres/lfcdaemon.service \
+    ${RPM_BUILD_ROOT}%{_datadir}/lfc-postgres
+touch ${RPM_BUILD_ROOT}%{_unitdir}/lfcdaemon.service
+%else
 sed -e 's/LD_LIBRARY_PATH=$LD_LIBRARY_PATH //' \
     -e '/LD_LIBRARY_PATH/d' \
     -e 's!\$PREFIX/bin!\$PREFIX/sbin!' \
@@ -882,13 +995,12 @@ chmod 755 ${RPM_BUILD_ROOT}%{_sysconfdir}/lfc-postgres/lfcdaemon.init
 rm ${RPM_BUILD_ROOT}%{_datadir}/lfc/rc.lfcdaemon
 touch ${RPM_BUILD_ROOT}%{_initrddir}/lfcdaemon
 chmod 755 ${RPM_BUILD_ROOT}%{_initrddir}/lfcdaemon
-
-# lfcdaemon configuration file
 sed -e 's!/opt/lcg!!' -e 's!export SEMSGCONFIGFILE!#&!' \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/lfcdaemon.conf.templ > \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/lfc-postgres/lfcdaemon.conf
 rm ${RPM_BUILD_ROOT}%{_sysconfdir}/lfcdaemon.conf.templ
 touch ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig/lfcdaemon
+%endif
 
 # lfcdaemon log directory and log rotation configuration
 mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/lfc
@@ -910,7 +1022,7 @@ rm ${RPM_BUILD_ROOT}%{_mandir}/man1/lfcdaemon.1
 touch ${RPM_BUILD_ROOT}%{_mandir}/man8/lfcdaemon.8
 
 mv ${RPM_BUILD_ROOT}%{_sysconfdir}/NSCONFIG.templ \
-   ${RPM_BUILD_ROOT}%{_libdir}/lfc-postgres/NSCONFIG.templ
+   ${RPM_BUILD_ROOT}%{_datadir}/lfc-postgres/NSCONFIG.templ
 touch ${RPM_BUILD_ROOT}%{_datadir}/lfc/NSCONFIG.templ
 
 # lfc-shutdown binary and man page
@@ -932,11 +1044,13 @@ mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/grid-security/lfcmgr
 sed '/CREATE DATABASE/d' -i \
     ${RPM_BUILD_ROOT}%{_datadir}/lfc/create_lfc_tables_postgres.sql
 
+%if %systemd == 0
 # Turn off services by default
 sed -e 's/\(chkconfig: \)\w*/\1-/' \
     -e '/Default-Start/d' \
     -e 's/\(Default-Stop: *\).*/\10 1 2 3 4 5 6/' \
     -i ${RPM_BUILD_ROOT}%{_sysconfdir}/lfc-postgres/lfcdaemon.init
+%endif
 
 popd
 
@@ -956,8 +1070,16 @@ rmdir ${RPM_BUILD_ROOT}%{_datadir}/DPM
 
 mkdir -p ${RPM_BUILD_ROOT}%{_libdir}/dpm-mysql
 mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm-mysql
+mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/dpm-mysql
 
-# dpm startup script
+# dpm unit file / startup script
+%if %systemd
+rm ${RPM_BUILD_ROOT}%{_datadir}/dpm/rc.dpm
+rm ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm.conf.templ
+install -m 644 -p ../../lcgdm-unitfiles/mysql/dpm.service \
+    ${RPM_BUILD_ROOT}%{_datadir}/dpm-mysql
+touch ${RPM_BUILD_ROOT}%{_unitdir}/dpm.service
+%else
 sed -e 's/LD_LIBRARY_PATH=$LD_LIBRARY_PATH //' \
     -e '/LD_LIBRARY_PATH/d' \
     -e 's!\$PREFIX/bin!\$PREFIX/sbin!' \
@@ -968,13 +1090,12 @@ chmod 755 ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm-mysql/dpm.init
 rm ${RPM_BUILD_ROOT}%{_datadir}/dpm/rc.dpm
 touch ${RPM_BUILD_ROOT}%{_initrddir}/dpm
 chmod 755 ${RPM_BUILD_ROOT}%{_initrddir}/dpm
-
-# dpm configuration file
 sed -e 's/\(^DPNS_HOST=\).*/\1`hostname -f`/' \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm.conf.templ > \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm-mysql/dpm.conf
 rm ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm.conf.templ
 touch ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig/dpm
+%endif
 
 # dpm log directory and log rotation configuration
 mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/dpm
@@ -995,7 +1116,7 @@ rm ${RPM_BUILD_ROOT}%{_mandir}/man1/dpm.1
 touch ${RPM_BUILD_ROOT}%{_mandir}/man8/dpm.8
 
 mv ${RPM_BUILD_ROOT}%{_sysconfdir}/DPMCONFIG.templ \
-   ${RPM_BUILD_ROOT}%{_libdir}/dpm-mysql/DPMCONFIG.templ
+   ${RPM_BUILD_ROOT}%{_datadir}/dpm-mysql/DPMCONFIG.templ
 touch ${RPM_BUILD_ROOT}%{_datadir}/dpm/DPMCONFIG.templ
 
 # dpm-shutdown binary and man page
@@ -1020,7 +1141,14 @@ sed -e 's/\(\.TH [^ ]* \)1/\18/' \
 rm ${RPM_BUILD_ROOT}%{_mandir}/man1/dpm-buildfsv.1
 touch ${RPM_BUILD_ROOT}%{_mandir}/man8/dpm-buildfsv.8
 
-# dpnsdaemon startup script
+# dpnsdaemon unit file / startup script
+%if %systemd
+rm ${RPM_BUILD_ROOT}%{_datadir}/dpm/rc.dpnsdaemon
+rm ${RPM_BUILD_ROOT}%{_sysconfdir}/dpnsdaemon.conf.templ
+install -m 644 -p ../../lcgdm-unitfiles/mysql/dpnsdaemon.service \
+    ${RPM_BUILD_ROOT}%{_datadir}/dpm-mysql
+touch ${RPM_BUILD_ROOT}%{_unitdir}/dpnsdaemon.service
+%else
 sed -e 's/LD_LIBRARY_PATH=$LD_LIBRARY_PATH //' \
     -e '/LD_LIBRARY_PATH/d' \
     -e 's!\$PREFIX/bin!\$PREFIX/sbin!' \
@@ -1032,14 +1160,13 @@ chmod 755 ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm-mysql/dpnsdaemon.init
 rm ${RPM_BUILD_ROOT}%{_datadir}/dpm/rc.dpnsdaemon
 touch ${RPM_BUILD_ROOT}%{_initrddir}/dpnsdaemon
 chmod 755 ${RPM_BUILD_ROOT}%{_initrddir}/dpnsdaemon
-
-# dpnsdaemon configuration file
 sed -e 's!/etc/NSCONFIG!/etc/DPNSCONFIG!g' \
     -e 's!/opt/lcg!!' -e 's!export SEMSGCONFIGFILE!#&!' \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/dpnsdaemon.conf.templ > \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm-mysql/dpnsdaemon.conf
 rm ${RPM_BUILD_ROOT}%{_sysconfdir}/dpnsdaemon.conf.templ
 touch ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig/dpnsdaemon
+%endif
 
 # dpnsdaemon log directory and log rotation configuration
 mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/dpns
@@ -1062,7 +1189,7 @@ rm ${RPM_BUILD_ROOT}%{_mandir}/man1/dpnsdaemon.1
 touch ${RPM_BUILD_ROOT}%{_mandir}/man8/dpnsdaemon.8
 
 mv ${RPM_BUILD_ROOT}%{_sysconfdir}/NSCONFIG.templ \
-   ${RPM_BUILD_ROOT}%{_libdir}/dpm-mysql/DPNSCONFIG.templ
+   ${RPM_BUILD_ROOT}%{_datadir}/dpm-mysql/DPNSCONFIG.templ
 touch ${RPM_BUILD_ROOT}%{_datadir}/dpm/DPNSCONFIG.templ
 
 # dpns-shutdown binary and man page
@@ -1076,7 +1203,14 @@ sed -e 's/\(\.TH [^ ]* \)1/\18/' \
 rm ${RPM_BUILD_ROOT}%{_mandir}/man1/dpns-shutdown.1
 touch ${RPM_BUILD_ROOT}%{_mandir}/man8/dpns-shutdown.8
 
-# dpmcopyd startup script
+# dpmcopyd unit file / startup script
+%if %systemd
+rm ${RPM_BUILD_ROOT}%{_datadir}/dpm/rc.dpmcopyd
+rm ${RPM_BUILD_ROOT}%{_sysconfdir}/dpmcopyd.conf.templ
+install -m 644 -p ../../lcgdm-unitfiles/mysql/dpmcopyd.service \
+    ${RPM_BUILD_ROOT}%{_datadir}/dpm-mysql
+touch ${RPM_BUILD_ROOT}%{_unitdir}/dpmcopyd.service
+%else
 sed -e 's/LD_LIBRARY_PATH=$LD_LIBRARY_PATH //' \
     -e '/LD_LIBRARY_PATH/d' \
     -e 's!\$PREFIX/bin!\$PREFIX/sbin!' \
@@ -1087,14 +1221,13 @@ chmod 755 ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm-mysql/dpmcopyd.init
 rm ${RPM_BUILD_ROOT}%{_datadir}/dpm/rc.dpmcopyd
 touch ${RPM_BUILD_ROOT}%{_initrddir}/dpmcopyd
 chmod 755 ${RPM_BUILD_ROOT}%{_initrddir}/dpmcopyd
-
-# dpmcopyd configuration file
 sed -e 's/\(^DPNS_HOST=\).*/\1`hostname -f`/' \
     -e 's/\(^DPM_HOST=\).*/\1`hostname -f`/' \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/dpmcopyd.conf.templ > \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm-mysql/dpmcopyd.conf
 rm ${RPM_BUILD_ROOT}%{_sysconfdir}/dpmcopyd.conf.templ
 touch ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig/dpmcopyd
+%endif
 
 # dpmcopyd log directory and log rotation configuration
 mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/dpmcopy
@@ -1114,7 +1247,14 @@ rm ${RPM_BUILD_ROOT}%{_mandir}/man1/dpmcopyd.1
 touch ${RPM_BUILD_ROOT}%{_mandir}/man8/dpmcopyd.8
 
 for svc in srmv1 srmv2 srmv2.2 ; do
-    # startup script
+    # unit file / startup script
+%if %systemd
+    rm ${RPM_BUILD_ROOT}%{_datadir}/dpm/rc.${svc}
+    rm ${RPM_BUILD_ROOT}%{_sysconfdir}/${svc}.conf.templ
+    install -m 644 -p ../../lcgdm-unitfiles/mysql/dpm-${svc}.service \
+	${RPM_BUILD_ROOT}%{_datadir}/dpm-mysql
+    touch ${RPM_BUILD_ROOT}%{_unitdir}/dpm-${svc}.service
+%else
     sed -e 's/LD_LIBRARY_PATH=$LD_LIBRARY_PATH //' \
 	-e '/LD_LIBRARY_PATH/d' \
 	-e 's!\$PREFIX/bin!\$PREFIX/sbin!' \
@@ -1126,8 +1266,6 @@ for svc in srmv1 srmv2 srmv2.2 ; do
     rm ${RPM_BUILD_ROOT}%{_datadir}/dpm/rc.${svc}
     touch ${RPM_BUILD_ROOT}%{_initrddir}/dpm-${svc}
     chmod 755 ${RPM_BUILD_ROOT}%{_initrddir}/dpm-${svc}
-
-    # configuration file
     sed -e "s/${svc}/dpm-${svc}/g" \
 	-e 's/\(^DPNS_HOST=\).*/\1`hostname -f`/' \
 	-e 's/\(^DPM_HOST=\).*/\1`hostname -f`/' \
@@ -1136,6 +1274,7 @@ for svc in srmv1 srmv2 srmv2.2 ; do
 	${RPM_BUILD_ROOT}%{_sysconfdir}/dpm-mysql/dpm-${svc}.conf
     rm ${RPM_BUILD_ROOT}%{_sysconfdir}/${svc}.conf.templ
     touch ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig/dpm-${svc}
+%endif
 
     # log directory and log rotation configuration
     mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/dpm-${svc}
@@ -1157,7 +1296,13 @@ for svc in srmv1 srmv2 srmv2.2 ; do
     touch ${RPM_BUILD_ROOT}%{_mandir}/man8/dpm-${svc}.8
 done
 
-# dpm-rfiod startup script
+# dpm-rfiod unit file / startup script
+%if %systemd
+rm ${RPM_BUILD_ROOT}%{_datadir}/dpm/rc.rfiod
+rm ${RPM_BUILD_ROOT}%{_sysconfdir}/rfiod.conf.templ
+install -m 644 -p ../../lcgdm-unitfiles/dpm-rfiod.service \
+    ${RPM_BUILD_ROOT}%{_unitdir}
+%else
 sed -e 's/LD_LIBRARY_PATH=$LD_LIBRARY_PATH //' \
     -e '/LD_LIBRARY_PATH/d' \
     -e 's!\$PREFIX/bin!\$PREFIX/sbin!' \
@@ -1168,8 +1313,6 @@ sed -e 's/LD_LIBRARY_PATH=$LD_LIBRARY_PATH //' \
     ${RPM_BUILD_ROOT}%{_initrddir}/dpm-rfiod
 chmod 755 ${RPM_BUILD_ROOT}%{_initrddir}/dpm-rfiod
 rm ${RPM_BUILD_ROOT}%{_datadir}/dpm/rc.rfiod
-
-# dpm-rfiod configuration file
 sed -e 's/rfiod/dpm-rfiod/g' \
     -e 's!/var/log/rfio!/var/log/dpm-rfio!g' \
     -e 's/\(^DPNS_HOST=\).*/\1`hostname -f`/' \
@@ -1177,6 +1320,7 @@ sed -e 's/rfiod/dpm-rfiod/g' \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/rfiod.conf.templ > \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig/dpm-rfiod
 rm ${RPM_BUILD_ROOT}%{_sysconfdir}/rfiod.conf.templ
+%endif
 
 # dpm-rfiod log directory and log rotation configuration
 mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/dpm-rfio
@@ -1200,12 +1344,14 @@ mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/grid-security/dpmmgr
 # Remove static library
 rm ${RPM_BUILD_ROOT}%{_libdir}/libdpm.a
 
+%if %systemd == 0
 # Turn off services by default
 sed -e 's/\(chkconfig: \)\w*/\1-/' \
     -e '/Default-Start/d' \
     -e 's/\(Default-Stop: *\).*/\10 1 2 3 4 5 6/' \
     -i ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm-mysql/*.init \
        ${RPM_BUILD_ROOT}%{_initrddir}/dpm-rfiod
+%endif
 
 popd
 
@@ -1222,8 +1368,16 @@ rmdir ${RPM_BUILD_ROOT}%{_datadir}/DPM
 
 mkdir -p ${RPM_BUILD_ROOT}%{_libdir}/dpm-postgres
 mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm-postgres
+mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/dpm-postgres
 
-# dpm startup script
+# dpm unit file / startup script
+%if %systemd
+rm ${RPM_BUILD_ROOT}%{_datadir}/dpm/rc.dpm
+rm ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm.conf.templ
+install -m 644 -p ../../lcgdm-unitfiles/postgres/dpm.service \
+    ${RPM_BUILD_ROOT}%{_datadir}/dpm-postgres
+touch ${RPM_BUILD_ROOT}%{_unitdir}/dpm.service
+%else
 sed -e 's/LD_LIBRARY_PATH=$LD_LIBRARY_PATH //' \
     -e '/LD_LIBRARY_PATH/d' \
     -e 's!\$PREFIX/bin!\$PREFIX/sbin!' \
@@ -1234,13 +1388,12 @@ chmod 755 ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm-postgres/dpm.init
 rm ${RPM_BUILD_ROOT}%{_datadir}/dpm/rc.dpm
 touch ${RPM_BUILD_ROOT}%{_initrddir}/dpm
 chmod 755 ${RPM_BUILD_ROOT}%{_initrddir}/dpm
-
-# dpm configuration file
 sed -e 's/\(^DPNS_HOST=\).*/\1`hostname -f`/' \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm.conf.templ > \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm-postgres/dpm.conf
 rm ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm.conf.templ
 touch ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig/dpm
+%endif
 
 # dpm log directory and log rotation configuration
 mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/dpm
@@ -1261,7 +1414,7 @@ rm ${RPM_BUILD_ROOT}%{_mandir}/man1/dpm.1
 touch ${RPM_BUILD_ROOT}%{_mandir}/man8/dpm.8
 
 mv ${RPM_BUILD_ROOT}%{_sysconfdir}/DPMCONFIG.templ \
-   ${RPM_BUILD_ROOT}%{_libdir}/dpm-postgres/DPMCONFIG.templ
+   ${RPM_BUILD_ROOT}%{_datadir}/dpm-postgres/DPMCONFIG.templ
 touch ${RPM_BUILD_ROOT}%{_datadir}/dpm/DPMCONFIG.templ
 
 # dpm-shutdown binary and man page
@@ -1286,7 +1439,14 @@ sed -e 's/\(\.TH [^ ]* \)1/\18/' \
 rm ${RPM_BUILD_ROOT}%{_mandir}/man1/dpm-buildfsv.1
 touch ${RPM_BUILD_ROOT}%{_mandir}/man8/dpm-buildfsv.8
 
-# dpnsdaemon startup script
+# dpnsdaemon unit file / startup script
+%if %systemd
+rm ${RPM_BUILD_ROOT}%{_datadir}/dpm/rc.dpnsdaemon
+rm ${RPM_BUILD_ROOT}%{_sysconfdir}/dpnsdaemon.conf.templ
+install -m 644 -p ../../lcgdm-unitfiles/postgres/dpnsdaemon.service \
+    ${RPM_BUILD_ROOT}%{_datadir}/dpm-postgres
+touch ${RPM_BUILD_ROOT}%{_unitdir}/dpnsdaemon.service
+%else
 sed -e 's/LD_LIBRARY_PATH=$LD_LIBRARY_PATH //' \
     -e '/LD_LIBRARY_PATH/d' \
     -e 's!\$PREFIX/bin!\$PREFIX/sbin!' \
@@ -1298,14 +1458,13 @@ chmod 755 ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm-postgres/dpnsdaemon.init
 rm ${RPM_BUILD_ROOT}%{_datadir}/dpm/rc.dpnsdaemon
 touch ${RPM_BUILD_ROOT}%{_initrddir}/dpnsdaemon
 chmod 755 ${RPM_BUILD_ROOT}%{_initrddir}/dpnsdaemon
-
-# dpnsdaemon configuration file
 sed -e 's!/etc/NSCONFIG!/etc/DPNSCONFIG!g' \
     -e 's!/opt/lcg!!' -e 's!export SEMSGCONFIGFILE!#&!' \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/dpnsdaemon.conf.templ > \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm-postgres/dpnsdaemon.conf
 rm ${RPM_BUILD_ROOT}%{_sysconfdir}/dpnsdaemon.conf.templ
 touch ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig/dpnsdaemon
+%endif
 
 # dpnsdaemon log directory and log rotation configuration
 mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/dpns
@@ -1328,7 +1487,7 @@ rm ${RPM_BUILD_ROOT}%{_mandir}/man1/dpnsdaemon.1
 touch ${RPM_BUILD_ROOT}%{_mandir}/man8/dpnsdaemon.8
 
 mv ${RPM_BUILD_ROOT}%{_sysconfdir}/NSCONFIG.templ \
-   ${RPM_BUILD_ROOT}%{_libdir}/dpm-postgres/DPNSCONFIG.templ
+   ${RPM_BUILD_ROOT}%{_datadir}/dpm-postgres/DPNSCONFIG.templ
 touch ${RPM_BUILD_ROOT}%{_datadir}/dpm/DPNSCONFIG.templ
 
 # dpns-shutdown binary and man page
@@ -1342,7 +1501,14 @@ sed -e 's/\(\.TH [^ ]* \)1/\18/' \
 rm ${RPM_BUILD_ROOT}%{_mandir}/man1/dpns-shutdown.1
 touch ${RPM_BUILD_ROOT}%{_mandir}/man8/dpns-shutdown.8
 
-# dpmcopyd startup script
+# dpmcopyd unit file / startup script
+%if %systemd
+rm ${RPM_BUILD_ROOT}%{_datadir}/dpm/rc.dpmcopyd
+rm ${RPM_BUILD_ROOT}%{_sysconfdir}/dpmcopyd.conf.templ
+install -m 644 -p ../../lcgdm-unitfiles/postgres/dpmcopyd.service \
+    ${RPM_BUILD_ROOT}%{_datadir}/dpm-postgres
+touch ${RPM_BUILD_ROOT}%{_unitdir}/dpmcopyd.service
+%else
 sed -e 's/LD_LIBRARY_PATH=$LD_LIBRARY_PATH //' \
     -e '/LD_LIBRARY_PATH/d' \
     -e 's!\$PREFIX/bin!\$PREFIX/sbin!' \
@@ -1353,14 +1519,13 @@ chmod 755 ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm-postgres/dpmcopyd.init
 rm ${RPM_BUILD_ROOT}%{_datadir}/dpm/rc.dpmcopyd
 touch ${RPM_BUILD_ROOT}%{_initrddir}/dpmcopyd
 chmod 755 ${RPM_BUILD_ROOT}%{_initrddir}/dpmcopyd
-
-# dpmcopyd configuration file
 sed -e 's/\(^DPNS_HOST=\).*/\1`hostname -f`/' \
     -e 's/\(^DPM_HOST=\).*/\1`hostname -f`/' \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/dpmcopyd.conf.templ > \
     ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm-postgres/dpmcopyd.conf
 rm ${RPM_BUILD_ROOT}%{_sysconfdir}/dpmcopyd.conf.templ
 touch ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig/dpmcopyd
+%endif
 
 # dpmcopyd log directory and log rotation configuration
 mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/dpmcopy
@@ -1380,7 +1545,14 @@ rm ${RPM_BUILD_ROOT}%{_mandir}/man1/dpmcopyd.1
 touch ${RPM_BUILD_ROOT}%{_mandir}/man8/dpmcopyd.8
 
 for svc in srmv1 srmv2 srmv2.2 ; do
-    # startup script
+    # unit file / startup script
+%if %systemd
+    rm ${RPM_BUILD_ROOT}%{_datadir}/dpm/rc.${svc}
+    rm ${RPM_BUILD_ROOT}%{_sysconfdir}/${svc}.conf.templ
+    install -m 644 -p ../../lcgdm-unitfiles/postgres/dpm-${svc}.service \
+	${RPM_BUILD_ROOT}%{_datadir}/dpm-postgres
+    touch ${RPM_BUILD_ROOT}%{_unitdir}/dpm-${svc}.service
+%else
     sed -e 's/LD_LIBRARY_PATH=$LD_LIBRARY_PATH //' \
 	-e '/LD_LIBRARY_PATH/d' \
 	-e 's!\$PREFIX/bin!\$PREFIX/sbin!' \
@@ -1392,8 +1564,6 @@ for svc in srmv1 srmv2 srmv2.2 ; do
     rm ${RPM_BUILD_ROOT}%{_datadir}/dpm/rc.${svc}
     touch ${RPM_BUILD_ROOT}%{_initrddir}/dpm-${svc}
     chmod 755 ${RPM_BUILD_ROOT}%{_initrddir}/dpm-${svc}
-
-    # configuration file
     sed -e "s/${svc}/dpm-${svc}/g" \
 	-e 's/\(^DPNS_HOST=\).*/\1`hostname -f`/' \
 	-e 's/\(^DPM_HOST=\).*/\1`hostname -f`/' \
@@ -1402,6 +1572,7 @@ for svc in srmv1 srmv2 srmv2.2 ; do
 	${RPM_BUILD_ROOT}%{_sysconfdir}/dpm-postgres/dpm-${svc}.conf
     rm ${RPM_BUILD_ROOT}%{_sysconfdir}/${svc}.conf.templ
     touch ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig/dpm-${svc}
+%endif
 
     # log directory and log rotation configuration
     mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/dpm-${svc}
@@ -1432,11 +1603,13 @@ sed '/CREATE DATABASE/d' -i \
     ${RPM_BUILD_ROOT}%{_datadir}/dpm/create_dpm_tables_postgres.sql \
     ${RPM_BUILD_ROOT}%{_datadir}/dpm/create_dpns_tables_postgres.sql
 
+%if %systemd == 0
 # Turn off services by default
 sed -e 's/\(chkconfig: \)\w*/\1-/' \
     -e '/Default-Start/d' \
     -e 's/\(Default-Stop: *\).*/\10 1 2 3 4 5 6/' \
     -i ${RPM_BUILD_ROOT}%{_sysconfdir}/dpm-postgres/*.init
+%endif
 
 popd
 
@@ -1544,11 +1717,16 @@ updatelfc
   --slave %{_mandir}/man8/lfcdaemon.8.gz lfcdaemon.8.gz \
 	  %{_libdir}/lfc-mysql/lfcdaemon.8.gz \
   --slave %{_datadir}/lfc/NSCONFIG.templ NSCONFIG.templ \
-	  %{_libdir}/lfc-mysql/NSCONFIG.templ \
+	  %{_datadir}/lfc-mysql/NSCONFIG.templ \
+%if %systemd
+  --slave %{_unitdir}/lfcdaemon.service lfcdaemon.service \
+	  %{_datadir}/lfc-mysql/lfcdaemon.service \
+%else
   --slave %{_initrddir}/lfcdaemon lfcdaemon.init \
 	  %{_sysconfdir}/lfc-mysql/lfcdaemon.init \
   --slave %{_sysconfdir}/sysconfig/lfcdaemon lfcdaemon.conf \
 	  %{_sysconfdir}/lfc-mysql/lfcdaemon.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/lfcdaemon lfcdaemon.logrotate \
 	  %{_sysconfdir}/lfc-mysql/lfcdaemon.logrotate \
   --slave %{_sbindir}/lfc-shutdown lfc-shutdown \
@@ -1556,10 +1734,12 @@ updatelfc
   --slave %{_mandir}/man8/lfc-shutdown.8.gz lfc-shutdown.8.gz \
 	  %{_libdir}/lfc-mysql/lfc-shutdown.8.gz
 
-if [ $1 = 1 ]; then
-    if [ -r %{_initrddir}/lfcdaemon ]; then
-	/sbin/chkconfig --add lfcdaemon
-    fi
+if [ $1 -eq 1 ]; then
+%if %systemd
+    /bin/systemctl daemon-reload > /dev/null 2>&1 || :
+%else
+    /sbin/chkconfig --add lfcdaemon
+%endif
 fi
 
 %post -n lfc-server-postgres
@@ -1609,16 +1789,29 @@ updatelfc () {
 
 updatelfc
 
+%if %systemd
+# Clean up pre-systemd config
+if [ -r %{_initrddir}/lfcdaemon ] ; then
+    /sbin/service lfcdaemon stop > /dev/null 2>&1 || :
+    /sbin/chkconfig --del lfcdaemon > /dev/null 2>&1 || :
+fi
+%endif
+
 %{_sbindir}/update-alternatives --install %{_sbindir}/lfcdaemon lfcdaemon \
 	  %{_libdir}/lfc-postgres/lfcdaemon 10 \
   --slave %{_mandir}/man8/lfcdaemon.8.gz lfcdaemon.8.gz \
 	  %{_libdir}/lfc-postgres/lfcdaemon.8.gz \
   --slave %{_datadir}/lfc/NSCONFIG.templ NSCONFIG.templ \
-	  %{_libdir}/lfc-postgres/NSCONFIG.templ \
+	  %{_datadir}/lfc-postgres/NSCONFIG.templ \
+%if %systemd
+  --slave %{_unitdir}/lfcdaemon.service lfcdaemon.service \
+	  %{_datadir}/lfc-postgres/lfcdaemon.service \
+%else
   --slave %{_initrddir}/lfcdaemon lfcdaemon.init \
 	  %{_sysconfdir}/lfc-postgres/lfcdaemon.init \
   --slave %{_sysconfdir}/sysconfig/lfcdaemon lfcdaemon.conf \
 	  %{_sysconfdir}/lfc-postgres/lfcdaemon.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/lfcdaemon lfcdaemon.logrotate \
 	  %{_sysconfdir}/lfc-postgres/lfcdaemon.logrotate \
   --slave %{_sbindir}/lfc-shutdown lfc-shutdown \
@@ -1626,54 +1819,84 @@ updatelfc
   --slave %{_mandir}/man8/lfc-shutdown.8.gz lfc-shutdown.8.gz \
 	  %{_libdir}/lfc-postgres/lfc-shutdown.8.gz
 
-if [ $1 = 1 ]; then
-    if [ -r %{_initrddir}/lfcdaemon ]; then
-	/sbin/chkconfig --add lfcdaemon
-    fi
+if [ $1 -eq 1 ]; then
+%if %systemd
+    /bin/systemctl daemon-reload > /dev/null 2>&1 || :
+%else
+    /sbin/chkconfig --add lfcdaemon
+%endif
 fi
 
 %preun -n lfc-server-mysql
 export LANG=C
 
-if [ $1 = 0 ]; then
-    %{_sbindir}/update-alternatives --display lfcdaemon | \
-	grep currently | grep -q lfc-mysql && \
+if [ $1 -eq 0 ]; then
+    if ( %{_sbindir}/update-alternatives --display lfcdaemon | \
+	grep currently | grep -q lfc-mysql ) ; then
+%if %systemd
+	/bin/systemctl --no-reload disable lfcdaemon.service \
+	    > /dev/null 2>&1 || :
+	/bin/systemctl stop lfcdaemon.service > /dev/null 2>&1 || :
+%else
 	/sbin/service lfcdaemon stop > /dev/null 2>&1 || :
+%endif
+    fi
     %{_sbindir}/update-alternatives --remove lfcdaemon \
 	%{_libdir}/lfc-mysql/lfcdaemon
+%if %systemd == 0
     %{_sbindir}/update-alternatives --display lfcdaemon > /dev/null || \
 	/sbin/chkconfig --del lfcdaemon > /dev/null 2>&1 || :
+%endif
 fi
 
 %preun -n lfc-server-postgres
 export LANG=C
 
-if [ $1 = 0 ]; then
-    %{_sbindir}/update-alternatives --display lfcdaemon | \
-	grep currently | grep -q lfc-postgres && \
+if [ $1 -eq 0 ]; then
+    if ( %{_sbindir}/update-alternatives --display lfcdaemon | \
+	grep currently | grep -q lfc-postgres ) ; then
+%if %systemd
+	/bin/systemctl --no-reload disable lfcdaemon.service \
+	    > /dev/null 2>&1 || :
+	/bin/systemctl stop lfcdaemon.service > /dev/null 2>&1 || :
+%else
 	/sbin/service lfcdaemon stop > /dev/null 2>&1 || :
+%endif
+    fi
     %{_sbindir}/update-alternatives --remove lfcdaemon \
 	%{_libdir}/lfc-postgres/lfcdaemon
+%if %systemd == 0
     %{_sbindir}/update-alternatives --display lfcdaemon > /dev/null || \
 	/sbin/chkconfig --del lfcdaemon > /dev/null 2>&1 || :
+%endif
 fi
 
 %postun -n lfc-server-mysql
 export LANG=C
 
 if [ $1 -ge 1 ]; then
-    %{_sbindir}/update-alternatives --display lfcdaemon | \
-	grep currently | grep -q lfc-mysql && \
+    if ( %{_sbindir}/update-alternatives --display lfcdaemon | \
+	grep currently | grep -q lfc-mysql ) ; then
+%if %systemd
+	/bin/systemctl try-restart lfcdaemon.service > /dev/null 2>&1 || :
+%else
 	/sbin/service lfcdaemon condrestart > /dev/null 2>&1 || :
+%endif
+    fi
 fi
 
 %postun -n lfc-server-postgres
 export LANG=C
 
 if [ $1 -ge 1 ]; then
-    %{_sbindir}/update-alternatives --display lfcdaemon | \
-	grep currently | grep -q lfc-postgres && \
+    if ( %{_sbindir}/update-alternatives --display lfcdaemon | \
+	grep currently | grep -q lfc-postgres ) ; then
+%if %systemd
+	/bin/systemctl try-restart lfcdaemon.service > /dev/null 2>&1 || :
+%else
 	/sbin/service lfcdaemon condrestart > /dev/null 2>&1 || :
+%endif
+    fi
 fi
 
 %triggerpostun -n lfc-server-mysql -- lfc-mysql < 1.8.1.2-2
@@ -1683,11 +1906,16 @@ fi
   --slave %{_mandir}/man8/lfcdaemon.8.gz lfcdaemon.8.gz \
 	  %{_libdir}/lfc-mysql/lfcdaemon.8.gz \
   --slave %{_datadir}/lfc/NSCONFIG.templ NSCONFIG.templ \
-	  %{_libdir}/lfc-mysql/NSCONFIG.templ \
+	  %{_datadir}/lfc-mysql/NSCONFIG.templ \
+%if %systemd
+  --slave %{_unitdir}/lfcdaemon.service lfcdaemon.service \
+	  %{_datadir}/lfc-mysql/lfcdaemon.service \
+%else
   --slave %{_initrddir}/lfcdaemon lfcdaemon.init \
 	  %{_sysconfdir}/lfc-mysql/lfcdaemon.init \
   --slave %{_sysconfdir}/sysconfig/lfcdaemon lfcdaemon.conf \
 	  %{_sysconfdir}/lfc-mysql/lfcdaemon.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/lfcdaemon lfcdaemon.logrotate \
 	  %{_sysconfdir}/lfc-mysql/lfcdaemon.logrotate \
   --slave %{_sbindir}/lfc-shutdown lfc-shutdown \
@@ -1702,11 +1930,16 @@ fi
   --slave %{_mandir}/man8/lfcdaemon.8.gz lfcdaemon.8.gz \
 	  %{_libdir}/lfc-postgres/lfcdaemon.8.gz \
   --slave %{_datadir}/lfc/NSCONFIG.templ NSCONFIG.templ \
-	  %{_libdir}/lfc-postgres/NSCONFIG.templ \
+	  %{_datadir}/lfc-postgres/NSCONFIG.templ \
+%if %systemd
+  --slave %{_unitdir}/lfcdaemon.service lfcdaemon.service \
+	  %{_datadir}/lfc-postgres/lfcdaemon.service \
+%else
   --slave %{_initrddir}/lfcdaemon lfcdaemon.init \
 	  %{_sysconfdir}/lfc-postgres/lfcdaemon.init \
   --slave %{_sysconfdir}/sysconfig/lfcdaemon lfcdaemon.conf \
 	  %{_sysconfdir}/lfc-postgres/lfcdaemon.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/lfcdaemon lfcdaemon.logrotate \
 	  %{_sysconfdir}/lfc-postgres/lfcdaemon.logrotate \
   --slave %{_sbindir}/lfc-shutdown lfc-shutdown \
@@ -1721,19 +1954,40 @@ getent passwd lfcmgr > /dev/null || useradd -r -g lfcmgr \
 exit 0
 
 %post -n lfc-dli
-if [ $1 = 1 ]; then
+%if %systemd
+# Clean up pre-systemd config
+if [ -r %{_initrddir}/lfc-dli ] ; then
+    /sbin/service lfc-dli stop > /dev/null 2>&1 || :
+    /sbin/chkconfig --del lfc-dli > /dev/null 2>&1 || :
+fi
+%endif
+
+if [ $1 -eq 1 ]; then
+%if %systemd
+    /bin/systemctl daemon-reload > /dev/null 2>&1 || :
+%else
     /sbin/chkconfig --add lfc-dli
+%endif
 fi
 
 %preun -n lfc-dli
-if [ $1 = 0 ]; then
+if [ $1 -eq 0 ]; then
+%if %systemd
+    /bin/systemctl --no-reload disable lfc-dli.service > /dev/null 2>&1 || :
+    /bin/systemctl stop lfc-dli.service > /dev/null 2>&1 || :
+%else
     /sbin/service lfc-dli stop > /dev/null 2>&1 || :
     /sbin/chkconfig --del lfc-dli
+%endif
 fi
 
 %postun -n lfc-dli
 if [ $1 -ge 1 ]; then
+%if %systemd
+    /bin/systemctl try-restart lfc-dli.service > /dev/null 2>&1 || :
+%else
     /sbin/service lfc-dli condrestart > /dev/null 2>&1 || :
+%endif
 fi
 
 %pre -n dpm-server-mysql
@@ -1801,16 +2055,29 @@ updatedpm () {
 
 updatedpm
 
+%if %systemd
+# Clean up pre-systemd config
+if [ -r %{_initrddir}/dpm ] ; then
+    /sbin/service dpm stop > /dev/null 2>&1 || :
+    /sbin/chkconfig --del dpm > /dev/null 2>&1 || :
+fi
+%endif
+
 %{_sbindir}/update-alternatives --install %{_sbindir}/dpm dpm \
 	  %{_libdir}/dpm-mysql/dpm 20 \
   --slave %{_mandir}/man8/dpm.8.gz dpm.8.gz \
 	  %{_libdir}/dpm-mysql/dpm.8.gz \
   --slave %{_datadir}/dpm/DPMCONFIG.templ DPMCONFIG.templ \
-	  %{_libdir}/dpm-mysql/DPMCONFIG.templ \
+	  %{_datadir}/dpm-mysql/DPMCONFIG.templ \
+%if %systemd
+  --slave %{_unitdir}/dpm.service dpm.service \
+	  %{_datadir}/dpm-mysql/dpm.service \
+%else
   --slave %{_initrddir}/dpm dpm.init \
 	  %{_sysconfdir}/dpm-mysql/dpm.init \
   --slave %{_sysconfdir}/sysconfig/dpm dpm.conf \
 	  %{_sysconfdir}/dpm-mysql/dpm.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpm dpm.logrotate \
 	  %{_sysconfdir}/dpm-mysql/dpm.logrotate \
   --slave %{_sbindir}/dpm-shutdown dpm-shutdown \
@@ -1822,10 +2089,12 @@ updatedpm
   --slave %{_mandir}/man8/dpm-buildfsv.8.gz dpm-buildfsv.8.gz \
 	  %{_libdir}/dpm-mysql/dpm-buildfsv.8.gz
 
-if [ $1 = 1 ]; then
-    if [ -r %{_initrddir}/dpm ]; then
-	/sbin/chkconfig --add dpm
-    fi
+if [ $1 -eq 1 ]; then
+%if %systemd
+    /bin/systemctl daemon-reload > /dev/null 2>&1 || :
+%else
+    /sbin/chkconfig --add dpm
+%endif
 fi
 
 %post -n dpm-server-postgres
@@ -1873,16 +2142,29 @@ updatedpm () {
 
 updatedpm
 
+%if %systemd
+# Clean up pre-systemd config
+if [ -r %{_initrddir}/dpm ] ; then
+    /sbin/service dpm stop > /dev/null 2>&1 || :
+    /sbin/chkconfig --del dpm > /dev/null 2>&1 || :
+fi
+%endif
+
 %{_sbindir}/update-alternatives --install %{_sbindir}/dpm dpm \
 	  %{_libdir}/dpm-postgres/dpm 10 \
   --slave %{_mandir}/man8/dpm.8.gz dpm.8.gz \
 	  %{_libdir}/dpm-postgres/dpm.8.gz \
   --slave %{_datadir}/dpm/DPMCONFIG.templ DPMCONFIG.templ \
-	  %{_libdir}/dpm-postgres/DPMCONFIG.templ \
+	  %{_datadir}/dpm-postgres/DPMCONFIG.templ \
+%if %systemd
+  --slave %{_unitdir}/dpm.service dpm.service \
+	  %{_datadir}/dpm-postgres/dpm.service \
+%else
   --slave %{_initrddir}/dpm dpm.init \
 	  %{_sysconfdir}/dpm-postgres/dpm.init \
   --slave %{_sysconfdir}/sysconfig/dpm dpm.conf \
 	  %{_sysconfdir}/dpm-postgres/dpm.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpm dpm.logrotate \
 	  %{_sysconfdir}/dpm-postgres/dpm.logrotate \
   --slave %{_sbindir}/dpm-shutdown dpm-shutdown \
@@ -1894,10 +2176,12 @@ updatedpm
   --slave %{_mandir}/man8/dpm-buildfsv.8.gz dpm-buildfsv.8.gz \
 	  %{_libdir}/dpm-postgres/dpm-buildfsv.8.gz
 
-if [ $1 = 1 ]; then
-    if [ -r %{_initrddir}/dpm ]; then
-	/sbin/chkconfig --add dpm
-    fi
+if [ $1 -eq 1 ]; then
+%if %systemd
+    /bin/systemctl daemon-reload > /dev/null 2>&1 || :
+%else
+    /sbin/chkconfig --add dpm
+%endif
 fi
 
 %triggerpostun -n dpm-server-mysql -- dpm-mysql < 1.8.1.2-2
@@ -1907,11 +2191,16 @@ fi
   --slave %{_mandir}/man8/dpm.8.gz dpm.8.gz \
 	  %{_libdir}/dpm-mysql/dpm.8.gz \
   --slave %{_datadir}/dpm/DPMCONFIG.templ DPMCONFIG.templ \
-	  %{_libdir}/dpm-mysql/DPMCONFIG.templ \
+	  %{_datadir}/dpm-mysql/DPMCONFIG.templ \
+%if %systemd
+  --slave %{_unitdir}/dpm.service dpm.service \
+	  %{_datadir}/dpm-mysql/dpm.service \
+%else
   --slave %{_initrddir}/dpm dpm.init \
 	  %{_sysconfdir}/dpm-mysql/dpm.init \
   --slave %{_sysconfdir}/sysconfig/dpm dpm.conf \
 	  %{_sysconfdir}/dpm-mysql/dpm.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpm dpm.logrotate \
 	  %{_sysconfdir}/dpm-mysql/dpm.logrotate \
   --slave %{_sbindir}/dpm-shutdown dpm-shutdown \
@@ -1930,11 +2219,16 @@ fi
   --slave %{_mandir}/man8/dpm.8.gz dpm.8.gz \
 	  %{_libdir}/dpm-postgres/dpm.8.gz \
   --slave %{_datadir}/dpm/DPMCONFIG.templ DPMCONFIG.templ \
-	  %{_libdir}/dpm-postgres/DPMCONFIG.templ \
+	  %{_datadir}/dpm-postgres/DPMCONFIG.templ \
+%if %systemd
+  --slave %{_unitdir}/dpm.service dpm.service \
+	  %{_datadir}/dpm-postgres/dpm.service \
+%else
   --slave %{_initrddir}/dpm dpm.init \
 	  %{_sysconfdir}/dpm-postgres/dpm.init \
   --slave %{_sysconfdir}/sysconfig/dpm dpm.conf \
 	  %{_sysconfdir}/dpm-postgres/dpm.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpm dpm.logrotate \
 	  %{_sysconfdir}/dpm-postgres/dpm.logrotate \
   --slave %{_sbindir}/dpm-shutdown dpm-shutdown \
@@ -1949,45 +2243,73 @@ fi
 %preun -n dpm-server-mysql
 export LANG=C
 
-if [ $1 = 0 ]; then
-    %{_sbindir}/update-alternatives --display dpm | \
-	grep currently | grep -q dpm-mysql && \
+if [ $1 -eq 0 ]; then
+    if ( %{_sbindir}/update-alternatives --display dpm | \
+	grep currently | grep -q dpm-mysql ) ; then
+%if %systemd
+	/bin/systemctl --no-reload disable dpm.service \
+	    > /dev/null 2>&1 || :
+	/bin/systemctl stop dpm.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpm stop > /dev/null 2>&1 || :
+%endif
+    fi
     %{_sbindir}/update-alternatives --remove dpm \
 	%{_libdir}/dpm-mysql/dpm
+%if %systemd == 0
     %{_sbindir}/update-alternatives --display dpm > /dev/null || \
 	/sbin/chkconfig --del dpm > /dev/null 2>&1 || :
+%endif
 fi
 
 %preun -n dpm-server-postgres
 export LANG=C
 
-if [ $1 = 0 ]; then
-    %{_sbindir}/update-alternatives --display dpm | \
-	grep currently | grep -q dpm-postgres && \
+if [ $1 -eq 0 ]; then
+    if ( %{_sbindir}/update-alternatives --display dpm | \
+	grep currently | grep -q dpm-postgres ) ; then
+%if %systemd
+	/bin/systemctl --no-reload disable dpm.service \
+	    > /dev/null 2>&1 || :
+	/bin/systemctl stop dpm.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpm stop > /dev/null 2>&1 || :
+%endif
+    fi
     %{_sbindir}/update-alternatives --remove dpm \
 	%{_libdir}/dpm-postgres/dpm
+%if %systemd == 0
     %{_sbindir}/update-alternatives --display dpm > /dev/null || \
 	/sbin/chkconfig --del dpm > /dev/null 2>&1 || :
+%endif
 fi
 
 %postun -n dpm-server-mysql
 export LANG=C
 
 if [ $1 -ge 1 ]; then
-    %{_sbindir}/update-alternatives --display dpm | \
-	grep currently | grep -q dpm-mysql && \
+    if ( %{_sbindir}/update-alternatives --display dpm | \
+	grep currently | grep -q dpm-mysql ) ; then
+%if %systemd
+	/bin/systemctl try-restart dpm.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpm condrestart > /dev/null 2>&1 || :
+%endif
+    fi
 fi
 
 %postun -n dpm-server-postgres
 export LANG=C
 
 if [ $1 -ge 1 ]; then
-    %{_sbindir}/update-alternatives --display dpm | \
-	grep currently | grep -q dpm-postgres && \
+    if ( %{_sbindir}/update-alternatives --display dpm | \
+	grep currently | grep -q dpm-postgres ) ; then
+%if %systemd
+	/bin/systemctl try-restart dpm.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpm condrestart > /dev/null 2>&1 || :
+%endif
+    fi
 fi
 
 %pre -n dpm-name-server-mysql
@@ -2057,16 +2379,29 @@ updatedpns () {
 
 updatedpns
 
+%if %systemd
+# Clean up pre-systemd config
+if [ -r %{_initrddir}/dpnsdaemon ] ; then
+    /sbin/service dpnsdaemon stop > /dev/null 2>&1 || :
+    /sbin/chkconfig --del dpnsdaemon > /dev/null 2>&1 || :
+fi
+%endif
+
 %{_sbindir}/update-alternatives --install %{_sbindir}/dpnsdaemon dpnsdaemon \
 	  %{_libdir}/dpm-mysql/dpnsdaemon 20 \
   --slave %{_mandir}/man8/dpnsdaemon.8.gz dpnsdaemon.8.gz \
 	  %{_libdir}/dpm-mysql/dpnsdaemon.8.gz \
   --slave %{_datadir}/dpm/DPNSCONFIG.templ DPNSCONFIG.templ \
-	  %{_libdir}/dpm-mysql/DPNSCONFIG.templ \
+	  %{_datadir}/dpm-mysql/DPNSCONFIG.templ \
+%if %systemd
+  --slave %{_unitdir}/dpnsdaemon.service dpnsdaemon.service \
+	  %{_datadir}/dpm-mysql/dpnsdaemon.service \
+%else
   --slave %{_initrddir}/dpnsdaemon dpnsdaemon.init \
 	  %{_sysconfdir}/dpm-mysql/dpnsdaemon.init \
   --slave %{_sysconfdir}/sysconfig/dpnsdaemon dpnsdaemon.conf \
 	  %{_sysconfdir}/dpm-mysql/dpnsdaemon.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpnsdaemon dpnsdaemon.logrotate \
 	  %{_sysconfdir}/dpm-mysql/dpnsdaemon.logrotate \
   --slave %{_sbindir}/dpns-shutdown dpns-shutdown \
@@ -2074,10 +2409,12 @@ updatedpns
   --slave %{_mandir}/man8/dpns-shutdown.8.gz dpns-shutdown.8.gz \
 	  %{_libdir}/dpm-mysql/dpns-shutdown.8.gz
 
-if [ $1 = 1 ]; then
-    if [ -r %{_initrddir}/dpnsdaemon ]; then
-	/sbin/chkconfig --add dpnsdaemon
-    fi
+if [ $1 -eq 1 ]; then
+%if %systemd
+    /bin/systemctl daemon-reload > /dev/null 2>&1 || :
+%else
+    /sbin/chkconfig --add dpnsdaemon
+%endif
 fi
 
 %post -n dpm-name-server-postgres
@@ -2127,16 +2464,29 @@ updatedpns () {
 
 updatedpns
 
+%if %systemd
+# Clean up pre-systemd config
+if [ -r %{_initrddir}/dpnsdaemon ] ; then
+    /sbin/service dpnsdaemon stop > /dev/null 2>&1 || :
+    /sbin/chkconfig --del dpnsdaemon > /dev/null 2>&1 || :
+fi
+%endif
+
 %{_sbindir}/update-alternatives --install %{_sbindir}/dpnsdaemon dpnsdaemon \
 	  %{_libdir}/dpm-postgres/dpnsdaemon 10 \
   --slave %{_mandir}/man8/dpnsdaemon.8.gz dpnsdaemon.8.gz \
 	  %{_libdir}/dpm-postgres/dpnsdaemon.8.gz \
   --slave %{_datadir}/dpm/DPNSCONFIG.templ DPNSCONFIG.templ \
-	  %{_libdir}/dpm-postgres/DPNSCONFIG.templ \
+	  %{_datadir}/dpm-postgres/DPNSCONFIG.templ \
+%if %systemd
+  --slave %{_unitdir}/dpnsdaemon.service dpnsdaemon.service \
+	  %{_datadir}/dpm-postgres/dpnsdaemon.service \
+%else
   --slave %{_initrddir}/dpnsdaemon dpnsdaemon.init \
 	  %{_sysconfdir}/dpm-postgres/dpnsdaemon.init \
   --slave %{_sysconfdir}/sysconfig/dpnsdaemon dpnsdaemon.conf \
 	  %{_sysconfdir}/dpm-postgres/dpnsdaemon.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpnsdaemon dpnsdaemon.logrotate \
 	  %{_sysconfdir}/dpm-postgres/dpnsdaemon.logrotate \
   --slave %{_sbindir}/dpns-shutdown dpns-shutdown \
@@ -2144,10 +2494,12 @@ updatedpns
   --slave %{_mandir}/man8/dpns-shutdown.8.gz dpns-shutdown.8.gz \
 	  %{_libdir}/dpm-postgres/dpns-shutdown.8.gz
 
-if [ $1 = 1 ]; then
-    if [ -r %{_initrddir}/dpnsdaemon ]; then
-	/sbin/chkconfig --add dpnsdaemon
-    fi
+if [ $1 -eq 1 ]; then
+%if %systemd
+    /bin/systemctl daemon-reload > /dev/null 2>&1 || :
+%else
+    /sbin/chkconfig --add dpnsdaemon
+%endif
 fi
 
 %triggerpostun -n dpm-name-server-mysql -- dpm-mysql-nameserver < 1.8.1.2-2
@@ -2157,11 +2509,16 @@ fi
   --slave %{_mandir}/man8/dpnsdaemon.8.gz dpnsdaemon.8.gz \
 	  %{_libdir}/dpm-mysql/dpnsdaemon.8.gz \
   --slave %{_datadir}/dpm/DPNSCONFIG.templ DPNSCONFIG.templ \
-	  %{_libdir}/dpm-mysql/DPNSCONFIG.templ \
+	  %{_datadir}/dpm-mysql/DPNSCONFIG.templ \
+%if %systemd
+  --slave %{_unitdir}/dpnsdaemon.service dpnsdaemon.service \
+	  %{_datadir}/dpm-mysql/dpnsdaemon.service \
+%else
   --slave %{_initrddir}/dpnsdaemon dpnsdaemon.init \
 	  %{_sysconfdir}/dpm-mysql/dpnsdaemon.init \
   --slave %{_sysconfdir}/sysconfig/dpnsdaemon dpnsdaemon.conf \
 	  %{_sysconfdir}/dpm-mysql/dpnsdaemon.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpnsdaemon dpnsdaemon.logrotate \
 	  %{_sysconfdir}/dpm-mysql/dpnsdaemon.logrotate \
   --slave %{_sbindir}/dpns-shutdown dpns-shutdown \
@@ -2176,11 +2533,16 @@ fi
   --slave %{_mandir}/man8/dpnsdaemon.8.gz dpnsdaemon.8.gz \
 	  %{_libdir}/dpm-postgres/dpnsdaemon.8.gz \
   --slave %{_datadir}/dpm/DPNSCONFIG.templ DPNSCONFIG.templ \
-	  %{_libdir}/dpm-postgres/DPNSCONFIG.templ \
+	  %{_datadir}/dpm-postgres/DPNSCONFIG.templ \
+%if %systemd
+  --slave %{_unitdir}/dpnsdaemon.service dpnsdaemon.service \
+	  %{_datadir}/dpm-postgres/dpnsdaemon.service \
+%else
   --slave %{_initrddir}/dpnsdaemon dpnsdaemon.init \
 	  %{_sysconfdir}/dpm-postgres/dpnsdaemon.init \
   --slave %{_sysconfdir}/sysconfig/dpnsdaemon dpnsdaemon.conf \
 	  %{_sysconfdir}/dpm-postgres/dpnsdaemon.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpnsdaemon dpnsdaemon.logrotate \
 	  %{_sysconfdir}/dpm-postgres/dpnsdaemon.logrotate \
   --slave %{_sbindir}/dpns-shutdown dpns-shutdown \
@@ -2191,45 +2553,73 @@ fi
 %preun -n dpm-name-server-mysql
 export LANG=C
 
-if [ $1 = 0 ]; then
-    %{_sbindir}/update-alternatives --display dpnsdaemon | \
-	grep currently | grep -q dpm-mysql && \
+if [ $1 -eq 0 ]; then
+    if ( %{_sbindir}/update-alternatives --display dpnsdaemon | \
+	grep currently | grep -q dpm-mysql ) ; then
+%if %systemd
+	/bin/systemctl --no-reload disable dpnsdaemon.service \
+	    > /dev/null 2>&1 || :
+	/bin/systemctl stop dpnsdaemon.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpnsdaemon stop > /dev/null 2>&1 || :
+%endif
+    fi
     %{_sbindir}/update-alternatives --remove dpnsdaemon \
 	%{_libdir}/dpm-mysql/dpnsdaemon
+%if %systemd == 0
     %{_sbindir}/update-alternatives --display dpnsdaemon > /dev/null || \
 	/sbin/chkconfig --del dpnsdaemon > /dev/null 2>&1 || :
+%endif
 fi
 
 %preun -n dpm-name-server-postgres
 export LANG=C
 
-if [ $1 = 0 ]; then
-    %{_sbindir}/update-alternatives --display dpnsdaemon | \
-	grep currently | grep -q dpm-postgres && \
+if [ $1 -eq 0 ]; then
+    if ( %{_sbindir}/update-alternatives --display dpnsdaemon | \
+	grep currently | grep -q dpm-postgres ) ; then
+%if %systemd
+	/bin/systemctl --no-reload disable dpnsdaemon.service \
+	    > /dev/null 2>&1 || :
+	/bin/systemctl stop dpnsdaemon.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpnsdaemon stop > /dev/null 2>&1 || :
+%endif
+    fi
     %{_sbindir}/update-alternatives --remove dpnsdaemon \
 	%{_libdir}/dpm-postgres/dpnsdaemon
+%if %systemd == 0
     %{_sbindir}/update-alternatives --display dpnsdaemon > /dev/null || \
 	/sbin/chkconfig --del dpnsdaemon > /dev/null 2>&1 || :
+%endif
 fi
 
 %postun -n dpm-name-server-mysql
 export LANG=C
 
 if [ $1 -ge 1 ]; then
-    %{_sbindir}/update-alternatives --display dpnsdaemon | \
-	grep currently | grep -q dpm-mysql && \
+    if ( %{_sbindir}/update-alternatives --display dpnsdaemon | \
+	grep currently | grep -q dpm-mysql ) ; then
+%if %systemd
+	/bin/systemctl try-restart dpnsdaemon.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpnsdaemon condrestart > /dev/null 2>&1 || :
+%endif
+    fi
 fi
 
 %postun -n dpm-name-server-postgres
 export LANG=C
 
 if [ $1 -ge 1 ]; then
-    %{_sbindir}/update-alternatives --display dpnsdaemon | \
-	grep currently | grep -q dpm-postgres && \
+    if ( %{_sbindir}/update-alternatives --display dpnsdaemon | \
+	grep currently | grep -q dpm-postgres ) ; then
+%if %systemd
+	/bin/systemctl try-restart dpnsdaemon.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpnsdaemon condrestart > /dev/null 2>&1 || :
+%endif
+    fi
 fi
 
 %pre -n dpm-copy-server-mysql
@@ -2245,39 +2635,69 @@ getent passwd dpmmgr > /dev/null || useradd -r -g dpmmgr \
 exit 0
 
 %post -n dpm-copy-server-mysql
+%if %systemd
+# Clean up pre-systemd config
+if [ -r %{_initrddir}/dpmcopyd ] ; then
+    /sbin/service dpmcopyd stop > /dev/null 2>&1 || :
+    /sbin/chkconfig --del dpmcopyd > /dev/null 2>&1 || :
+fi
+%endif
+
 %{_sbindir}/update-alternatives --install %{_sbindir}/dpmcopyd dpmcopyd \
 	  %{_libdir}/dpm-mysql/dpmcopyd 20 \
   --slave %{_mandir}/man8/dpmcopyd.8.gz dpmcopyd.8.gz \
 	  %{_libdir}/dpm-mysql/dpmcopyd.8.gz \
+%if %systemd
+  --slave %{_unitdir}/dpmcopyd.service dpmcopyd.service \
+	  %{_datadir}/dpm-mysql/dpmcopyd.service \
+%else
   --slave %{_initrddir}/dpmcopyd dpmcopyd.init \
 	  %{_sysconfdir}/dpm-mysql/dpmcopyd.init \
   --slave %{_sysconfdir}/sysconfig/dpmcopyd dpmcopyd.conf \
 	  %{_sysconfdir}/dpm-mysql/dpmcopyd.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpmcopyd dpmcopyd.logrotate \
 	  %{_sysconfdir}/dpm-mysql/dpmcopyd.logrotate
 
-if [ $1 = 1 ]; then
-    if [ -r %{_initrddir}/dpmcopyd ]; then
-	/sbin/chkconfig --add dpmcopyd
-    fi
+if [ $1 -eq 1 ]; then
+%if %systemd
+    /bin/systemctl daemon-reload > /dev/null 2>&1 || :
+%else
+    /sbin/chkconfig --add dpmcopyd
+%endif
 fi
 
 %post -n dpm-copy-server-postgres
+%if %systemd
+# Clean up pre-systemd config
+if [ -r %{_initrddir}/dpmcopyd ] ; then
+    /sbin/service dpmcopyd stop > /dev/null 2>&1 || :
+    /sbin/chkconfig --del dpmcopyd > /dev/null 2>&1 || :
+fi
+%endif
+
 %{_sbindir}/update-alternatives --install %{_sbindir}/dpmcopyd dpmcopyd \
 	  %{_libdir}/dpm-postgres/dpmcopyd 10 \
   --slave %{_mandir}/man8/dpmcopyd.8.gz dpmcopyd.8.gz \
 	  %{_libdir}/dpm-postgres/dpmcopyd.8.gz \
+%if %systemd
+  --slave %{_unitdir}/dpmcopyd.service dpmcopyd.service \
+	  %{_datadir}/dpm-postgres/dpmcopyd.service \
+%else
   --slave %{_initrddir}/dpmcopyd dpmcopyd.init \
 	  %{_sysconfdir}/dpm-postgres/dpmcopyd.init \
   --slave %{_sysconfdir}/sysconfig/dpmcopyd dpmcopyd.conf \
 	  %{_sysconfdir}/dpm-postgres/dpmcopyd.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpmcopyd dpmcopyd.logrotate \
 	  %{_sysconfdir}/dpm-postgres/dpmcopyd.logrotate
 
-if [ $1 = 1 ]; then
-    if [ -r %{_initrddir}/dpmcopyd ]; then
-	/sbin/chkconfig --add dpmcopyd
-    fi
+if [ $1 -eq 1 ]; then
+%if %systemd
+    /bin/systemctl daemon-reload > /dev/null 2>&1 || :
+%else
+    /sbin/chkconfig --add dpmcopyd
+%endif
 fi
 
 %triggerpostun -n dpm-copy-server-mysql -- dpm-mysql-copyd < 1.8.1.2-2
@@ -2286,10 +2706,15 @@ fi
 	  %{_libdir}/dpm-mysql/dpmcopyd 20 \
   --slave %{_mandir}/man8/dpmcopyd.8.gz dpmcopyd.8.gz \
 	  %{_libdir}/dpm-mysql/dpmcopyd.8.gz \
+%if %systemd
+  --slave %{_unitdir}/dpmcopyd.service dpmcopyd.service \
+	  %{_datadir}/dpm-mysql/dpmcopyd.service \
+%else
   --slave %{_initrddir}/dpmcopyd dpmcopyd.init \
 	  %{_sysconfdir}/dpm-mysql/dpmcopyd.init \
   --slave %{_sysconfdir}/sysconfig/dpmcopyd dpmcopyd.conf \
 	  %{_sysconfdir}/dpm-mysql/dpmcopyd.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpmcopyd dpmcopyd.logrotate \
 	  %{_sysconfdir}/dpm-mysql/dpmcopyd.logrotate
 
@@ -2299,61 +2724,96 @@ fi
 	  %{_libdir}/dpm-postgres/dpmcopyd 10 \
   --slave %{_mandir}/man8/dpmcopyd.8.gz dpmcopyd.8.gz \
 	  %{_libdir}/dpm-postgres/dpmcopyd.8.gz \
+%if %systemd
+  --slave %{_unitdir}/dpmcopyd.service dpmcopyd.service \
+	  %{_datadir}/dpm-postgres/dpmcopyd.service \
+%else
   --slave %{_initrddir}/dpmcopyd dpmcopyd.init \
 	  %{_sysconfdir}/dpm-postgres/dpmcopyd.init \
   --slave %{_sysconfdir}/sysconfig/dpmcopyd dpmcopyd.conf \
 	  %{_sysconfdir}/dpm-postgres/dpmcopyd.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpmcopyd dpmcopyd.logrotate \
 	  %{_sysconfdir}/dpm-postgres/dpmcopyd.logrotate
 
-if [ $1 = 1 ]; then
-    if [ -r %{_initrddir}/dpmcopyd ]; then
-	/sbin/chkconfig --add dpmcopyd
-    fi
+if [ $1 -eq 1 ]; then
+%if %systemd
+    /bin/systemctl daemon-reload > /dev/null 2>&1 || :
+%else
+    /sbin/chkconfig --add dpmcopyd
+%endif
 fi
 
 %preun -n dpm-copy-server-mysql
 export LANG=C
 
-if [ $1 = 0 ]; then
-    %{_sbindir}/update-alternatives --display dpmcopyd | \
-	grep currently | grep -q dpm-mysql && \
+if [ $1 -eq 0 ]; then
+    if ( %{_sbindir}/update-alternatives --display dpmcopyd | \
+	grep currently | grep -q dpm-mysql ) ; then
+%if %systemd
+	/bin/systemctl --no-reload disable dpmcopyd.service \
+	    > /dev/null 2>&1 || :
+	/bin/systemctl stop dpmcopyd.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpmcopyd stop > /dev/null 2>&1 || :
+%endif
+    fi
     %{_sbindir}/update-alternatives --remove dpmcopyd \
 	%{_libdir}/dpm-mysql/dpmcopyd
+%if %systemd == 0
     %{_sbindir}/update-alternatives --display dpmcopyd > /dev/null || \
 	/sbin/chkconfig --del dpmcopyd > /dev/null 2>&1 || :
+%endif
 fi
 
 %preun -n dpm-copy-server-postgres
 export LANG=C
 
-if [ $1 = 0 ]; then
-    %{_sbindir}/update-alternatives --display dpmcopyd | \
-	grep currently | grep -q dpm-postgres && \
+if [ $1 -eq 0 ]; then
+    if ( %{_sbindir}/update-alternatives --display dpmcopyd | \
+	grep currently | grep -q dpm-postgres ) ; then
+%if %systemd
+	/bin/systemctl --no-reload disable dpmcopyd.service \
+	    > /dev/null 2>&1 || :
+	/bin/systemctl stop dpmcopyd.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpmcopyd stop > /dev/null 2>&1 || :
+%endif
+    fi
     %{_sbindir}/update-alternatives --remove dpmcopyd \
 	%{_libdir}/dpm-postgres/dpmcopyd
+%if %systemd == 0
     %{_sbindir}/update-alternatives --display dpmcopyd > /dev/null || \
 	/sbin/chkconfig --del dpmcopyd > /dev/null 2>&1 || :
+%endif
 fi
 
 %postun -n dpm-copy-server-mysql
 export LANG=C
 
 if [ $1 -ge 1 ]; then
-    %{_sbindir}/update-alternatives --display dpmcopyd | \
-	grep currently | grep -q dpm-mysql && \
+    if ( %{_sbindir}/update-alternatives --display dpmcopyd | \
+	grep currently | grep -q dpm-mysql ) ; then
+%if %systemd
+	/bin/systemctl try-restart dpmcopyd.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpmcopyd condrestart > /dev/null 2>&1 || :
+%endif
+    fi
 fi
 
 %postun -n dpm-copy-server-postgres
 export LANG=C
 
 if [ $1 -ge 1 ]; then
-    %{_sbindir}/update-alternatives --display dpmcopyd | \
-	grep currently | grep -q dpm-postgres && \
+    if ( %{_sbindir}/update-alternatives --display dpmcopyd | \
+	grep currently | grep -q dpm-postgres ) ; then
+%if %systemd
+	/bin/systemctl try-restart dpmcopyd.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpmcopyd condrestart > /dev/null 2>&1 || :
+%endif
+    fi
 fi
 
 %pre -n dpm-srm-server-mysql
@@ -2369,14 +2829,35 @@ getent passwd dpmmgr > /dev/null || useradd -r -g dpmmgr \
 exit 0
 
 %post -n dpm-srm-server-mysql
+%if %systemd
+# Clean up pre-systemd config
+if [ -r %{_initrddir}/dpm-srmv1 ] ; then
+    /sbin/service dpm-srmv1 stop > /dev/null 2>&1 || :
+    /sbin/chkconfig --del dpm-srmv1 > /dev/null 2>&1 || :
+fi
+if [ -r %{_initrddir}/dpm-srmv2 ] ; then
+    /sbin/service dpm-srmv2 stop > /dev/null 2>&1 || :
+    /sbin/chkconfig --del dpm-srmv2 > /dev/null 2>&1 || :
+fi
+if [ -r %{_initrddir}/dpm-srmv2.2 ] ; then
+    /sbin/service dpm-srmv2.2 stop > /dev/null 2>&1 || :
+    /sbin/chkconfig --del dpm-srmv2.2 > /dev/null 2>&1 || :
+fi
+%endif
+
 %{_sbindir}/update-alternatives --install %{_sbindir}/dpm-srmv1 dpm-srmv1 \
 	  %{_libdir}/dpm-mysql/dpm-srmv1 20 \
   --slave %{_mandir}/man8/dpm-srmv1.8.gz dpm-srmv1.8.gz \
 	  %{_libdir}/dpm-mysql/dpm-srmv1.8.gz \
+%if %systemd
+  --slave %{_unitdir}/dpm-srmv1.service dpm-srmv1.service \
+	  %{_datadir}/dpm-mysql/dpm-srmv1.service \
+%else
   --slave %{_initrddir}/dpm-srmv1 dpm-srmv1.init \
 	  %{_sysconfdir}/dpm-mysql/dpm-srmv1.init \
   --slave %{_sysconfdir}/sysconfig/dpm-srmv1 dpm-srmv1.conf \
 	  %{_sysconfdir}/dpm-mysql/dpm-srmv1.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpm-srmv1 dpm-srmv1.logrotate \
 	  %{_sysconfdir}/dpm-mysql/dpm-srmv1.logrotate
 
@@ -2384,10 +2865,15 @@ exit 0
 	  %{_libdir}/dpm-mysql/dpm-srmv2 20 \
   --slave %{_mandir}/man8/dpm-srmv2.8.gz dpm-srmv2.8.gz \
 	  %{_libdir}/dpm-mysql/dpm-srmv2.8.gz \
+%if %systemd
+  --slave %{_unitdir}/dpm-srmv2.service dpm-srmv2.service \
+	  %{_datadir}/dpm-mysql/dpm-srmv2.service \
+%else
   --slave %{_initrddir}/dpm-srmv2 dpm-srmv2.init \
 	  %{_sysconfdir}/dpm-mysql/dpm-srmv2.init \
   --slave %{_sysconfdir}/sysconfig/dpm-srmv2 dpm-srmv2.conf \
 	  %{_sysconfdir}/dpm-mysql/dpm-srmv2.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpm-srmv2 dpm-srmv2.logrotate \
 	  %{_sysconfdir}/dpm-mysql/dpm-srmv2.logrotate
 
@@ -2395,34 +2881,58 @@ exit 0
 	  %{_libdir}/dpm-mysql/dpm-srmv2.2 20 \
   --slave %{_mandir}/man8/dpm-srmv2.2.8.gz dpm-srmv2.2.8.gz \
 	  %{_libdir}/dpm-mysql/dpm-srmv2.2.8.gz \
+%if %systemd
+  --slave %{_unitdir}/dpm-srmv2.2.service dpm-srmv2.2.service \
+	  %{_datadir}/dpm-mysql/dpm-srmv2.2.service \
+%else
   --slave %{_initrddir}/dpm-srmv2.2 dpm-srmv2.2.init \
 	  %{_sysconfdir}/dpm-mysql/dpm-srmv2.2.init \
   --slave %{_sysconfdir}/sysconfig/dpm-srmv2.2 dpm-srmv2.2.conf \
 	  %{_sysconfdir}/dpm-mysql/dpm-srmv2.2.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpm-srmv2.2 dpm-srmv2.2.logrotate \
 	  %{_sysconfdir}/dpm-mysql/dpm-srmv2.2.logrotate
 
-if [ $1 = 1 ]; then
-    if [ -r %{_initrddir}/dpm-srmv1 ]; then
-	/sbin/chkconfig --add dpm-srmv1;
-    fi
-    if [ -r %{_initrddir}/dpm-srmv2 ]; then
-	/sbin/chkconfig --add dpm-srmv2
-    fi
-    if [ -r %{_initrddir}/dpm-srmv2.2 ]; then
-	/sbin/chkconfig --add dpm-srmv2.2
-    fi
+if [ $1 -eq 1 ]; then
+%if %systemd
+    /bin/systemctl daemon-reload > /dev/null 2>&1 || :
+%else
+    /sbin/chkconfig --add dpm-srmv1
+    /sbin/chkconfig --add dpm-srmv2
+    /sbin/chkconfig --add dpm-srmv2.2
+%endif
 fi
 
 %post -n dpm-srm-server-postgres
+%if %systemd
+# Clean up pre-systemd config
+if [ -r %{_initrddir}/dpm-srmv1 ] ; then
+    /sbin/service dpm-srmv1 stop > /dev/null 2>&1 || :
+    /sbin/chkconfig --del dpm-srmv1 > /dev/null 2>&1 || :
+fi
+if [ -r %{_initrddir}/dpm-srmv2 ] ; then
+    /sbin/service dpm-srmv2 stop > /dev/null 2>&1 || :
+    /sbin/chkconfig --del dpm-srmv2 > /dev/null 2>&1 || :
+fi
+if [ -r %{_initrddir}/dpm-srmv2.2 ] ; then
+    /sbin/service dpm-srmv2.2 stop > /dev/null 2>&1 || :
+    /sbin/chkconfig --del dpm-srmv2.2 > /dev/null 2>&1 || :
+fi
+%endif
+
 %{_sbindir}/update-alternatives --install %{_sbindir}/dpm-srmv1 dpm-srmv1 \
 	  %{_libdir}/dpm-postgres/dpm-srmv1 10 \
   --slave %{_mandir}/man8/dpm-srmv1.8.gz dpm-srmv1.8.gz \
 	  %{_libdir}/dpm-postgres/dpm-srmv1.8.gz \
+%if %systemd
+  --slave %{_unitdir}/dpm-srmv1.service dpm-srmv1.service \
+	  %{_datadir}/dpm-postgres/dpm-srmv1.service \
+%else
   --slave %{_initrddir}/dpm-srmv1 dpm-srmv1.init \
 	  %{_sysconfdir}/dpm-postgres/dpm-srmv1.init \
   --slave %{_sysconfdir}/sysconfig/dpm-srmv1 dpm-srmv1.conf \
 	  %{_sysconfdir}/dpm-postgres/dpm-srmv1.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpm-srmv1 dpm-srmv1.logrotate \
 	  %{_sysconfdir}/dpm-postgres/dpm-srmv1.logrotate
 
@@ -2430,10 +2940,15 @@ fi
 	  %{_libdir}/dpm-postgres/dpm-srmv2 10 \
   --slave %{_mandir}/man8/dpm-srmv2.8.gz dpm-srmv2.8.gz \
 	  %{_libdir}/dpm-postgres/dpm-srmv2.8.gz \
+%if %systemd
+  --slave %{_unitdir}/dpm-srmv2.service dpm-srmv2.service \
+	  %{_datadir}/dpm-postgres/dpm-srmv2.service \
+%else
   --slave %{_initrddir}/dpm-srmv2 dpm-srmv2.init \
 	  %{_sysconfdir}/dpm-postgres/dpm-srmv2.init \
   --slave %{_sysconfdir}/sysconfig/dpm-srmv2 dpm-srmv2.conf \
 	  %{_sysconfdir}/dpm-postgres/dpm-srmv2.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpm-srmv2 dpm-srmv2.logrotate \
 	  %{_sysconfdir}/dpm-postgres/dpm-srmv2.logrotate
 
@@ -2441,23 +2956,26 @@ fi
 	  %{_libdir}/dpm-postgres/dpm-srmv2.2 10 \
   --slave %{_mandir}/man8/dpm-srmv2.2.8.gz dpm-srmv2.2.8.gz \
 	  %{_libdir}/dpm-postgres/dpm-srmv2.2.8.gz \
+%if %systemd
+  --slave %{_unitdir}/dpm-srmv2.2.service dpm-srmv2.2.service \
+	  %{_datadir}/dpm-postgres/dpm-srmv2.2.service \
+%else
   --slave %{_initrddir}/dpm-srmv2.2 dpm-srmv2.2.init \
 	  %{_sysconfdir}/dpm-postgres/dpm-srmv2.2.init \
   --slave %{_sysconfdir}/sysconfig/dpm-srmv2.2 dpm-srmv2.2.conf \
 	  %{_sysconfdir}/dpm-postgres/dpm-srmv2.2.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpm-srmv2.2 dpm-srmv2.2.logrotate \
 	  %{_sysconfdir}/dpm-postgres/dpm-srmv2.2.logrotate
 
-if [ $1 = 1 ]; then
-    if [ -r %{_initrddir}/dpm-srmv1 ]; then
-	/sbin/chkconfig --add dpm-srmv1;
-    fi
-    if [ -r %{_initrddir}/dpm-srmv2 ]; then
-	/sbin/chkconfig --add dpm-srmv2
-    fi
-    if [ -r %{_initrddir}/dpm-srmv2.2 ]; then
-	/sbin/chkconfig --add dpm-srmv2.2
-    fi
+if [ $1 -eq 1 ]; then
+%if %systemd
+    /bin/systemctl daemon-reload > /dev/null 2>&1 || :
+%else
+    /sbin/chkconfig --add dpm-srmv1
+    /sbin/chkconfig --add dpm-srmv2
+    /sbin/chkconfig --add dpm-srmv2.2
+%endif
 fi
 
 %triggerpostun -n dpm-srm-server-mysql -- dpm-mysql-srmv1 < 1.8.1.2-2
@@ -2466,10 +2984,15 @@ fi
 	  %{_libdir}/dpm-mysql/dpm-srmv1 20 \
   --slave %{_mandir}/man8/dpm-srmv1.8.gz dpm-srmv1.8.gz \
 	  %{_libdir}/dpm-mysql/dpm-srmv1.8.gz \
+%if %systemd
+  --slave %{_unitdir}/dpm-srmv1.service dpm-srmv1.service \
+	  %{_datadir}/dpm-mysql/dpm-srmv1.service \
+%else
   --slave %{_initrddir}/dpm-srmv1 dpm-srmv1.init \
 	  %{_sysconfdir}/dpm-mysql/dpm-srmv1.init \
   --slave %{_sysconfdir}/sysconfig/dpm-srmv1 dpm-srmv1.conf \
 	  %{_sysconfdir}/dpm-mysql/dpm-srmv1.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpm-srmv1 dpm-srmv1.logrotate \
 	  %{_sysconfdir}/dpm-mysql/dpm-srmv1.logrotate
 
@@ -2479,10 +3002,15 @@ fi
 	  %{_libdir}/dpm-mysql/dpm-srmv2 20 \
   --slave %{_mandir}/man8/dpm-srmv2.8.gz dpm-srmv2.8.gz \
 	  %{_libdir}/dpm-mysql/dpm-srmv2.8.gz \
+%if %systemd
+  --slave %{_unitdir}/dpm-srmv2.service dpm-srmv2.service \
+	  %{_datadir}/dpm-mysql/dpm-srmv2.service \
+%else
   --slave %{_initrddir}/dpm-srmv2 dpm-srmv2.init \
 	  %{_sysconfdir}/dpm-mysql/dpm-srmv2.init \
   --slave %{_sysconfdir}/sysconfig/dpm-srmv2 dpm-srmv2.conf \
 	  %{_sysconfdir}/dpm-mysql/dpm-srmv2.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpm-srmv2 dpm-srmv2.logrotate \
 	  %{_sysconfdir}/dpm-mysql/dpm-srmv2.logrotate
 
@@ -2492,10 +3020,15 @@ fi
 	  %{_libdir}/dpm-mysql/dpm-srmv2.2 20 \
   --slave %{_mandir}/man8/dpm-srmv2.2.8.gz dpm-srmv2.2.8.gz \
 	  %{_libdir}/dpm-mysql/dpm-srmv2.2.8.gz \
+%if %systemd
+  --slave %{_unitdir}/dpm-srmv2.2.service dpm-srmv2.2.service \
+	  %{_datadir}/dpm-mysql/dpm-srmv2.2.service \
+%else
   --slave %{_initrddir}/dpm-srmv2.2 dpm-srmv2.2.init \
 	  %{_sysconfdir}/dpm-mysql/dpm-srmv2.2.init \
   --slave %{_sysconfdir}/sysconfig/dpm-srmv2.2 dpm-srmv2.2.conf \
 	  %{_sysconfdir}/dpm-mysql/dpm-srmv2.2.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpm-srmv2.2 dpm-srmv2.2.logrotate \
 	  %{_sysconfdir}/dpm-mysql/dpm-srmv2.2.logrotate
 
@@ -2505,10 +3038,15 @@ fi
 	  %{_libdir}/dpm-postgres/dpm-srmv1 10 \
   --slave %{_mandir}/man8/dpm-srmv1.8.gz dpm-srmv1.8.gz \
 	  %{_libdir}/dpm-postgres/dpm-srmv1.8.gz \
+%if %systemd
+  --slave %{_unitdir}/dpm-srmv1.service dpm-srmv1.service \
+	  %{_datadir}/dpm-postgres/dpm-srmv1.service \
+%else
   --slave %{_initrddir}/dpm-srmv1 dpm-srmv1.init \
 	  %{_sysconfdir}/dpm-postgres/dpm-srmv1.init \
   --slave %{_sysconfdir}/sysconfig/dpm-srmv1 dpm-srmv1.conf \
 	  %{_sysconfdir}/dpm-postgres/dpm-srmv1.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpm-srmv1 dpm-srmv1.logrotate \
 	  %{_sysconfdir}/dpm-postgres/dpm-srmv1.logrotate
 
@@ -2518,10 +3056,15 @@ fi
 	  %{_libdir}/dpm-postgres/dpm-srmv2 10 \
   --slave %{_mandir}/man8/dpm-srmv2.8.gz dpm-srmv2.8.gz \
 	  %{_libdir}/dpm-postgres/dpm-srmv2.8.gz \
+%if %systemd
+  --slave %{_unitdir}/dpm-srmv2.service dpm-srmv2.service \
+	  %{_datadir}/dpm-postgres/dpm-srmv2.service \
+%else
   --slave %{_initrddir}/dpm-srmv2 dpm-srmv2.init \
 	  %{_sysconfdir}/dpm-postgres/dpm-srmv2.init \
   --slave %{_sysconfdir}/sysconfig/dpm-srmv2 dpm-srmv2.conf \
 	  %{_sysconfdir}/dpm-postgres/dpm-srmv2.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpm-srmv2 dpm-srmv2.logrotate \
 	  %{_sysconfdir}/dpm-postgres/dpm-srmv2.logrotate
 
@@ -2531,119 +3074,229 @@ fi
 	  %{_libdir}/dpm-postgres/dpm-srmv2.2 10 \
   --slave %{_mandir}/man8/dpm-srmv2.2.8.gz dpm-srmv2.2.8.gz \
 	  %{_libdir}/dpm-postgres/dpm-srmv2.2.8.gz \
+%if %systemd
+  --slave %{_unitdir}/dpm-srmv2.2.service dpm-srmv2.2.service \
+	  %{_datadir}/dpm-postgres/dpm-srmv2.2.service \
+%else
   --slave %{_initrddir}/dpm-srmv2.2 dpm-srmv2.2.init \
 	  %{_sysconfdir}/dpm-postgres/dpm-srmv2.2.init \
   --slave %{_sysconfdir}/sysconfig/dpm-srmv2.2 dpm-srmv2.2.conf \
 	  %{_sysconfdir}/dpm-postgres/dpm-srmv2.2.conf \
+%endif
   --slave %{_sysconfdir}/logrotate.d/dpm-srmv2.2 dpm-srmv2.2.logrotate \
 	  %{_sysconfdir}/dpm-postgres/dpm-srmv2.2.logrotate
 
 %preun -n dpm-srm-server-mysql
 export LANG=C
 
-if [ $1 = 0 ]; then
-    %{_sbindir}/update-alternatives --display dpm-srmv1 | \
-	grep currently | grep -q dpm-mysql && \
+if [ $1 -eq 0 ]; then
+    if ( %{_sbindir}/update-alternatives --display dpm-srmv1 | \
+	grep currently | grep -q dpm-mysql ) ; then
+%if %systemd
+	/bin/systemctl --no-reload disable dpm-srmv1.service \
+	    > /dev/null 2>&1 || :
+	/bin/systemctl stop dpm-srmv1.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpm-srmv1 stop > /dev/null 2>&1 || :
+%endif
+    fi
     %{_sbindir}/update-alternatives --remove dpm-srmv1 \
 	%{_libdir}/dpm-mysql/dpm-srmv1
+%if %systemd == 0
     %{_sbindir}/update-alternatives --display dpm-srmv1 > /dev/null || \
 	/sbin/chkconfig --del dpm-srmv1 > /dev/null 2>&1 || :
+%endif
 
-    %{_sbindir}/update-alternatives --display dpm-srmv2 | \
-	grep currently | grep -q dpm-mysql && \
+    if ( %{_sbindir}/update-alternatives --display dpm-srmv2 | \
+	grep currently | grep -q dpm-mysql ) ; then
+%if %systemd
+	/bin/systemctl --no-reload disable dpm-srmv2.service \
+	    > /dev/null 2>&1 || :
+	/bin/systemctl stop dpm-srmv2.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpm-srmv2 stop > /dev/null 2>&1 || :
+%endif
+    fi
     %{_sbindir}/update-alternatives --remove dpm-srmv2 \
 	%{_libdir}/dpm-mysql/dpm-srmv2
+%if %systemd == 0
     %{_sbindir}/update-alternatives --display dpm-srmv2 > /dev/null || \
 	/sbin/chkconfig --del dpm-srmv2 > /dev/null 2>&1 || :
+%endif
 
-    %{_sbindir}/update-alternatives --display dpm-srmv2.2 | \
-	grep currently | grep -q dpm-mysql && \
+    if ( %{_sbindir}/update-alternatives --display dpm-srmv2.2 | \
+	grep currently | grep -q dpm-mysql ) ; then
+%if %systemd
+	/bin/systemctl --no-reload disable dpm-srmv2.2.service \
+	    > /dev/null 2>&1 || :
+	/bin/systemctl stop dpm-srmv2.2.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpm-srmv2.2 stop > /dev/null 2>&1 || :
+%endif
+    fi
     %{_sbindir}/update-alternatives --remove dpm-srmv2.2 \
 	%{_libdir}/dpm-mysql/dpm-srmv2.2
+%if %systemd == 0
     %{_sbindir}/update-alternatives --display dpm-srmv2.2 > /dev/null || \
 	/sbin/chkconfig --del dpm-srmv2.2 > /dev/null 2>&1 || :
+%endif
 fi
 
 %preun -n dpm-srm-server-postgres
 export LANG=C
 
-if [ $1 = 0 ]; then
-    %{_sbindir}/update-alternatives --display dpm-srmv1 | \
-	grep currently | grep -q dpm-postgres && \
+if [ $1 -eq 0 ]; then
+    if ( %{_sbindir}/update-alternatives --display dpm-srmv1 | \
+	grep currently | grep -q dpm-postgres ) ; then
+%if %systemd
+	/bin/systemctl --no-reload disable dpm-srmv1.service \
+	    > /dev/null 2>&1 || :
+	/bin/systemctl stop dpm-srmv1.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpm-srmv1 stop > /dev/null 2>&1 || :
+%endif
+    fi
     %{_sbindir}/update-alternatives --remove dpm-srmv1 \
 	%{_libdir}/dpm-postgres/dpm-srmv1
+%if %systemd == 0
     %{_sbindir}/update-alternatives --display dpm-srmv1 > /dev/null || \
 	/sbin/chkconfig --del dpm-srmv1 > /dev/null 2>&1 || :
+%endif
 
-    %{_sbindir}/update-alternatives --display dpm-srmv2 | \
-	grep currently | grep -q dpm-postgres && \
+    if ( %{_sbindir}/update-alternatives --display dpm-srmv2 | \
+	grep currently | grep -q dpm-postgres ) ; then
+%if %systemd
+	/bin/systemctl --no-reload disable dpm-srmv2.service \
+	    > /dev/null 2>&1 || :
+	/bin/systemctl stop dpm-srmv2.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpm-srmv2 stop > /dev/null 2>&1 || :
+%endif
+    fi
     %{_sbindir}/update-alternatives --remove dpm-srmv2 \
 	%{_libdir}/dpm-postgres/dpm-srmv2
+%if %systemd == 0
     %{_sbindir}/update-alternatives --display dpm-srmv2 > /dev/null || \
 	/sbin/chkconfig --del dpm-srmv2 > /dev/null 2>&1 || :
+%endif
 
-    %{_sbindir}/update-alternatives --display dpm-srmv2.2 | \
-	grep currently | grep -q dpm-postgres && \
+    if ( %{_sbindir}/update-alternatives --display dpm-srmv2.2 | \
+	grep currently | grep -q dpm-postgres ) ; then
+%if %systemd
+	/bin/systemctl --no-reload disable dpm-srmv2.2.service \
+	    > /dev/null 2>&1 || :
+	/bin/systemctl stop dpm-srmv2.2.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpm-srmv2.2 stop > /dev/null 2>&1 || :
+%endif
+    fi
     %{_sbindir}/update-alternatives --remove dpm-srmv2.2 \
 	%{_libdir}/dpm-postgres/dpm-srmv2.2
+%if %systemd == 0
     %{_sbindir}/update-alternatives --display dpm-srmv2.2 > /dev/null || \
 	/sbin/chkconfig --del dpm-srmv2.2 > /dev/null 2>&1 || :
+%endif
 fi
 
 %postun -n dpm-srm-server-mysql
 export LANG=C
 
 if [ $1 -ge 1 ]; then
-    %{_sbindir}/update-alternatives --display dpm-srmv1 | \
-	grep currently | grep -q dpm-mysql && \
+    if ( %{_sbindir}/update-alternatives --display dpm-srmv1 | \
+	grep currently | grep -q dpm-mysql ) ; then
+%if %systemd
+	/bin/systemctl try-restart dpm-srmv1.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpm-srmv1 condrestart > /dev/null 2>&1 || :
+%endif
+    fi
 
-    %{_sbindir}/update-alternatives --display dpm-srmv2 | \
-	grep currently | grep -q dpm-mysql && \
+    if ( %{_sbindir}/update-alternatives --display dpm-srmv2 | \
+	grep currently | grep -q dpm-mysql ) ; then
+%if %systemd
+	/bin/systemctl try-restart dpm-srmv2.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpm-srmv2 condrestart > /dev/null 2>&1 || :
+%endif
+    fi
 
-    %{_sbindir}/update-alternatives --display dpm-srmv2.2 | \
-	grep currently | grep -q dpm-mysql && \
+    if ( %{_sbindir}/update-alternatives --display dpm-srmv2.2 | \
+	grep currently | grep -q dpm-mysql ) ; then
+%if %systemd
+	/bin/systemctl try-restart dpm-srmv2.2.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpm-srmv2.2 condrestart > /dev/null 2>&1 || :
+%endif
+    fi
 fi
 
 %postun -n dpm-srm-server-postgres
 export LANG=C
 
 if [ $1 -ge 1 ]; then
-    %{_sbindir}/update-alternatives --display dpm-srmv1 | \
-	grep currently | grep -q dpm-postgres && \
+    if ( %{_sbindir}/update-alternatives --display dpm-srmv1 | \
+	grep currently | grep -q dpm-postgres ) ; then
+%if %systemd
+	/bin/systemctl try-restart dpm-srmv1.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpm-srmv1 condrestart > /dev/null 2>&1 || :
+%endif
+    fi
 
-    %{_sbindir}/update-alternatives --display dpm-srmv2 | \
-	grep currently | grep -q dpm-postgres && \
+    if ( %{_sbindir}/update-alternatives --display dpm-srmv2 | \
+	grep currently | grep -q dpm-postgres ) ; then
+%if %systemd
+	/bin/systemctl try-restart dpm-srmv2.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpm-srmv2 condrestart > /dev/null 2>&1 || :
+%endif
+    fi
 
-    %{_sbindir}/update-alternatives --display dpm-srmv2.2 | \
-	grep currently | grep -q dpm-postgres && \
+    if ( %{_sbindir}/update-alternatives --display dpm-srmv2.2 | \
+	grep currently | grep -q dpm-postgres ) ; then
+%if %systemd
+	/bin/systemctl try-restart dpm-srmv2.2.service > /dev/null 2>&1 || :
+%else
 	/sbin/service dpm-srmv2.2 condrestart > /dev/null 2>&1 || :
+%endif
+    fi
 fi
 
 %post -n dpm-rfio-server
-if [ $1 = 1 ]; then
+%if %systemd
+# Clean up pre-systemd config
+if [ -r %{_initrddir}/dpm-rfiod ] ; then
+    /sbin/service dpm-rfiod stop > /dev/null 2>&1 || :
+    /sbin/chkconfig --del dpm-rfiod > /dev/null 2>&1 || :
+fi
+%endif
+
+if [ $1 -eq 1 ]; then
+%if %systemd
+    /bin/systemctl daemon-reload > /dev/null 2>&1 || :
+%else
     /sbin/chkconfig --add dpm-rfiod
+%endif
 fi
 
 %preun -n dpm-rfio-server
-if [ $1 = 0 ]; then
+if [ $1 -eq 0 ]; then
+%if %systemd
+    /bin/systemctl --no-reload disable dpm-rfiod.service > /dev/null 2>&1 || :
+    /bin/systemctl stop dpm-rfiod.service > /dev/null 2>&1 || :
+%else
     /sbin/service dpm-rfiod stop > /dev/null 2>&1 || :
     /sbin/chkconfig --del dpm-rfiod
+%endif
 fi
 
 %postun -n dpm-rfio-server
 if [ $1 -ge 1 ]; then
+%if %systemd
+    /bin/systemctl try-restart dpm-rfiod.service > /dev/null 2>&1 || :
+%else
     /sbin/service dpm-rfiod condrestart > /dev/null 2>&1 || :
+%endif
 fi
 
 %files libs
@@ -2725,17 +3378,23 @@ fi
 %ghost %{_sbindir}/lfcdaemon
 %{_libdir}/lfc-mysql/lfc-shutdown
 %ghost %{_sbindir}/lfc-shutdown
-%{_libdir}/lfc-mysql/NSCONFIG.templ
+%dir %{_datadir}/lfc-mysql
+%{_datadir}/lfc-mysql/NSCONFIG.templ
 %ghost %{_datadir}/lfc/NSCONFIG.templ
 %doc %{_libdir}/lfc-mysql/lfcdaemon.8*
 %ghost %{_mandir}/man8/lfcdaemon.8*
 %doc %{_libdir}/lfc-mysql/lfc-shutdown.8*
 %ghost %{_mandir}/man8/lfc-shutdown.8*
 %dir %{_sysconfdir}/lfc-mysql
+%if %systemd
+%{_datadir}/lfc-mysql/lfcdaemon.service
+%ghost %{_unitdir}/lfcdaemon.service
+%else
 %{_sysconfdir}/lfc-mysql/lfcdaemon.init
 %ghost %{_initrddir}/lfcdaemon
 %config(noreplace) %{_sysconfdir}/lfc-mysql/lfcdaemon.conf
 %ghost %{_sysconfdir}/sysconfig/lfcdaemon
+%endif
 %config(noreplace) %{_sysconfdir}/lfc-mysql/lfcdaemon.logrotate
 %ghost %{_sysconfdir}/logrotate.d/lfcdaemon
 %dir %{_datadir}/lfc
@@ -2753,17 +3412,23 @@ fi
 %ghost %{_sbindir}/lfcdaemon
 %{_libdir}/lfc-postgres/lfc-shutdown
 %ghost %{_sbindir}/lfc-shutdown
-%{_libdir}/lfc-postgres/NSCONFIG.templ
+%dir %{_datadir}/lfc-postgres
+%{_datadir}/lfc-postgres/NSCONFIG.templ
 %ghost %{_datadir}/lfc/NSCONFIG.templ
 %doc %{_libdir}/lfc-postgres/lfcdaemon.8*
 %ghost %{_mandir}/man8/lfcdaemon.8*
 %doc %{_libdir}/lfc-postgres/lfc-shutdown.8*
 %ghost %{_mandir}/man8/lfc-shutdown.8*
 %dir %{_sysconfdir}/lfc-postgres
+%if %systemd
+%{_datadir}/lfc-postgres/lfcdaemon.service
+%ghost %{_unitdir}/lfcdaemon.service
+%else
 %{_sysconfdir}/lfc-postgres/lfcdaemon.init
 %ghost %{_initrddir}/lfcdaemon
 %config(noreplace) %{_sysconfdir}/lfc-postgres/lfcdaemon.conf
 %ghost %{_sysconfdir}/sysconfig/lfcdaemon
+%endif
 %config(noreplace) %{_sysconfdir}/lfc-postgres/lfcdaemon.logrotate
 %ghost %{_sysconfdir}/logrotate.d/lfcdaemon
 %dir %{_datadir}/lfc
@@ -2778,8 +3443,12 @@ fi
 %defattr(-,root,root,-)
 %{_sbindir}/lfc-dli
 %doc %{_mandir}/man8/lfc-dli.8*
+%if %systemd
+%{_unitdir}/lfc-dli.service
+%else
 %{_initrddir}/lfc-dli
 %config(noreplace) %{_sysconfdir}/sysconfig/lfc-dli
+%endif
 %config(noreplace) %{_sysconfdir}/logrotate.d/lfc-dli
 %dir %{_datadir}/lfc
 %{_datadir}/lfc/lcg-info-provider-lfc
@@ -2857,13 +3526,19 @@ fi
 %ghost %{_mandir}/man8/dpm-shutdown.8*
 %doc %{_libdir}/dpm-mysql/dpm-buildfsv.8*
 %ghost %{_mandir}/man8/dpm-buildfsv.8*
-%{_libdir}/dpm-mysql/DPMCONFIG.templ
+%dir %{_datadir}/dpm-mysql
+%{_datadir}/dpm-mysql/DPMCONFIG.templ
 %ghost %{_datadir}/dpm/DPMCONFIG.templ
 %dir %{_sysconfdir}/dpm-mysql
+%if %systemd
+%{_datadir}/dpm-mysql/dpm.service
+%ghost %{_unitdir}/dpm.service
+%else
 %{_sysconfdir}/dpm-mysql/dpm.init
 %ghost %{_initrddir}/dpm
 %config(noreplace) %{_sysconfdir}/dpm-mysql/dpm.conf
 %ghost %{_sysconfdir}/sysconfig/dpm
+%endif
 %config(noreplace) %{_sysconfdir}/dpm-mysql/dpm.logrotate
 %ghost %{_sysconfdir}/logrotate.d/dpm
 %dir %{_datadir}/dpm
@@ -2889,13 +3564,19 @@ fi
 %ghost %{_mandir}/man8/dpm-shutdown.8*
 %doc %{_libdir}/dpm-postgres/dpm-buildfsv.8*
 %ghost %{_mandir}/man8/dpm-buildfsv.8*
-%{_libdir}/dpm-postgres/DPMCONFIG.templ
+%dir %{_datadir}/dpm-postgres
+%{_datadir}/dpm-postgres/DPMCONFIG.templ
 %ghost %{_datadir}/dpm/DPMCONFIG.templ
 %dir %{_sysconfdir}/dpm-postgres
+%if %systemd
+%{_datadir}/dpm-postgres/dpm.service
+%ghost %{_unitdir}/dpm.service
+%else
 %{_sysconfdir}/dpm-postgres/dpm.init
 %ghost %{_initrddir}/dpm
 %config(noreplace) %{_sysconfdir}/dpm-postgres/dpm.conf
 %ghost %{_sysconfdir}/sysconfig/dpm
+%endif
 %config(noreplace) %{_sysconfdir}/dpm-postgres/dpm.logrotate
 %ghost %{_sysconfdir}/logrotate.d/dpm
 %dir %{_datadir}/dpm
@@ -2917,13 +3598,19 @@ fi
 %ghost %{_mandir}/man8/dpnsdaemon.8*
 %doc %{_libdir}/dpm-mysql/dpns-shutdown.8*
 %ghost %{_mandir}/man8/dpns-shutdown.8*
-%{_libdir}/dpm-mysql/DPNSCONFIG.templ
+%dir %{_datadir}/dpm-mysql
+%{_datadir}/dpm-mysql/DPNSCONFIG.templ
 %ghost %{_datadir}/dpm/DPNSCONFIG.templ
 %dir %{_sysconfdir}/dpm-mysql
+%if %systemd
+%{_datadir}/dpm-mysql/dpnsdaemon.service
+%ghost %{_unitdir}/dpnsdaemon.service
+%else
 %{_sysconfdir}/dpm-mysql/dpnsdaemon.init
 %ghost %{_initrddir}/dpnsdaemon
 %config(noreplace) %{_sysconfdir}/dpm-mysql/dpnsdaemon.conf
 %ghost %{_sysconfdir}/sysconfig/dpnsdaemon
+%endif
 %config(noreplace) %{_sysconfdir}/dpm-mysql/dpnsdaemon.logrotate
 %ghost %{_sysconfdir}/logrotate.d/dpnsdaemon
 %dir %{_datadir}/dpm
@@ -2945,13 +3632,19 @@ fi
 %ghost %{_mandir}/man8/dpnsdaemon.8*
 %doc %{_libdir}/dpm-postgres/dpns-shutdown.8*
 %ghost %{_mandir}/man8/dpns-shutdown.8*
-%{_libdir}/dpm-postgres/DPNSCONFIG.templ
+%dir %{_datadir}/dpm-postgres
+%{_datadir}/dpm-postgres/DPNSCONFIG.templ
 %ghost %{_datadir}/dpm/DPNSCONFIG.templ
 %dir %{_sysconfdir}/dpm-postgres
+%if %systemd
+%{_datadir}/dpm-postgres/dpnsdaemon.service
+%ghost %{_unitdir}/dpnsdaemon.service
+%else
 %{_sysconfdir}/dpm-postgres/dpnsdaemon.init
 %ghost %{_initrddir}/dpnsdaemon
 %config(noreplace) %{_sysconfdir}/dpm-postgres/dpnsdaemon.conf
 %ghost %{_sysconfdir}/sysconfig/dpnsdaemon
+%endif
 %config(noreplace) %{_sysconfdir}/dpm-postgres/dpnsdaemon.logrotate
 %ghost %{_sysconfdir}/logrotate.d/dpnsdaemon
 %dir %{_datadir}/dpm
@@ -2970,10 +3663,16 @@ fi
 %doc %{_libdir}/dpm-mysql/dpmcopyd.8*
 %ghost %{_mandir}/man8/dpmcopyd.8*
 %dir %{_sysconfdir}/dpm-mysql
+%if %systemd
+%dir %{_datadir}/dpm-mysql
+%{_datadir}/dpm-mysql/dpmcopyd.service
+%ghost %{_unitdir}/dpmcopyd.service
+%else
 %{_sysconfdir}/dpm-mysql/dpmcopyd.init
 %ghost %{_initrddir}/dpmcopyd
 %config(noreplace) %{_sysconfdir}/dpm-mysql/dpmcopyd.conf
 %ghost %{_sysconfdir}/sysconfig/dpmcopyd
+%endif
 %config(noreplace) %{_sysconfdir}/dpm-mysql/dpmcopyd.logrotate
 %ghost %{_sysconfdir}/logrotate.d/dpmcopyd
 %attr(-,dpmmgr,dpmmgr) %{_localstatedir}/log/dpmcopy
@@ -2989,10 +3688,16 @@ fi
 %doc %{_libdir}/dpm-postgres/dpmcopyd.8*
 %ghost %{_mandir}/man8/dpmcopyd.8*
 %dir %{_sysconfdir}/dpm-postgres
+%if %systemd
+%dir %{_datadir}/dpm-postgres
+%{_datadir}/dpm-postgres/dpmcopyd.service
+%ghost %{_unitdir}/dpmcopyd.service
+%else
 %{_sysconfdir}/dpm-postgres/dpmcopyd.init
 %ghost %{_initrddir}/dpmcopyd
 %config(noreplace) %{_sysconfdir}/dpm-postgres/dpmcopyd.conf
 %ghost %{_sysconfdir}/sysconfig/dpmcopyd
+%endif
 %config(noreplace) %{_sysconfdir}/dpm-postgres/dpmcopyd.logrotate
 %ghost %{_sysconfdir}/logrotate.d/dpmcopyd
 %attr(-,dpmmgr,dpmmgr) %{_localstatedir}/log/dpmcopy
@@ -3016,6 +3721,15 @@ fi
 %ghost %{_mandir}/man8/dpm-srmv2.8*
 %ghost %{_mandir}/man8/dpm-srmv2.2.8*
 %dir %{_sysconfdir}/dpm-mysql
+%if %systemd
+%dir %{_datadir}/dpm-mysql
+%{_datadir}/dpm-mysql/dpm-srmv1.service
+%{_datadir}/dpm-mysql/dpm-srmv2.service
+%{_datadir}/dpm-mysql/dpm-srmv2.2.service
+%ghost %{_unitdir}/dpm-srmv1.service
+%ghost %{_unitdir}/dpm-srmv2.service
+%ghost %{_unitdir}/dpm-srmv2.2.service
+%else
 %{_sysconfdir}/dpm-mysql/dpm-srmv1.init
 %{_sysconfdir}/dpm-mysql/dpm-srmv2.init
 %{_sysconfdir}/dpm-mysql/dpm-srmv2.2.init
@@ -3028,6 +3742,7 @@ fi
 %ghost %{_sysconfdir}/sysconfig/dpm-srmv1
 %ghost %{_sysconfdir}/sysconfig/dpm-srmv2
 %ghost %{_sysconfdir}/sysconfig/dpm-srmv2.2
+%endif
 %config(noreplace) %{_sysconfdir}/dpm-mysql/dpm-srmv1.logrotate
 %config(noreplace) %{_sysconfdir}/dpm-mysql/dpm-srmv2.logrotate
 %config(noreplace) %{_sysconfdir}/dpm-mysql/dpm-srmv2.2.logrotate
@@ -3057,6 +3772,15 @@ fi
 %ghost %{_mandir}/man8/dpm-srmv2.8*
 %ghost %{_mandir}/man8/dpm-srmv2.2.8*
 %dir %{_sysconfdir}/dpm-postgres
+%if %systemd
+%dir %{_datadir}/dpm-postgres
+%{_datadir}/dpm-postgres/dpm-srmv1.service
+%{_datadir}/dpm-postgres/dpm-srmv2.service
+%{_datadir}/dpm-postgres/dpm-srmv2.2.service
+%ghost %{_unitdir}/dpm-srmv1.service
+%ghost %{_unitdir}/dpm-srmv2.service
+%ghost %{_unitdir}/dpm-srmv2.2.service
+%else
 %{_sysconfdir}/dpm-postgres/dpm-srmv1.init
 %{_sysconfdir}/dpm-postgres/dpm-srmv2.init
 %{_sysconfdir}/dpm-postgres/dpm-srmv2.2.init
@@ -3069,6 +3793,7 @@ fi
 %ghost %{_sysconfdir}/sysconfig/dpm-srmv1
 %ghost %{_sysconfdir}/sysconfig/dpm-srmv2
 %ghost %{_sysconfdir}/sysconfig/dpm-srmv2.2
+%endif
 %config(noreplace) %{_sysconfdir}/dpm-postgres/dpm-srmv1.logrotate
 %config(noreplace) %{_sysconfdir}/dpm-postgres/dpm-srmv2.logrotate
 %config(noreplace) %{_sysconfdir}/dpm-postgres/dpm-srmv2.2.logrotate
@@ -3085,13 +3810,22 @@ fi
 %files -n dpm-rfio-server
 %defattr(-,root,root,-)
 %{_sbindir}/dpm-rfiod
+%if %systemd
+%{_unitdir}/dpm-rfiod.service
+%else
 %{_initrddir}/dpm-rfiod
 %config(noreplace) %{_sysconfdir}/sysconfig/dpm-rfiod
+%endif
 %config(noreplace) %{_sysconfdir}/logrotate.d/dpm-rfiod
 %{_localstatedir}/log/dpm-rfio
 %doc %{_mandir}/man8/dpm-rfiod.8*
 
 %changelog
+* Tue Feb 28 2012 Mattias Ellert <mattias.ellert at fysast.uu.se> - 1.8.2-3
+- Convert to systemd (Fedora 17+)
+- Rebuild for new gsoap (Fedora 17+)
+- Update obsolete sql scripts
+
 * Fri Jan 13 2012 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 1.8.2-2
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild
 
diff --git a/sources b/sources
index adca0f4..2b4828e 100644
--- a/sources
+++ b/sources
@@ -1 +1,2 @@
 f1125c6bc0edf6a6215a9f00172794eb  lcgdm-1.8.2.tar.gz
+2e8831fa908ac8a82ab47289628924d0  lcgdm-unitfiles.tar.gz


More information about the scm-commits mailing list