示例#1
0
    def save(self):
        # Compute the address mapping.
        # NOTE: We do not currently support the weight parameter
        # for dns-based loadbalancer. This may be implemented in
        # the future -- but for now this parameter is ignored.
        ipmap = {}
        for (name, backends) in self.ipmappings.items():
            for backend in backends:
                if not (backend.ip in ipmap):
                    ipmap[backend.ip] = []
                ipmap[backend.ip].append(name)

        # Write out our hosts file.
        hosts = open(self._manager_config().hosts_path, "wb")
        for (address, names) in ipmap.items():
            for name in set(names):
                hosts.write("%s %s\n" % (address, name))
        hosts.close()

        # Write out our configuration template.
        conf = self.template.render(hosts=self._manager_config().hosts_path)

        # Write out the config file.
        config_file = file(os.path.join(self._manager_config().config_path, "reactor.conf"), "wb")
        config_file.write(conf)
        config_file.close()

        # Send a signal to dnsmasq to reload the configuration
        # (Note: we might need permission to do this!!).
        pid = read_pid(self._manager_config().pid_file)
        if pid:
            os.kill(pid, signal.SIGHUP)
        else:
            subprocess.call(["service", "dnsmasq", "start"], close_fds=True)
示例#2
0
    def save(self):
        # Copy over our base configuration.
        shutil.copyfile(
            os.path.join(os.path.dirname(__file__), 'reactor.conf'),
            os.path.join(self._manager_config().config_path, 'reactor.conf'))

        # Send a signal to NginX to reload the configuration
        # (Note: we might need permission to do this!!)
        pid = read_pid(self._manager_config().pid_file)
        if pid:
            os.kill(pid, signal.SIGHUP)
        else:
            subprocess.call(["service", "nginx", "start"], close_fds=True)
示例#3
0
    def save(self):
        # Copy over our base configuration.
        shutil.copyfile(os.path.join(os.path.dirname(__file__), 'reactor.conf'),
                        os.path.join(self._manager_config().config_path, 'reactor.conf'))

        # Send a signal to NginX to reload the configuration
        # (Note: we might need permission to do this!!)
        pid = read_pid(self._manager_config().pid_file)
        if pid:
            os.kill(pid, signal.SIGHUP)
        else:
            subprocess.call(
                ["service", "nginx", "start"],
                close_fds=True)
示例#4
0
    def save(self):
        # Render our given template.
        config = self._manager_config()
        conf = self.template.render(global_opts=config.global_opts,
                                    maxconn=config.maxconn,
                                    clitimeout=config.clitimeout,
                                    stats_path=config.stats_path,
                                    stats_mode=config.stats_mode,
                                    frontends=self.frontends,
                                    http_backends=self.http_backends,
                                    tcp_backends=self.tcp_backends)

        # Write out the config file.
        config_file = file(config.config_file, 'wb')
        config_file.write(conf)
        config_file.flush()
        config_file.close()

        # Restart gently.
        pid = read_pid(config.pid_file)
        if len(self.frontends) > 0:
            if pid:
                subprocess.call([
                    "haproxy",
                    "-f", str(config.config_file),
                    "-p", str(config.pid_file),
                    "-sf", str(pid)],
                    close_fds=True)
            else:
                subprocess.call(
                    ["service", "haproxy", "start"],
                    close_fds=True)
        else:
            # NOTE: If haproxy doesn't have any frontends,
            # then it considers the configuration to be invalid.
            # It will continue serving traffic to the old IPs,
            # which *we* consider to be invalid. Thus, we have
            # no choice here and have to stop haproxy when we
            # have no frontend listening ports.
            if pid:
                subprocess.call(
                    ["service", "haproxy", "stop"],
                    close_fds=True)
示例#5
0
    def save(self):
        # Render our given template.
        config = self._manager_config()
        conf = self.template.render(global_opts=config.global_opts,
                                    maxconn=config.maxconn,
                                    clitimeout=config.clitimeout,
                                    stats_path=config.stats_path,
                                    stats_mode=config.stats_mode,
                                    frontends=self.frontends,
                                    http_backends=self.http_backends,
                                    tcp_backends=self.tcp_backends)

        # Write out the config file.
        config_file = file(config.config_file, 'wb')
        config_file.write(conf)
        config_file.flush()
        config_file.close()

        # Restart gently.
        pid = read_pid(config.pid_file)
        if len(self.frontends) > 0:
            if pid:
                subprocess.call([
                    "haproxy", "-f",
                    str(config.config_file), "-p",
                    str(config.pid_file), "-sf",
                    str(pid)
                ],
                                close_fds=True)
            else:
                subprocess.call(["service", "haproxy", "start"],
                                close_fds=True)
        else:
            # NOTE: If haproxy doesn't have any frontends,
            # then it considers the configuration to be invalid.
            # It will continue serving traffic to the old IPs,
            # which *we* consider to be invalid. Thus, we have
            # no choice here and have to stop haproxy when we
            # have no frontend listening ports.
            if pid:
                subprocess.call(["service", "haproxy", "stop"], close_fds=True)
示例#6
0
    def save(self):
        # Compute the address mapping.
        # NOTE: We do not currently support the weight parameter
        # for dns-based loadbalancer. This may be implemented in
        # the future -- but for now this parameter is ignored.
        ipmap = {}
        for (name, backends) in self.ipmappings.items():
            for backend in backends:
                if not (backend.ip in ipmap):
                    ipmap[backend.ip] = []
                ipmap[backend.ip].append(name)

        # Write out our hosts file.
        hosts = open(self._manager_config().hosts_path, 'wb')
        for (address, names) in ipmap.items():
            for name in set(names):
                hosts.write("%s %s\n" % (address, name))
        hosts.close()

        # Write out our configuration template.
        conf = self.template.render(hosts=self._manager_config().hosts_path)

        # Write out the config file.
        config_file = file(
            os.path.join(self._manager_config().config_path, "reactor.conf"),
            'wb')
        config_file.write(conf)
        config_file.close()

        # Send a signal to dnsmasq to reload the configuration
        # (Note: we might need permission to do this!!).
        pid = read_pid(self._manager_config().pid_file)
        if pid:
            os.kill(pid, signal.SIGHUP)
        else:
            subprocess.call(["service", "dnsmasq", "start"], close_fds=True)