Skip to content
Snippets Groups Projects
Commit 670474cf authored by Thomas Bellman's avatar Thomas Bellman
Browse files

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.
parent 57727842
Branches
No related tags found
No related merge requests found
...@@ -86,10 +86,25 @@ class apache::base ...@@ -86,10 +86,25 @@ class apache::base
*/ */
class apache::daily_restart 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 # 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 # the restart fails. And it will not try to start Apache if it is
# not running. # 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 { cron {
'apache::daily_restart': 'apache::daily_restart':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment