From 3a0ce44e533de955a84ae5e2085e862066cc3e8b Mon Sep 17 00:00:00 2001
From: Markus Frosch <markus.frosch@icinga.com>
Date: Mon, 9 Sep 2019 14:43:12 +0200
Subject: [PATCH] Use correct username for service

---
 icinga-x509.service         | 2 +-
 icingaweb2-module-x509.spec | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/icinga-x509.service b/icinga-x509.service
index aac5f2b..e76115f 100644
--- a/icinga-x509.service
+++ b/icinga-x509.service
@@ -3,7 +3,7 @@ Description=Icinga Certificate Monitoring Module Jobs Runner
 
 [Service]
 Type=simple
-User=icingaweb2
+User=apache
 ExecStart=/usr/bin/icingacli x509 jobs run
 Restart=on-success
 
diff --git a/icingaweb2-module-x509.spec b/icingaweb2-module-x509.spec
index fd55237..03b7fb1 100644
--- a/icingaweb2-module-x509.spec
+++ b/icingaweb2-module-x509.spec
@@ -20,6 +20,12 @@ BuildArch:      noarch
 %global basedir %{_datadir}/icingaweb2/modules/%{module_name}
 %global service_name icinga-%{module_name}
 
+%if "%{_vendor}" == "suse"
+%global service_user wwwrun
+%else # suse
+%global service_user apache
+%endif # suse
+
 BuildRequires:  systemd-devel
 Requires:       systemd
 
@@ -58,6 +64,9 @@ cp -r * %{buildroot}%{basedir}
 install -d %{buildroot}%{_unitdir}
 install -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}/%{service_name}.service
 
+# Replace user in service unit
+sed -i -e 's~^User=.*~User=%{service_user}~' %{buildroot}%{_unitdir}/%{service_name}.service
+
 %if "%{_vendor}" == "suse"
 install -d %{buildroot}%{_sbindir}
 ln -sf /usr/sbin/service %{buildroot}%{_sbindir}/rc%{service_name}
-- 
GitLab