def _re_start_load_balancer(self, timeout_msg, rc_non_zero_msg, additional_params=[]): """ A common method for (re-)starting HAProxy. """ command = [ self.haproxy_command, '-D', '-f', self.config_path, '-p', self.haproxy_pidfile ] command.extend(additional_params) timeouting_popen(command, 5.0, timeout_msg, rc_non_zero_msg)
def validate_haproxy_config(config_data, haproxy_command): """ Writes the config into a temporary file and validates it using the HAProxy's -c check mode. """ try: with NamedTemporaryFile(prefix='zato-tmp') as tf: tf.write(config_data) tf.flush() common_msg = 'config_file:`{}`' common_msg = common_msg.format(open(tf.name).read()) timeout_msg = 'HAProxy didn\'t respond in `{}` seconds. ' rc_non_zero_msg = 'Failed to validate the config file using HAProxy. ' command = [haproxy_command, '-c', '-f', tf.name] timeouting_popen(command, HAPROXY_VALIDATE_TIMEOUT, timeout_msg, rc_non_zero_msg, common_msg) except Exception, e: msg = 'Caught an exception, e:`{}`'.format(format_exc(e)) logger.error(msg) raise Exception(msg)
def _re_start_load_balancer(self, timeout_msg, rc_non_zero_msg, additional_params=[]): """ A common method for (re-)starting HAProxy. """ command = [self.haproxy_command, '-D', '-f', self.config_path, '-p', self.pid_path] command.extend(additional_params) timeouting_popen(command, 5.0, timeout_msg, rc_non_zero_msg)