From d54a665a22f92f4abcb1fece8d8cd8f9da14b5f4 Mon Sep 17 00:00:00 2001 From: Markus Frosch <markus.frosch@icinga.com> Date: Fri, 30 Aug 2019 17:09:30 +0200 Subject: [PATCH] Add systemd service --- icinga-x509.service | 11 ++++++++ icingaweb2-module-x509.spec | 53 +++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 icinga-x509.service diff --git a/icinga-x509.service b/icinga-x509.service new file mode 100644 index 0000000..aac5f2b --- /dev/null +++ b/icinga-x509.service @@ -0,0 +1,11 @@ +[Unit] +Description=Icinga Certificate Monitoring Module Jobs Runner + +[Service] +Type=simple +User=icingaweb2 +ExecStart=/usr/bin/icingacli x509 jobs run +Restart=on-success + +[Install] +WantedBy=multi-user.target diff --git a/icingaweb2-module-x509.spec b/icingaweb2-module-x509.spec index 14044e1..b71f810 100644 --- a/icingaweb2-module-x509.spec +++ b/icingaweb2-module-x509.spec @@ -17,6 +17,10 @@ Source0: https://github.com/Icinga/icingaweb2-module-%{module_name}/archi BuildArch: noarch %global basedir %{_datadir}/icingaweb2/modules/%{module_name} +%global service_name icinga-%{module_name} + +BuildRequires: systemd-devel +Requires: systemd Requires: icingaweb2 >= %{icingaweb_min_version} Requires: php-Icinga >= %{icingaweb_min_version} @@ -50,12 +54,44 @@ mkdir -p %{buildroot}%{basedir} cp -r * %{buildroot}%{basedir} +install -d %{buildroot}%{_unitdir} +install -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}/%{service_name}.service + +%if "%{_vendor}" == "suse" +install -d %{buildroot}%{_sbindir} +ln -sf /usr/sbin/service %{buildroot}%{_sbindir}/rc%{service_name} +%endif # suse + %clean rm -rf %{buildroot} +%pre +%if "%{_vendor}" == "suse" + %service_add_pre %{service_name}.service +%endif # suse + +exit 0 + +%post +set -e + +%if "%{_vendor}" == "suse" + %service_add_post %{service_name}.service +%else # suse +%systemd_post %{service_name}.service +%endif # suse + +exit 0 + %preun set -e +%if "%{_vendor}" == "suse" + %service_del_preun %{service_name}.service +%else # suse + %systemd_preun %{service_name}.service +%endif # suse + # Only for removal if [ $1 == 0 ]; then echo "Disabling icingaweb2 module '%{module_name}'" @@ -64,12 +100,29 @@ fi exit 0 +%postun +set -e + +%if "%{_vendor}" == "suse" + %service_del_postun %{service_name}.service +%else # suse + %systemd_postun_with_restart %{service_name}.service +%endif # suse + +exit 0 + %files %doc README.md LICENSE %defattr(-,root,root) %{basedir} +%{_unitdir}/%{service_name}.service + +%if "%{_vendor}" == "suse" +%{_sbindir}/rc%{service_name} +%endif # suse + %changelog * Fri Aug 30 2019 Markus Frosch <markus.frosch@icinga.com> - 1.0.0-1 - Initial package version -- GitLab