From 5f95fbfad2729e59d67730d2d476befa4e0a2e02 Mon Sep 17 00:00:00 2001 From: Martin Kosek Date: Oct 19 2012 00:53:51 +0000 Subject: Add fallback for httpd restarts on sysV platforms httpd init script on sysV based platforms cannot guarantee that two consecutive httpd service restarts succeed when run in a small time distance. Add fallback procedure that adds additional waiting time after such failed restart attempt, and then try to stop and start the service again. https://fedorahosted.org/freeipa/ticket/2965 --- diff --git a/ipapython/platform/redhat.py b/ipapython/platform/redhat.py index 3f35cfc..3551c28 100644 --- a/ipapython/platform/redhat.py +++ b/ipapython/platform/redhat.py @@ -25,9 +25,11 @@ import stat import sys import socket import stat +import time from ipapython import ipautil from ipapython.platform import base +from ipapython.ipa_log_manager import root_logger from ipalib import api # All what we allow exporting directly from this module @@ -115,6 +117,19 @@ class RedHatSSHService(RedHatService): def get_config_dir(self, instance_name=""): return '/etc/ssh' +class RedHatHTTPDService(RedHatService): + def restart(self, instance_name="", capture_output=True, wait=True): + try: + super(RedHatHTTPDService, self).restart(instance_name, capture_output, wait) + except ipautil.CalledProcessError: + # http may have issues with binding to ports, try to fallback + # https://bugzilla.redhat.com/show_bug.cgi?id=845405 + root_logger.debug("%s restart failed, try to stop&start again", self.service_name) + time.sleep(5) + self.stop(instance_name, capture_output) + time.sleep(5) + self.start(instance_name, capture_output, wait) + class RedHatAuthConfig(base.AuthConfig): """ AuthConfig class implements system-independent interface to configure @@ -145,6 +160,8 @@ class RedHatAuthConfig(base.AuthConfig): def redhat_service(name): if name == 'sshd': return RedHatSSHService(name) + elif name == 'httpd': + return RedHatHTTPDService(name) return RedHatService(name) class RedHatServices(base.KnownServices):