Puppet Restarts Apache, Server Crashes

1 minute read Published:

Earlier, one of my servers stopped responding on port 80. It appears puppet had restarted apache because it updated a config file for one of the virtual hosts, and there was a configuration error, so apache didn’t come back up. By default puppet uses restart, even when a daemon supports reload, so when it messes up, it kills apache. Also, I realized it’d be nice to use configtest before even trying to restart. So, in hindsight, I leave you all with this:

service { "httpd" :
    ensure    => running,
    enable    => true,
    restart   => "/usr/sbin/apachectl configtest && /etc/init.d/httpd reload",
    subscribe => Package["httpd"],

Using the restart metaparam overrides what puppet normally uses to restart a service. First, we do a config test to make sure the configuration is good, then by using &&, we make sure that apache only reloads if the config test returned 0 (success).