From 731ef505e2aff8b0a94986f03b4b57b2acce9996 Mon Sep 17 00:00:00 2001
From: Dan Callaghan <dcallagh@redhat.com>
Date: Mon, 7 Mar 2016 13:39:35 +1000
Subject: [PATCH 1/1] systemd: populate SRS_DOMAIN default using postconf

Fixes #48
---
 init/postsrsd.systemd.in | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/init/postsrsd.systemd.in b/init/postsrsd.systemd.in
index dcc5298..ab168ca 100644
--- a/init/postsrsd.systemd.in
+++ b/init/postsrsd.systemd.in
@@ -3,11 +3,21 @@ Description=PostSRSd Daemon
 
 [Service]
 Type=simple
+Restart=always
+
+# Fallback defaults.
 Environment=SRS_DOMAIN=localhost.localdomain
 Environment=SRS_EXCLUDE_DOMAINS=
+
+# Fill in a default value for SRS_DOMAIN using postconf.
+RuntimeDirectory=@PROJECT_NAME@
+ExecStartPre=/bin/sh -c '{ echo -n SRS_DOMAIN= ; postconf -h mydomain ; } >/run/@PROJECT_NAME@/default'
+EnvironmentFile=-/run/@PROJECT_NAME@/default
+
+# Load the real configuration.
 EnvironmentFile=@CONFIG_DIR@/@PROJECT_NAME@
+
 ExecStart=@CMAKE_INSTALL_PREFIX@/sbin/@POSTSRSD@ -f "${SRS_FORWARD_PORT}" -r "${SRS_REVERSE_PORT}" -d "${SRS_DOMAIN}" -s "${SRS_SECRET}" -a "${SRS_SEPARATOR}" -u "${RUN_AS}" -c "${CHROOT}" -X"${SRS_EXCLUDE_DOMAINS}"
-Restart=always
 
 [Install]
 WantedBy=multi-user.target
-- 
2.12.2

