예제 #1
0
def delete_listener(listener_id):
    _check_listener_exists(listener_id)

    # check if that haproxy is still running and if stop it
    if os.path.exists(util.pid_path(listener_id)) and os.path.exists(
            os.path.join('/proc', util.get_haproxy_pid(listener_id))):
        cmd = "/usr/sbin/service haproxy-{0} stop".format(listener_id)
        try:
            subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as e:
            LOG.debug("Failed to stop HAProxy service: %s", e)
            return flask.make_response(flask.jsonify(dict(
                message="Error stopping haproxy",
                details=e.output)), 500)

    # parse config and delete stats socket
    try:
        cfg = _parse_haproxy_file(listener_id)
        os.remove(cfg['stats_socket'])
    except Exception:
        pass

    # delete the ssl files
    try:
        shutil.rmtree(_cert_dir(listener_id))
    except Exception:
        pass

    # delete the directory + upstart script for that listener
    shutil.rmtree(util.haproxy_dir(listener_id))
    if os.path.exists(util.upstart_path(listener_id)):
        os.remove(util.upstart_path(listener_id))

    return flask.jsonify({'message': 'OK'})
예제 #2
0
 def _check_haproxy_status(self, listener_id):
     if os.path.exists(util.pid_path(listener_id)):
         if os.path.exists(
                 os.path.join('/proc', util.get_haproxy_pid(listener_id))):
             return consts.ACTIVE
         else:  # pid file but no process...
             return consts.OFFLINE
     else:
         return consts.OFFLINE
예제 #3
0
def _check_listener_status(listener_id):
    if os.path.exists(util.pid_path(listener_id)):
        if os.path.exists(
                os.path.join('/proc', util.get_haproxy_pid(listener_id))):
            return consts.ACTIVE
        else:  # pid file but no process...
            return consts.ERROR
    else:
        return consts.OFFLINE
예제 #4
0
    def delete_listener(self, listener_id):
        self._check_listener_exists(listener_id)

        # check if that haproxy is still running and if stop it
        if os.path.exists(util.pid_path(listener_id)) and os.path.exists(
                os.path.join('/proc', util.get_haproxy_pid(listener_id))):
            cmd = "/usr/sbin/service haproxy-{0} stop".format(listener_id)
            try:
                subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT)
            except subprocess.CalledProcessError as e:
                LOG.error("Failed to stop HAProxy service: %s", e)
                return webob.Response(json=dict(
                    message="Error stopping haproxy",
                    details=e.output), status=500)

        # parse config and delete stats socket
        try:
            cfg = self._parse_haproxy_file(listener_id)
            os.remove(cfg['stats_socket'])
        except Exception:
            pass

        # delete the ssl files
        try:
            shutil.rmtree(self._cert_dir(listener_id))
        except Exception:
            pass

        # disable the service
        init_system = util.get_os_init_system()
        init_path = util.init_path(listener_id, init_system)

        if init_system == consts.INIT_SYSTEMD:
            init_disable_cmd = "systemctl disable haproxy-{list}".format(
                               list=listener_id)
        elif init_system == consts.INIT_SYSVINIT:
            init_disable_cmd = "insserv -r {file}".format(file=init_path)
        elif init_system != consts.INIT_UPSTART:
            raise util.UnknownInitError()

        if init_system != consts.INIT_UPSTART:
            try:
                subprocess.check_output(init_disable_cmd.split(),
                                        stderr=subprocess.STDOUT)
            except subprocess.CalledProcessError as e:
                LOG.error("Failed to disable haproxy-%(list)s service: "
                          "%(err)s", {'list': listener_id, 'err': e})
                return webob.Response(json=dict(
                    message="Error disabling haproxy-{0} service".format(
                            listener_id), details=e.output), status=500)

        # delete the directory + init script for that listener
        shutil.rmtree(util.haproxy_dir(listener_id))
        if os.path.exists(init_path):
            os.remove(init_path)

        return webob.Response(json={'message': 'OK'})
예제 #5
0
 def _get_listeners_on_lb(self, lb_id):
     if os.path.exists(util.pid_path(lb_id)):
         if os.path.exists(
                 os.path.join('/proc', util.get_haproxy_pid(lb_id))):
             # Check if the listener is disabled
             with open(util.config_path(lb_id), 'r') as file:
                 cfg = file.read()
                 m = re.findall('^frontend (.*)$', cfg, re.MULTILINE)
                 return m or []
         else:  # pid file but no process...
             return []
     else:
         return []
예제 #6
0
 def _check_listener_status(self, listener_id):
     if os.path.exists(util.pid_path(listener_id)):
         if os.path.exists(
                 os.path.join('/proc', util.get_haproxy_pid(listener_id))):
             # Check if the listener is disabled
             with open(util.config_path(listener_id), 'r') as file:
                 cfg = file.read()
                 m = re.search('frontend {}'.format(listener_id), cfg)
                 if m:
                     return consts.ACTIVE
                 return consts.OFFLINE
         else:  # pid file but no process...
             return consts.ERROR
     else:
         return consts.OFFLINE
예제 #7
0
 def _check_listener_status(self, listener_id):
     if os.path.exists(util.pid_path(listener_id)):
         if os.path.exists(
                 os.path.join('/proc', util.get_haproxy_pid(listener_id))):
             # Check if the listener is disabled
             with open(util.config_path(listener_id), 'r') as file:
                 cfg = file.read()
                 m = re.search('frontend {}'.format(listener_id), cfg)
                 if m:
                     return consts.ACTIVE
                 return consts.OFFLINE
         else:  # pid file but no process...
             return consts.ERROR
     else:
         return consts.OFFLINE
예제 #8
0
    def delete_listener(self, listener_id):
        try:
            self._check_listener_exists(listener_id)
        except exceptions.HTTPException:
            return webob.Response(json={'message': 'OK'})

        # check if that haproxy is still running and if stop it
        if os.path.exists(util.pid_path(listener_id)) and os.path.exists(
                os.path.join('/proc', util.get_haproxy_pid(listener_id))):
            cmd = "/usr/sbin/service haproxy-{0} stop".format(listener_id)
            try:
                subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT)
            except subprocess.CalledProcessError as e:
                LOG.error("Failed to stop haproxy-%s service: %s %s",
                          listener_id, e, e.output)
                return webob.Response(json=dict(
                    message="Error stopping haproxy", details=e.output),
                                      status=500)

        # parse config and delete stats socket
        try:
            cfg = self._parse_haproxy_file(listener_id)
            os.remove(cfg['stats_socket'])
        except Exception:
            pass

        # Since this script should be deleted at LB delete time
        # we can check for this path to see if VRRP is enabled
        # on this amphora and not write the file if VRRP is not in use
        if os.path.exists(util.keepalived_check_script_path()):
            self.vrrp_check_script_update(listener_id,
                                          action=consts.AMP_ACTION_STOP)

        # delete the ssl files
        try:
            shutil.rmtree(self._cert_dir(listener_id))
        except Exception:
            pass

        # disable the service
        init_system = util.get_os_init_system()
        init_path = util.init_path(listener_id, init_system)

        if init_system == consts.INIT_SYSTEMD:
            util.run_systemctl_command(
                consts.DISABLE, "haproxy-{list}".format(list=listener_id))
        elif init_system == consts.INIT_SYSVINIT:
            init_disable_cmd = "insserv -r {file}".format(file=init_path)
        elif init_system != consts.INIT_UPSTART:
            raise util.UnknownInitError()

        if init_system == consts.INIT_SYSVINIT:
            try:
                subprocess.check_output(init_disable_cmd.split(),
                                        stderr=subprocess.STDOUT)
            except subprocess.CalledProcessError as e:
                LOG.error(
                    "Failed to disable haproxy-%(list)s service: "
                    "%(err)s %(out)s", {
                        'list': listener_id,
                        'err': e,
                        'out': e.output
                    })
                return webob.Response(json=dict(
                    message="Error disabling haproxy-{0} service".format(
                        listener_id),
                    details=e.output),
                                      status=500)

        # delete the directory + init script for that listener
        shutil.rmtree(util.haproxy_dir(listener_id))
        if os.path.exists(init_path):
            os.remove(init_path)

        return webob.Response(json={'message': 'OK'})
예제 #9
0
 def _check_haproxy_status(self, lb_id):
     if os.path.exists(util.pid_path(lb_id)):
         if os.path.exists(
                 os.path.join('/proc', util.get_haproxy_pid(lb_id))):
             return consts.ACTIVE
     return consts.OFFLINE
예제 #10
0
 def _check_haproxy_status(self, listener_id):
     if os.path.exists(util.pid_path(listener_id)):
         if os.path.exists(
                 os.path.join('/proc', util.get_haproxy_pid(listener_id))):
             return consts.ACTIVE
     return consts.OFFLINE
예제 #11
0
    def delete_listener(self, listener_id):
        try:
            self._check_listener_exists(listener_id)
        except exceptions.HTTPException:
            return webob.Response(json={'message': 'OK'})

        # check if that haproxy is still running and if stop it
        if os.path.exists(util.pid_path(listener_id)) and os.path.exists(
                os.path.join('/proc', util.get_haproxy_pid(listener_id))):
            cmd = "/usr/sbin/service haproxy-{0} stop".format(listener_id)
            try:
                subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT)
            except subprocess.CalledProcessError as e:
                LOG.error("Failed to stop haproxy-%s service: %s %s",
                          listener_id, e, e.output)
                return webob.Response(json=dict(
                    message="Error stopping haproxy",
                    details=e.output), status=500)

        # parse config and delete stats socket
        try:
            cfg = self._parse_haproxy_file(listener_id)
            os.remove(cfg['stats_socket'])
        except Exception:
            pass

        # Since this script should be deleted at LB delete time
        # we can check for this path to see if VRRP is enabled
        # on this amphora and not write the file if VRRP is not in use
        if os.path.exists(util.keepalived_check_script_path()):
            self.vrrp_check_script_update(
                listener_id, action=consts.AMP_ACTION_STOP)

        # delete the ssl files
        try:
            shutil.rmtree(self._cert_dir(listener_id))
        except Exception:
            pass

        # disable the service
        init_system = util.get_os_init_system()
        init_path = util.init_path(listener_id, init_system)

        if init_system == consts.INIT_SYSTEMD:
            util.run_systemctl_command(
                consts.DISABLE, "haproxy-{list}".format(
                    list=listener_id))
        elif init_system == consts.INIT_SYSVINIT:
            init_disable_cmd = "insserv -r {file}".format(file=init_path)
        elif init_system != consts.INIT_UPSTART:
            raise util.UnknownInitError()

        if init_system == consts.INIT_SYSVINIT:
            try:
                subprocess.check_output(init_disable_cmd.split(),
                                        stderr=subprocess.STDOUT)
            except subprocess.CalledProcessError as e:
                LOG.error("Failed to disable haproxy-%(list)s service: "
                          "%(err)s %(out)s", {'list': listener_id, 'err': e,
                                              'out': e.output})
                return webob.Response(json=dict(
                    message="Error disabling haproxy-{0} service".format(
                            listener_id), details=e.output), status=500)

        # delete the directory + init script for that listener
        shutil.rmtree(util.haproxy_dir(listener_id))
        if os.path.exists(init_path):
            os.remove(init_path)

        return webob.Response(json={'message': 'OK'})