From 670474cf1f16a0770fd8b460ff6eaecb6c8b2fad Mon Sep 17 00:00:00 2001 From: Thomas Bellman <bellman@nsc.liu.se> Date: Wed, 4 Apr 2018 20:19:12 +0200 Subject: [PATCH] Support for systemd in apache::daily_restart. The cron job created by the apache::daily_restart class used the /sbin/service command explicitly to check if httpd is already running. While at least RHEL-7/Fedora has a compatibility script that calls systemctl, it is good form to use systemctl directly when we are on a systemd-based OS. Do so. Also use systemctl status to give more information when the restart failed. --- manifests/init.pp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index 486875f..7a03d51 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -86,10 +86,25 @@ class apache::base */ class apache::daily_restart { + $gracefulcmd = 'o=`/usr/sbin/apachectl graceful 2>&1`' + case $::initsystem + { + 'sysvinit', 'upstart': { + $statuscmd = '/sbin/service httpd status >/dev/null 2>&1' + $extrastatus = 'echo "$o" >&2' + } + 'systemd': { + $statuscmd = '/bin/systemctl status httpd.service >/dev/null 2>&1' + $extrastatus = '/bin/systemctl status -l httpd.service >&2' + } + default: { + fail("${name}: Init system ${::initsystem} not supported") + } + } # This tries to only generate output (mailed to root by Cron) if # the restart fails. And it will not try to start Apache if it is # not running. - $restart = '/sbin/service httpd status >/dev/null 2>&1 && (o=`/usr/sbin/apachectl graceful 2>&1` || echo "$o" >&2)' + $restart = "${statuscmd} && (${gracefulcmd} || ${extrastatus})" cron { 'apache::daily_restart': -- GitLab