From 0a58b89af7fafc04285a9b3bee43cd3c02864aba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Hertzog?= <hertzog@debian.org>
Date: Tue, 20 Sep 2016 15:39:15 +0200
Subject: [PATCH 2/6] Add systemd unit files. Closes: #798430

Partly based on former work of Timo Aaltonen <tjaalton@debian.org>.
---
 debian/apache2.apache-htcacheclean.service  | 16 ++++++++++++++++
 debian/apache2.apache-htcacheclean@.service | 16 ++++++++++++++++
 debian/apache2.service                      | 14 ++++++++++++++
 debian/apache2@.service                     | 16 ++++++++++++++++
 debian/changelog                            |  4 ++++
 debian/control                              |  3 ++-
 debian/rules                                |  8 +++++++-
 7 files changed, 75 insertions(+), 2 deletions(-)
 create mode 100644 debian/apache2.apache-htcacheclean.service
 create mode 100644 debian/apache2.apache-htcacheclean@.service
 create mode 100644 debian/apache2.service
 create mode 100644 debian/apache2@.service

diff --git a/debian/apache2.apache-htcacheclean.service b/debian/apache2.apache-htcacheclean.service
new file mode 100644
index 0000000..70222f3
--- /dev/null
+++ b/debian/apache2.apache-htcacheclean.service
@@ -0,0 +1,16 @@
+[Unit]
+Description=Disk Cache Cleaning Daemon for Apache HTTP Server
+After=apache2.service
+
+[Service]
+Type=forking
+User=www-data
+Environment=HTCACHECLEAN_SIZE=300M
+Environment=HTCACHECLEAN_DAEMON_INTERVAL=120
+Environment=HTCACHECLEAN_PATH=/var/cache/apache2/mod_cache_disk
+Environment=HTCACHECLEAN_OPTIONS=-n
+EnvironmentFile=-/etc/default/apache-htcacheclean
+ExecStart=/usr/bin/htcacheclean -d $HTCACHECLEAN_DAEMON_INTERVAL -p $HTCACHECLEAN_PATH -l $HTCACHECLEAN_SIZE $HTCACHECLEAN_OPTIONS
+
+[Install]
+WantedBy=multi-user.target
diff --git a/debian/apache2.apache-htcacheclean@.service b/debian/apache2.apache-htcacheclean@.service
new file mode 100644
index 0000000..1ec2f62
--- /dev/null
+++ b/debian/apache2.apache-htcacheclean@.service
@@ -0,0 +1,16 @@
+[Unit]
+Description=Disk Cache Cleaning Daemon for Apache HTTP Server
+After=apache2@%i.service
+
+[Service]
+Type=forking
+User=www-data
+Environment=HTCACHECLEAN_SIZE=300M
+Environment=HTCACHECLEAN_DAEMON_INTERVAL=120
+Environment=HTCACHECLEAN_PATH=/var/cache/apache2-%I/mod_cache_disk
+Environment=HTCACHECLEAN_OPTIONS=-n
+EnvironmentFile=-/etc/default/apache-htcacheclean-%I
+ExecStart=/usr/bin/htcacheclean -d $HTCACHECLEAN_DAEMON_INTERVAL -p $HTCACHECLEAN_PATH -l $HTCACHECLEAN_SIZE $HTCACHECLEAN_OPTIONS
+
+[Install]
+WantedBy=multi-user.target
diff --git a/debian/apache2.service b/debian/apache2.service
new file mode 100644
index 0000000..92a371a
--- /dev/null
+++ b/debian/apache2.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=The Apache HTTP Server
+After=network.target remote-fs.target nss-lookup.target
+
+[Service]
+Type=forking
+ExecStart=/usr/sbin/apachectl start
+ExecStop=/usr/sbin/apachectl stop
+ExecReload=/usr/sbin/apachectl graceful
+PrivateTmp=true
+Restart=on-abort
+
+[Install]
+WantedBy=multi-user.target
diff --git a/debian/apache2@.service b/debian/apache2@.service
new file mode 100644
index 0000000..c072050
--- /dev/null
+++ b/debian/apache2@.service
@@ -0,0 +1,16 @@
+[Unit]
+Description=The Apache HTTP Server
+After=network.target remote-fs.target nss-lookup.target
+ConditionPathIsDirectory=/etc/apache2-%I
+
+[Service]
+Type=forking
+Environment=APACHE_CONFDIR=/etc/apache2-%I
+ExecStart=/usr/sbin/apachectl start
+ExecStop=/usr/sbin/apachectl stop
+ExecReload=/usr/sbin/apachectl graceful
+PrivateTmp=true
+Restart=on-abort
+
+[Install]
+WantedBy=multi-user.target
diff --git a/debian/changelog b/debian/changelog
index 861d285..4eef0f3 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,8 +1,12 @@
 apache2 (2.4.23-5) UNRELEASED; urgency=medium
 
+  [ Stefan Fritsch ]
   * Tweak creation of .tar.gz embedded in preinst to get reproducible
     build.
 
+  [ Raphaël Hertzog ]
+  * Add systemd unit files. Closes: #798430
+
  -- Stefan Fritsch <sf@debian.org>  Sat, 13 Aug 2016 13:38:30 +0200
 
 apache2 (2.4.23-4) unstable; urgency=medium
diff --git a/debian/control b/debian/control
index 151d462..9bc98a1 100644
--- a/debian/control
+++ b/debian/control
@@ -6,7 +6,8 @@ Uploaders: Stefan Fritsch <sf@debian.org>, Arno Töll <arno@debian.org>
 Build-Depends: debhelper (>= 9.20131213~), lsb-release, dpkg-dev (>= 1.16.1~),
  libaprutil1-dev (>= 1.5.0), libapr1-dev (>= 1.5.0), libpcre3-dev, zlib1g-dev,
  libnghttp2-dev, libssl-dev (>= 0.9.8m), perl,
- liblua5.2-dev, libxml2-dev, autotools-dev, gawk | awk
+ liblua5.2-dev, libxml2-dev, autotools-dev, gawk | awk,
+ dh-systemd
 Build-Conflicts: autoconf2.13
 Standards-Version: 3.9.8
 Vcs-Browser: https://anonscm.debian.org/cgit/pkg-apache/apache2.git/
diff --git a/debian/rules b/debian/rules
index 0202f75..00dff14 100755
--- a/debian/rules
+++ b/debian/rules
@@ -96,7 +96,7 @@ generate-maintainer-scripts: debian/apache2.preinst
 	done
 
 clean build build-arch build-indep binary binary-arch binary-indep: %:
-	dh $@ --parallel --with autotools_dev
+	dh $@ --parallel --with autotools_dev,systemd
 
 override_dh_auto_configure: generate-maintainer-scripts prebuild-checks support/suexec-custom.c
 	./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
@@ -150,6 +150,12 @@ override_dh_installinit:
 	dh_installinit --error-handler=true
 	dh_installinit --name apache-htcacheclean --noscripts
 
+override_dh_systemd_enable:
+	dh_systemd_enable -papache2 apache2.service
+	dh_systemd_enable -papache2 --name=apache2@ apache2@.service
+	dh_systemd_enable -papache2 --no-enable --name=apache-htcacheclean apache-htcacheclean.service
+	dh_systemd_enable -papache2 --no-enable --name=apache-htcacheclean@ apache-htcacheclean@.service
+
 override_dh_installdocs-indep:
 	# TODO: So, did anyone check convert_docs needs an update? ;)
 	perl debian/convert_docs debian/apache2-doc/usr/share/doc/apache2-doc/manual
-- 
2.9.3

