Control: tag -1 + patch

Hello Scott and Lamont,

please find attached 3 patches to apply on top of the stable/v3.1 branch
of your git packaging repository. It adds systemd service files for
postfix. I'm using the resulting package on my laptop so the result
has been tested.

I wanted to double check I broke nothing with autopkgtest, unfortunately
the tests are currently broken (even before those changes I mean):
https://ci.debian.net/packages/p/postfix/

I believe the integration is really clean with systemd generators for
the full multi-instance support and I hope you can merge this work
soonish and upload it to unstable.

If you don't have the time right now, let me know if you want me to upload
this NMU.

BTW, I was a bit astonished to see that postfix was not using "dh", and
that you handle many things manually while there are dh_* helper tools for
them. Also you have plenty of lintian warnings that are very easy to fix
and that would clean up the packaging (like many maintainer scripts that
are not doing anything useful). A little bit of modernization of the
packaging would not hurt IMO.

Cheers,
-- 
Raphaël Hertzog ◈ Debian Developer

Support Debian LTS: http://www.freexian.com/services/debian-lts.html
Learn to master Debian: http://debian-handbook.info/get/
>From 93b127751987de746c60beefb22ad3711f6bd8c5 Mon Sep 17 00:00:00 2001
From: Sophie Brun <[email protected]>
Date: Mon, 20 Jun 2016 10:53:20 +0200
Subject: [PATCH 1/3] Use "service postfix" instead of "/etc/init.d/postfix"
 everywhere

---
 debian/ip-down.d             |  2 +-
 debian/ip-up.d               |  2 +-
 debian/postfix.postinst      |  2 +-
 debian/templates             |  2 +-
 debian/tests/postfix         |  2 +-
 debian/tests/test-postfix.py | 12 ++++++------
 debian/update-libc.d         |  4 ++--
 7 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/debian/ip-down.d b/debian/ip-down.d
index 71bc70f..07913aa 100644
--- a/debian/ip-down.d
+++ b/debian/ip-down.d
@@ -27,7 +27,7 @@ if [ ! -x /sbin/resolvconf ]; then
 		exit 0
 	fi
 	if [ -n "$RUNNING" ]; then
-		/etc/init.d/postfix reload >/dev/null 2>&1
+		service postfix reload >/dev/null 2>&1
 	fi
 fi
 
diff --git a/debian/ip-up.d b/debian/ip-up.d
index bae9b6f..f91f518 100644
--- a/debian/ip-up.d
+++ b/debian/ip-up.d
@@ -30,7 +30,7 @@ if [ ! -x /sbin/resolvconf ]; then
 		exit 0
 	fi
 	if [ -n "$RUNNING" ]; then
-		/etc/init.d/postfix reload >/dev/null 2>&1
+		service postfix reload >/dev/null 2>&1
 	fi
 fi
 
diff --git a/debian/postfix.postinst b/debian/postfix.postinst
index 36001f1..fa53f9d 100644
--- a/debian/postfix.postinst
+++ b/debian/postfix.postinst
@@ -576,7 +576,7 @@ Postfix $MSG.  If you need to make changes, edit
 /etc/postfix/main.cf (and others) as needed.  To view Postfix configuration
 values, see postconf(1).
 
-After modifying main.cf, be sure to run '/etc/init.d/postfix reload'.
+After modifying main.cf, be sure to run 'service postfix reload'.
 
 EOF
 
diff --git a/debian/templates b/debian/templates
index 7edcfea..637d1c1 100644
--- a/debian/templates
+++ b/debian/templates
@@ -124,7 +124,7 @@ _Description: Postfix not configured
  will not be started by default. Please run 'dpkg-reconfigure postfix' at
  a later date, or configure it yourself by:
   - Editing /etc/postfix/main.cf to your liking;
-  - Running '/etc/init.d/postfix start'.
+  - Running 'service postfix start'.
 
 Template: postfix/mailname
 Type: string
diff --git a/debian/tests/postfix b/debian/tests/postfix
index e625f28..22dd0c0 100644
--- a/debian/tests/postfix
+++ b/debian/tests/postfix
@@ -12,5 +12,5 @@ debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Si
 hostname localhost
 apt-get install -y postfix 2>&1
 hostname --fqdn > /etc/mailname
-/etc/init.d/postfix restart 2>&1
+service postfix restart 2>&1
 python `dirname $0`/test-postfix.py 2>&1
diff --git a/debian/tests/test-postfix.py b/debian/tests/test-postfix.py
index 5b9ae42..779dd0e 100644
--- a/debian/tests/test-postfix.py
+++ b/debian/tests/test-postfix.py
@@ -94,8 +94,8 @@ class PostfixTest(testlib.TestlibCase):
             elif os.path.exists(f):
                 testlib.recursive_rm(f)
         subprocess.call(['mkdir','-p','/var/run/saslauthd'])
-        subprocess.call(['/etc/init.d/saslauthd', 'stop'], stdout=subprocess.PIPE)
-        subprocess.call(['/etc/init.d/saslauthd', 'start'], stdout=subprocess.PIPE)
+        subprocess.call(['/usr/sbin/service', 'saslauthd', 'stop'], stdout=subprocess.PIPE)
+        subprocess.call(['/usr/sbin/service', 'saslauthd', 'start'], stdout=subprocess.PIPE)
 
     def tearDown(self):
         '''Clean up after each test_* function'''
@@ -108,8 +108,8 @@ class PostfixTest(testlib.TestlibCase):
 
     def _restart_server(self):
         '''Restart server'''
-        subprocess.call(['/etc/init.d/postfix', 'stop'], stdout=subprocess.PIPE)
-        assert subprocess.call(['/etc/init.d/postfix', 'start'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) == 0
+        subprocess.call(['/usr/sbin/service', 'postfix', 'stop'], stdout=subprocess.PIPE)
+        assert subprocess.call(['/usr/sbin/service', 'postfix', 'start'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) == 0
         # Postfix exits its init script before the master listener has started
         time.sleep(2)
 
@@ -144,8 +144,8 @@ mech_list: %s %s
             subprocess.call(['mkdir','-p','/var/spool/postfix/var/run/saslauthd'])
             subprocess.call(['rm','-rf','/var/run/saslauthd'])
             subprocess.call(['ln','-s','/var/spool/postfix/var/run/saslauthd','/var/run/saslauthd'])
-            subprocess.call(['/etc/init.d/saslauthd', 'stop'], stdout=subprocess.PIPE)
-            assert subprocess.call(['/etc/init.d/saslauthd', 'start'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) == 0
+            subprocess.call(['/usr/sbin/service', 'saslauthd', 'stop'], stdout=subprocess.PIPE)
+            assert subprocess.call(['/usr/sbin/service', 'saslauthd', 'start'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) == 0
 
             # Force crackful perms so chroot'd postfix can talk to saslauthd
             subprocess.call(['chmod','o+x','/var/spool/postfix/var/run/saslauthd'])
diff --git a/debian/update-libc.d b/debian/update-libc.d
index 738d82b..44faba0 100644
--- a/debian/update-libc.d
+++ b/debian/update-libc.d
@@ -2,12 +2,12 @@
 
 # we only need to copy this in if the service is already running.
 # if it's not running, it'll get picked up by the init script on start.
-/etc/init.d/postfix status >/dev/null 2>&1 || exit 0
+service postfix status >/dev/null 2>&1 || exit 0
 
 QUEUEDIR="$(/usr/sbin/postconf -h queue_directory 2>/dev/null || true)"
 if [ -n "$QUEUEDIR" ]; then
     cp /etc/resolv.conf ${QUEUEDIR}/etc/resolv.conf
-    /etc/init.d/postfix reload >/dev/null 2>&1 || exit 0
+    service postfix reload >/dev/null 2>&1 || exit 0
 fi
 
 exit 0
-- 
2.8.1

>From 2b21f824d5c939c45d143626773384ca08b4597b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Hertzog?= <[email protected]>
Date: Mon, 20 Jun 2016 11:02:32 +0200
Subject: [PATCH 2/3] Move instance configuration out of the SystemV init
 script

That way we will be able to reuse it for the systemd service unit.
---
 debian/configure-instance.sh | 141 +++++++++++++++++++++++++++++++++++++++++++
 debian/init.d                | 138 +-----------------------------------------
 debian/rules                 |   1 +
 3 files changed, 143 insertions(+), 137 deletions(-)
 create mode 100755 debian/configure-instance.sh

diff --git a/debian/configure-instance.sh b/debian/configure-instance.sh
new file mode 100755
index 0000000..579ea1f
--- /dev/null
+++ b/debian/configure-instance.sh
@@ -0,0 +1,141 @@
+#! /bin/sh -e
+
+# This helper script is used by the postfix init scripts,
+# upstart jobs, systemd services, openrc scripts, etc. in
+# prepping the instance of postfix to be started.
+
+# It was originally part of the postfix init script, which
+# was written by LaMont Jones <[email protected]>, and based
+# off of the sendmail init script.
+
+INSTANCE="$1"
+
+SYNC_CHROOT="y"
+
+if test -r /etc/default/postfix; then
+	. /etc/default/postfix
+fi
+
+if [ "X$INSTANCE" = X ]; then
+	POSTCONF="postconf"
+else
+	POSTCONF="postmulti -i $INSTANCE -x postconf"
+fi
+
+# if you set myorigin to 'ubuntu.com' or 'debian.org', it's wrong, and annoys the admins of
+# those domains.  See also sender_canonical_maps.
+
+MYORIGIN=$($POSTCONF -h myorigin | tr 'A-Z' 'a-z')
+if [ "X${MYORIGIN#/}" != "X${MYORIGIN}" ]; then
+	MYORIGIN=$(tr 'A-Z' 'a-z' < $MYORIGIN)
+fi
+if [ "X$MYORIGIN" = Xubuntu.com ] || [ "X$MYORIGIN" = Xdebian.org ]; then
+	echo "Invalid \$myorigin ($MYORIGIN), refusing to start"
+	exit 1
+fi
+
+config_dir=$($POSTCONF -h config_directory)
+# see if anything is running chrooted.
+NEED_CHROOT=$(awk '/^[0-9a-z]/ && ($5 ~ "[-yY]") { print "y"; exit}' ${config_dir}/master.cf)
+
+if [ -n "$NEED_CHROOT" ] && [ -n "$SYNC_CHROOT" ]; then
+	# Make sure that the chroot environment is set up correctly.
+	umask 022
+	queue_dir=$($POSTCONF -h queue_directory)
+	cd "$queue_dir"
+
+	# copy the CA path if specified
+	ca_path=$($POSTCONF -h smtp_tls_CApath)
+	case "$ca_path" in
+	    '') :;; # no ca_path
+	    $queue_dir/*) :;;  # skip stuff already in chroot
+	    *)
+		if test -d "$ca_path"; then
+		    dest_dir="$queue_dir/${ca_path#/}"
+		    # strip any/all trailing /
+		    while [ "${dest_dir%/}" != "${dest_dir}" ]; do
+			dest_dir="${dest_dir%/}"
+		    done
+		    new=0
+		    if test -d "$dest_dir"; then
+			# write to a new directory ...
+			dest_dir="${dest_dir}.NEW"
+			new=1
+		    fi
+		    mkdir --parent ${dest_dir}
+		    # handle files in subdirectories
+		    (cd "$ca_path" && find . -name '*.pem' -print0 | cpio -0pdL --quiet "$dest_dir") 2>/dev/null || 
+		        (echo failure copying certificates; exit 1)
+		    c_rehash "$dest_dir" >/dev/null 2>&1
+		    if [ "$new" = 1 ]; then
+			# and replace the old directory
+			rm -rf "${dest_dir%.NEW}"
+			mv "$dest_dir" "${dest_dir%.NEW}"
+		    fi
+		fi
+		;;
+	esac
+
+	# if there is a CA file, copy it
+	ca_file=$($POSTCONF -h smtp_tls_CAfile)
+	case "$ca_file" in
+	    $queue_dir/*) :;;  # skip stuff already in chroot
+	    '') # no ca_file
+		# or copy the bundle to preserve functionality
+		ca_bundle=/etc/ssl/certs/ca-certificates.crt
+		if [ -f $ca_bundle ]; then
+		    mkdir --parent "$queue_dir/${ca_bundle%/*}"
+		    cp -L "$ca_bundle" "$queue_dir/${ca_bundle%/*}"
+		fi
+		;;
+	    *)
+		if test -f "$ca_file"; then
+		    dest_file="$queue_dir/${ca_file#/}"
+		    if [ -d "${dest_file}" ]; then
+			# There was a bug where we created the dest_file as a
+			# directory.  Address that by removing it with
+			# prejudice.  Debian bug #815906
+			rm -rf "${dest_file}"
+		    fi
+		    dest_dir="${dest_file%/*}"
+		    mkdir --parent "$dest_dir"
+		    cp -L "$ca_file" "$dest_dir"
+		fi
+		;;
+	esac
+
+	# if we're using unix:passwd.byname, then we need to add etc/passwd.
+	local_maps=$($POSTCONF -h local_recipient_maps)
+	if [ "X$local_maps" != "X${local_maps#*unix:passwd.byname}" ]; then
+	    if [ "X$local_maps" = "X${local_maps#*proxy:unix:passwd.byname}" ]; then
+		sed 's/^\([^:]*\):[^:]*/\1:x/' /etc/passwd > etc/passwd
+		chmod a+r etc/passwd
+	    fi
+	fi
+
+	FILES="etc/localtime etc/services etc/resolv.conf etc/hosts \
+	    etc/host.conf etc/nsswitch.conf etc/nss_mdns.config"
+	for file in $FILES; do
+	    [ -d ${file%/*} ] || mkdir -p ${file%/*}
+	    if [ -f /${file} ]; then rm -f ${file} && cp /${file} ${file}; fi
+	    if [ -f  ${file} ]; then chmod a+rX ${file}; fi
+	done
+	# ldaps needs this. debian bug 572841
+	(echo /dev/random; echo /dev/urandom) | cpio -pdL --quiet . 2>/dev/null || true
+	rm -f usr/lib/zoneinfo/localtime
+	mkdir -p usr/lib/zoneinfo
+	ln -sf /etc/localtime usr/lib/zoneinfo/localtime
+
+	LIBLIST=$(for name in gcc_s nss resolv; do
+	    for f in /lib/*/lib${name}*.so* /lib/lib${name}*.so*; do
+	       if [ -f "$f" ]; then  echo ${f#/}; fi;
+	    done;
+	done)
+
+	if [ -n "$LIBLIST" ]; then
+	    for f in $LIBLIST; do
+		rm -f "$f"
+	    done
+	    tar cf - -C / $LIBLIST 2>/dev/null |tar xf -
+	fi
+fi
diff --git a/debian/init.d b/debian/init.d
index 0c4d02a..8273f4b 100644
--- a/debian/init.d
+++ b/debian/init.d
@@ -23,11 +23,6 @@ NAME=Postfix
 TZ=
 unset TZ
 
-# Defaults - don't touch, edit /etc/default/postfix
-SYNC_CHROOT="y"
-
-test -f /etc/default/postfix && . /etc/default/postfix
-
 test -x $DAEMON && test -f /etc/postfix/main.cf || exit 0
 
 . /lib/lsb/init-functions
@@ -57,137 +52,6 @@ running() {
     fi
 }
 
-configure_instance() {
-    INSTANCE="$1"
-    if [ "X$INSTANCE" = X ]; then
-	    POSTCONF="postconf"
-    else
-	    POSTCONF="postmulti -i $INSTANCE -x postconf"
-    fi
-
-
-    # if you set myorigin to 'ubuntu.com' or 'debian.org', it's wrong, and annoys the admins of
-    # those domains.  See also sender_canonical_maps.
-
-    MYORIGIN=$($POSTCONF -h myorigin | tr 'A-Z' 'a-z')
-    if [ "X${MYORIGIN#/}" != "X${MYORIGIN}" ]; then
-	MYORIGIN=$(tr 'A-Z' 'a-z' < $MYORIGIN)
-    fi
-    if [ "X$MYORIGIN" = Xubuntu.com ] || [ "X$MYORIGIN" = Xdebian.org ]; then
-	log_failure_msg "Invalid \$myorigin ($MYORIGIN), refusing to start"
-	log_end_msg 1
-	exit 1
-    fi
-
-    config_dir=$($POSTCONF -h config_directory)
-    # see if anything is running chrooted.
-    NEED_CHROOT=$(awk '/^[0-9a-z]/ && ($5 ~ "[-yY]") { print "y"; exit}' ${config_dir}/master.cf)
-
-    if [ -n "$NEED_CHROOT" ] && [ -n "$SYNC_CHROOT" ]; then
-	# Make sure that the chroot environment is set up correctly.
-	oldumask=$(umask)
-	umask 022
-	queue_dir=$($POSTCONF -h queue_directory)
-	cd "$queue_dir"
-
-	# copy the CA path if specified
-	ca_path=$($POSTCONF -h smtp_tls_CApath)
-	case "$ca_path" in
-	    '') :;; # no ca_path
-	    $queue_dir/*) :;;  # skip stuff already in chroot, (and to make vim syntax happy: */)
-	    *)
-		if test -d "$ca_path"; then
-		    dest_dir="$queue_dir/${ca_path#/}"
-		    # strip any/all trailing /
-		    while [ "${dest_dir%/}" != "${dest_dir}" ]; do
-			dest_dir="${dest_dir%/}"
-		    done
-		    new=0
-		    if test -d "$dest_dir"; then
-			# write to a new directory ...
-			dest_dir="${dest_dir}.NEW"
-			new=1
-		    fi
-		    mkdir --parent ${dest_dir}
-		    # handle files in subdirectories
-		    (cd "$ca_path" && find . -name '*.pem' -print0 | cpio -0pdL --quiet "$dest_dir") 2>/dev/null || 
-		        (log_failure_msg failure copying certificates; exit 1)
-		    c_rehash "$dest_dir" >/dev/null 2>&1
-		    if [ "$new" = 1 ]; then
-			# and replace the old directory
-			rm -rf "${dest_dir%.NEW}"
-			mv "$dest_dir" "${dest_dir%.NEW}"
-		    fi
-		fi
-		;;
-	esac
-
-	# if there is a CA file, copy it
-	ca_file=$($POSTCONF -h smtp_tls_CAfile)
-	case "$ca_file" in
-	    $queue_dir/*) :;;  # skip stuff already in chroot
-	    '') # no ca_file
-		# or copy the bundle to preserve functionality
-		ca_bundle=/etc/ssl/certs/ca-certificates.crt
-		if [ -f $ca_bundle ]; then
-		    mkdir --parent "$queue_dir/${ca_bundle%/*}"
-		    cp -L "$ca_bundle" "$queue_dir/${ca_bundle%/*}"
-		fi
-		;;
-	    *)
-		if test -f "$ca_file"; then
-		    dest_file="$queue_dir/${ca_file#/}"
-                    if [ -d "${dest_file}" ]; then
-                        # There was a bug where we created the dest_file as a
-                        # directory.  Address that by removing it with
-                        # prejudice.  Debian bug #815906
-                        rm -rf "${dest_file}"
-                    fi
-                    dest_dir="${dest_file%/*}"
-		    mkdir --parent "$dest_dir"
-		    cp -L "$ca_file" "$dest_dir"
-		fi
-		;;
-	esac
-
-	# if we're using unix:passwd.byname, then we need to add etc/passwd.
-	local_maps=$($POSTCONF -h local_recipient_maps)
-	if [ "X$local_maps" != "X${local_maps#*unix:passwd.byname}" ]; then
-	    if [ "X$local_maps" = "X${local_maps#*proxy:unix:passwd.byname}" ]; then
-		sed 's/^\([^:]*\):[^:]*/\1:x/' /etc/passwd > etc/passwd
-		chmod a+r etc/passwd
-	    fi
-	fi
-
-	FILES="etc/localtime etc/services etc/resolv.conf etc/hosts \
-	    etc/host.conf etc/nsswitch.conf etc/nss_mdns.config"
-	for file in $FILES; do
-	    [ -d ${file%/*} ] || mkdir -p ${file%/*}
-	    if [ -f /${file} ]; then rm -f ${file} && cp /${file} ${file}; fi
-	    if [ -f  ${file} ]; then chmod a+rX ${file}; fi
-	done
-	# ldaps needs this. debian bug 572841
-	(echo /dev/random; echo /dev/urandom) | cpio -pdL --quiet . 2>/dev/null || true
-	rm -f usr/lib/zoneinfo/localtime
-	mkdir -p usr/lib/zoneinfo
-	ln -sf /etc/localtime usr/lib/zoneinfo/localtime
-
-	LIBLIST=$(for name in gcc_s nss resolv; do
-	    for f in /lib/*/lib${name}*.so* /lib/lib${name}*.so*; do
-	       if [ -f "$f" ]; then  echo ${f#/}; fi;
-	    done;
-	done)
-
-	if [ -n "$LIBLIST" ]; then
-	    for f in $LIBLIST; do
-		rm -f "$f"
-	    done
-	    tar cf - -C / $LIBLIST 2>/dev/null |tar xf -
-	fi
-	umask $oldumask
-    fi
-}
-
 case "$1" in
     start)
 	log_daemon_msg "Starting Postfix Mail Transport Agent" postfix
@@ -196,7 +60,7 @@ case "$1" in
 	for INSTANCE in $(enabled_instances); do
 	    RUNNING=$(running $INSTANCE)
 	    if [ "X$RUNNING" = X ]; then
-		configure_instance $INSTANCE
+		/usr/lib/postfix/configure-instance.sh $INSTANCE
 		CMD="/usr/sbin/postmulti -- -i $INSTANCE -x ${DAEMON}"
 		if ! start-stop-daemon --start --exec $CMD quiet-quick-start; then
 		    RET=1
diff --git a/debian/rules b/debian/rules
index c02c7af..0c814e9 100755
--- a/debian/rules
+++ b/debian/rules
@@ -164,6 +164,7 @@ install: build
 	ln -sf bounce.8postfix.gz ${base}/usr/share/man/man8/defer.8postfix.gz
 
 	install debian/init.d ${base}/etc/init.d/postfix
+	install debian/configure-instance.sh $(libdir)
 	install debian/ip-up.d ${base}/etc/ppp/ip-up.d/postfix
 	install debian/ip-down.d ${base}/etc/ppp/ip-down.d/postfix
 	install debian/ip-up.d ${base}/etc/network/if-up.d/postfix
-- 
2.8.1

>From f305c93b26d559d6340a8eaf27aebd73000ab51b Mon Sep 17 00:00:00 2001
From: Sophie Brun <[email protected]>
Date: Mon, 20 Jun 2016 11:12:06 +0200
Subject: [PATCH 3/3] Add systemd service files
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The postfix.service is an empty service file whose only purpose is
to manage all instances at once. Each instance has
[email protected] file which is created dynamically
by the systemd generator that we install. The [email protected]
relies on the newly created configure-instance.sh script
to have the same behaviour than the corresponding init script.

We now use dh_installinit to install the init script
and dh_systemd_{enable,start} to manage the system service files.
This requires getting rid of some manual code in maintainer scripts.

Addresses-Debian-Bug: 715188, 755960
Signed-off-by: Raphaël Hertzog <[email protected]>
---
 debian/changelog                  | 17 +++++++++++++++++
 debian/control                    |  2 +-
 debian/postfix-instance-generator | 14 ++++++++++++++
 debian/postfix.dirs               |  2 ++
 debian/postfix.postinst           |  2 --
 debian/postfix.postrm             |  1 -
 debian/postfix.prerm              |  4 ----
 debian/postfix.service            | 14 ++++++++++++++
 debian/[email protected]           | 15 +++++++++++++++
 debian/rules                      |  6 +++++-
 10 files changed, 68 insertions(+), 9 deletions(-)
 create mode 100755 debian/postfix-instance-generator
 create mode 100644 debian/postfix.service
 create mode 100644 debian/[email protected]

diff --git a/debian/changelog b/debian/changelog
index 28d6714..5bf7505 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,20 @@
+postfix (3.1.0-3.1) unstable; urgency=medium
+
+  * Non-maintainer upload.
+  * Add systemd integration (Closes: #715188, #755960)
+    Thanks to Cameron Norman and Shawn Landden for the initial work.
+    The final design looks like this:
+    - postfix.service is an empty service file which lets you manage
+      all instances together.
+    - each instance is controlled by a [email protected] file
+    - postfix@instance services are brought into life by a new
+      systemd generator (postfix-instance-generator)
+    - the usage of "postmulti -p start/stop/reload" in [email protected]
+      ensures that the service is not started if disabled at the
+      postmulti level
+
+ -- Sophie Brun <[email protected]>  Wed, 15 Jun 2016 09:28:11 +0200
+
 postfix (3.1.0-3) unstable; urgency=medium
 
   * By default, include $myhostname into $mydestinations.
diff --git a/debian/control b/debian/control
index 1aea162..593c2c6 100644
--- a/debian/control
+++ b/debian/control
@@ -4,7 +4,7 @@ Priority: extra
 Maintainer: LaMont Jones <[email protected]>
 Standards-Version: 3.9.1.0
 Homepage: http://www.postfix.org
-Build-Depends: debhelper (>= 7), po-debconf (>= 0.5.0), groff-base, patch, lsb-release, libdb-dev (>=4.6.19), libldap2-dev (>=2.1), libpcre3-dev, libmysqlclient-dev, libssl-dev (>=0.9.7), libsasl2-dev, libpq-dev, libcdb-dev, dpkg-dev (>= 1.16.1~), libsqlite3-dev, html2text, libicu-dev
+Build-Depends: debhelper (>= 7), po-debconf (>= 0.5.0), groff-base, patch, lsb-release, libdb-dev (>=4.6.19), libldap2-dev (>=2.1), libpcre3-dev, libmysqlclient-dev, libssl-dev (>=0.9.7), libsasl2-dev, libpq-dev, libcdb-dev, dpkg-dev (>= 1.16.1~), libsqlite3-dev, html2text, libicu-dev, dh-systemd
 Vcs-Browser: https://git.launchpad.net/postfix
 Vcs-Git: git://git.launchpad.net/postfix
 Uploaders: Scott Kitterman <[email protected]>
diff --git a/debian/postfix-instance-generator b/debian/postfix-instance-generator
new file mode 100755
index 0000000..d02ea72
--- /dev/null
+++ b/debian/postfix-instance-generator
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+set -e
+
+WANTDIR="$1/postfix.service.wants"
+SERVICEFILE="/lib/systemd/system/[email protected]"
+
+mkdir -p "$WANTDIR"
+
+for NAME in $(postmulti -l -a | awk '{ print $1}'); do
+    ln -s "$SERVICEFILE" "$WANTDIR/postfix@$NAME.service"
+done
+
+exit 0
diff --git a/debian/postfix.dirs b/debian/postfix.dirs
index 9e0a90b..2811065 100644
--- a/debian/postfix.dirs
+++ b/debian/postfix.dirs
@@ -30,3 +30,5 @@ var/spool/postfix/usr/lib/zoneinfo
 var/spool/postfix/usr/lib/sasl2
 var/log
 var/lib/postfix
+lib/systemd/system
+lib/systemd/system-generators
diff --git a/debian/postfix.postinst b/debian/postfix.postinst
index fa53f9d..ce4bf29 100644
--- a/debian/postfix.postinst
+++ b/debian/postfix.postinst
@@ -189,8 +189,6 @@ esac
 CHANGES=""
 NEWALIASES="y"
 
-update-rc.d postfix defaults > /dev/null
-
 ldconfig
 
 dpkg-divert --package postfix --remove --rename \
diff --git a/debian/postfix.postrm b/debian/postfix.postrm
index a471945..aaec005 100644
--- a/debian/postfix.postrm
+++ b/debian/postfix.postrm
@@ -19,7 +19,6 @@ case "$1" in
 	rm -rf /var/spool/postfix
 	rm -rf /var/lib/postfix
 	rm -rf /etc/postfix
-	update-rc.d postfix remove >/dev/null
 	userdel postfix >/dev/null 2>&1 || true
 	groupdel postdrop >/dev/null 2>&1 || true
 	groupdel postfix >/dev/null 2>&1 || true
diff --git a/debian/postfix.prerm b/debian/postfix.prerm
index e1a28cf..146ecdb 100644
--- a/debian/postfix.prerm
+++ b/debian/postfix.prerm
@@ -6,10 +6,6 @@
 case "$1" in
     upgrade)
 	new=$2			# get new version
-	[ -x /usr/sbin/invoke-rc.d ] && \
-		INIT="invoke-rc.d postfix" || \
-		INIT="/etc/init.d/postfix"
-	${INIT} stop
 	if dpkg --compare-versions $new lt 0.0.20020113.SNAPSHOT-1; then
 	    # Need to handle some changes in services.
 	    MASTER=/etc/postfix/master.cf
diff --git a/debian/postfix.service b/debian/postfix.service
new file mode 100644
index 0000000..8e8f5f0
--- /dev/null
+++ b/debian/postfix.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=Postfix Mail Transport Agent
+After=network.target
+Conflicts=sendmail.service exim4.service
+ConditionPathExists=/etc/postfix/main.cf
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=/bin/true
+ExecReload=/bin/true
+
+[Install]
+WantedBy=multi-user.target
diff --git a/debian/[email protected] b/debian/[email protected]
new file mode 100644
index 0000000..2b31468
--- /dev/null
+++ b/debian/[email protected]
@@ -0,0 +1,15 @@
+[Unit]
+Description=Postfix Mail Transport Agent (instance %i)
+Documentation=man:postfix(1)
+PartOf=postfix.service
+
+[Service]
+Type=forking
+GuessMainPID=no
+ExecStartPre=/usr/lib/postfix/configure-instance.sh %i
+ExecStart=/usr/sbin/postmulti -i %i -p start
+ExecStop=/usr/sbin/postmulti -i %i -p stop
+ExecReload=/usr/sbin/postmulti -i %i -p reload
+
+[Install]
+WantedBy=multi-user.target
diff --git a/debian/rules b/debian/rules
index 0c814e9..88e9794 100755
--- a/debian/rules
+++ b/debian/rules
@@ -163,8 +163,9 @@ install: build
 	ln -sf bounce.8postfix.gz ${base}/usr/share/man/man8/trace.8postfix.gz
 	ln -sf bounce.8postfix.gz ${base}/usr/share/man/man8/defer.8postfix.gz
 
-	install debian/init.d ${base}/etc/init.d/postfix
 	install debian/configure-instance.sh $(libdir)
+	install debian/postfix-instance-generator ${base}/lib/systemd/system-generators/
+	install debian/[email protected] ${base}/lib/systemd/system/
 	install debian/ip-up.d ${base}/etc/ppp/ip-up.d/postfix
 	install debian/ip-down.d ${base}/etc/ppp/ip-down.d/postfix
 	install debian/ip-up.d ${base}/etc/network/if-up.d/postfix
@@ -211,6 +212,9 @@ binary-arch: checkroot build install debian/vars
 ##	dh_installcron -a
 	dh_installchangelogs -a
 	dh_installdebconf -a
+	dh_systemd_enable -a
+	dh_installinit -a
+	dh_systemd_start -a
 ##	dh_movefiles -a
 	[ -n "$(STRIP)" ] || dh_strip -a
 	dh_compress -a
-- 
2.8.1

Reply via email to