示例#1
0
    def notify_event(self, topic, msg):
        """Publish a message on the event publisher channel"""

        name = bytestring(self.res_name)

        multipart_msg = [b("watcher.%s.%s" % (name, topic)), json.dumps(msg)]

        if self.evpub_socket is not None and not self.evpub_socket.closed:
            self.evpub_socket.send_multipart(multipart_msg)
示例#2
0
    def notify_event(self, topic, msg):
        """Publish a message on the event publisher channel"""

        name = bytestring(self.res_name)

        multipart_msg = [b("watcher.%s.%s" % (name, topic)), json.dumps(msg)]

        if self.evpub_socket is not None and not self.evpub_socket.closed:
            self.evpub_socket.send_multipart(multipart_msg)
示例#3
0
 def __init__(self, context=None, endpoint=DEFAULT_ENDPOINT_DEALER,
              timeout=5.0, ssh_server=None, ssh_keyfile=None):
     self._init_context(context)
     self.endpoint = endpoint
     self._id = b(uuid.uuid4().hex)
     self.socket = self.context.socket(zmq.DEALER)
     self.socket.setsockopt(zmq.IDENTITY, self._id)
     self.socket.setsockopt(zmq.LINGER, 0)
     get_connection(self.socket, endpoint, ssh_server, ssh_keyfile)
     self._timeout = timeout
     self.timeout = timeout * 1000
     self.stream = ZMQStream(self.socket, tornado.ioloop.IOLoop.instance())
示例#4
0
 def __init__(self, endpoint, pubsub_endpoint, check_delay, ssh_server=None, **config):
     self.daemon = True
     self.config = config
     self.active = to_bool(config.get("active", True))
     self.context = zmq.Context()
     self.pubsub_endpoint = pubsub_endpoint
     self.endpoint = endpoint
     self.check_delay = check_delay
     self.ssh_server = ssh_server
     self.loop = ioloop.IOLoop()
     self._id = b(uuid.uuid4().hex)
     self.running = False
示例#5
0
 def __init__(self, context=None, endpoint=DEFAULT_ENDPOINT_DEALER,
              timeout=5.0, ssh_server=None, ssh_keyfile=None):
     self._init_context(context)
     self.endpoint = endpoint
     self._id = b(uuid.uuid4().hex)
     self.socket = self.context.socket(zmq.DEALER)
     self.socket.setsockopt(zmq.IDENTITY, self._id)
     self.socket.setsockopt(zmq.LINGER, 0)
     get_connection(self.socket, endpoint, ssh_server, ssh_keyfile)
     self._init_poller()
     self._timeout = timeout
     self.timeout = timeout * 1000
示例#6
0
 def __init__(self, topics, context=None, endpoint=DEFAULT_ENDPOINT_SUB,
              ssh_server=None, timeout=1.):
     self.topics = topics
     self.keep_context = context is not None
     self._init_context(context)
     self.endpoint = endpoint
     self.pubsub_socket = self.context.socket(zmq.SUB)
     get_connection(self.pubsub_socket, self.endpoint, ssh_server)
     for topic in self.topics:
         self.pubsub_socket.setsockopt(zmq.SUBSCRIBE, b(topic))
     self._init_poller()
     self.timeout = timeout
示例#7
0
    def publish(self, name, stat):
        try:
            topic = "stat.%s" % str(name)
            if "subtopic" in stat:
                topic += ".%d" % stat["subtopic"]

            stat = json.dumps(stat)
            logger.debug("Sending %s" % stat)
            self.socket.send_multipart([b(topic), stat])

        except zmq.ZMQError:
            if self.socket.closed:
                pass
            else:
                raise
示例#8
0
 def __init__(self,
              endpoint,
              pubsub_endpoint,
              check_delay,
              ssh_server=None,
              **config):
     self.daemon = True
     self.config = config
     self.active = to_bool(config.get('active', True))
     self.pubsub_endpoint = pubsub_endpoint
     self.endpoint = endpoint
     self.check_delay = check_delay
     self.ssh_server = ssh_server
     self._id = b(uuid.uuid4().hex)
     self.running = False
     self.loop = ioloop.IOLoop()
示例#9
0
 def __init__(self,
              context=None,
              endpoint=DEFAULT_ENDPOINT_DEALER,
              timeout=5.0,
              ssh_server=None,
              ssh_keyfile=None):
     self._init_context(context)
     self.endpoint = endpoint
     self._id = b(uuid.uuid4().hex)
     self.socket = self.context.socket(zmq.DEALER)
     self.socket.setsockopt(zmq.IDENTITY, self._id)
     self.socket.setsockopt(zmq.LINGER, 0)
     get_connection(self.socket, endpoint, ssh_server, ssh_keyfile)
     self._init_poller()
     self._timeout = timeout
     self.timeout = timeout * 1000
示例#10
0
 def __init__(self,
              context=None,
              endpoint=DEFAULT_ENDPOINT_DEALER,
              timeout=5.0,
              ssh_server=None,
              ssh_keyfile=None):
     self._init_context(context)
     self.endpoint = endpoint
     self._id = b(uuid.uuid4().hex)
     self.socket = self.context.socket(zmq.DEALER)
     self.socket.setsockopt(zmq.IDENTITY, self._id)
     self.socket.setsockopt(zmq.LINGER, 0)
     get_connection(self.socket, endpoint, ssh_server, ssh_keyfile)
     self._timeout = timeout
     self.timeout = timeout * 1000
     self.stream = ZMQStream(self.socket, tornado.ioloop.IOLoop.instance())
示例#11
0
 def __init__(self,
              topics,
              context=None,
              endpoint=DEFAULT_ENDPOINT_SUB,
              ssh_server=None,
              timeout=1.):
     self.topics = topics
     self.keep_context = context is not None
     self._init_context(context)
     self.endpoint = endpoint
     self.pubsub_socket = self.context.socket(zmq.SUB)
     get_connection(self.pubsub_socket, self.endpoint, ssh_server)
     for topic in self.topics:
         self.pubsub_socket.setsockopt(zmq.SUBSCRIBE, b(topic))
     self._init_poller()
     self.timeout = timeout
示例#12
0
def run_ctl(args, queue=None, stdin=''):
    cmd = '%s -m circus.circusctl' % sys.executable
    proc = subprocess.Popen(cmd.split() + shlex.split(args),
                            stdin=subprocess.PIPE if stdin else None,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    stdout, stderr = proc.communicate(b(stdin) if stdin else None)
    stdout = s(stdout)
    stderr = s(stderr)
    if queue:
        queue.put(stderr)
        queue.put(stdout)
    try:
        import gevent
        if hasattr(gevent, 'shutdown'):
            gevent.shutdown()
    except ImportError:
        pass
    return stdout, stderr
示例#13
0
def run_ctl(args, queue=None, stdin=''):
    cmd = '%s -m circus.circusctl' % sys.executable
    proc = subprocess.Popen(cmd.split() + shlex.split(args),
                            stdin=subprocess.PIPE if stdin else None,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    stdout, stderr = proc.communicate(b(stdin) if stdin else None)
    stdout = s(stdout)
    stderr = s(stderr)
    if queue:
        queue.put(stderr)
        queue.put(stdout)
    try:
        import gevent
        if hasattr(gevent, 'shutdown'):
            gevent.shutdown()
    except ImportError:
        pass
    return stdout, stderr
示例#14
0
def run_ctl(args, queue=None, stdin='', endpoint=DEFAULT_ENDPOINT_DEALER):
    cmd = '%s -m circus.circusctl' % PYTHON
    if '--endpoint' not in args:
        args = '--endpoint %s ' % endpoint + args

    proc = subprocess.Popen(cmd.split() + shlex.split(args),
                            stdin=subprocess.PIPE if stdin else None,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    stdout, stderr = proc.communicate(b(stdin) if stdin else None)
    stdout = s(stdout)
    stderr = s(stderr)
    if queue:
        queue.put(stderr)
        queue.put(stdout)
    try:
        import gevent
        if hasattr(gevent, 'shutdown'):
            gevent.shutdown()
    except ImportError:
        pass
    return stdout, stderr
示例#15
0
def run_ctl(args, queue=None, stdin='', endpoint=DEFAULT_ENDPOINT_DEALER):
    cmd = '%s -m circus.circusctl' % PYTHON
    if '--endpoint' not in args:
        args = '--endpoint %s ' % endpoint + args

    proc = subprocess.Popen(cmd.split() + shlex.split(args),
                            stdin=subprocess.PIPE if stdin else None,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    stdout, stderr = proc.communicate(b(stdin) if stdin else None)
    stdout = s(stdout)
    stderr = s(stderr)
    if queue:
        queue.put(stderr)
        queue.put(stdout)
    try:
        import gevent
        if hasattr(gevent, 'shutdown'):
            gevent.shutdown()
    except ImportError:
        pass
    return stdout, stderr
示例#16
0
    def set_opt(self, key, val):
        """Set a watcher option.

        This function set the watcher options. unknown keys are ignored.
        This function return an action number:

        - 0: trigger the process management
        - 1: trigger a graceful reload of the processes;
        """
        action = 0

        if key in self._options:
            self._options[key] = val
            action = -1  # XXX for now does not trigger a reload
        elif key == "numprocesses":
            val = int(val)
            if val < 0:
                val = 0
            if self.singleton and val > 1:
                raise ValueError('Singleton watcher has a single process')
            self.numprocesses = val
        elif key == "warmup_delay":
            self.warmup_delay = float(val)
        elif key == "working_dir":
            self.working_dir = val
            action = 1
        elif key == "uid":
            self.uid = util.to_uid(val)
            action = 1
        elif key == "gid":
            self.gid = util.to_gid(val)
            action = 1
        elif key == "send_hup":
            self.send_hup = val
        elif key == "stop_signal":
            self.stop_signal = util.to_signum(val)
        elif key == "stop_children":
            self.stop_children = util.to_bool(val)
        elif key == "shell":
            self.shell = val
            action = 1
        elif key == "env":
            if PY2 and IS_WINDOWS:
                # Windows on Python 2 does not accept Unicode values
                # in env dictionary
                self.env = dict((b(k), b(v)) for k, v in val.iteritems())
            else:
                self.env = val
            action = 1
        elif key == "cmd":
            self.cmd = val
            action = 1
        elif key == "args":
            self.args = val
            action = 1
        elif key == "graceful_timeout":
            self.graceful_timeout = float(val)
            action = -1
        elif key == "max_age":
            self.max_age = int(val)
            action = 1
        elif key == "max_age_variance":
            self.max_age_variance = int(val)
            action = 1
        elif (key.startswith('stdout_stream')
              or key.startswith('stderr_stream')):
            action = self._reload_stream(key, val)
        elif key.startswith('hooks'):
            val = val.split(',')
            if len(val) == 2:
                ignore_error = util.to_bool(val[1])
            else:
                ignore_error = False
            hook = val[0]
            self._reload_hook(key, hook, ignore_error)
            action = 0

        # send update event
        self.notify_event("updated", {"time": time.time()})
        return action
示例#17
0
    def set_opt(self, key, val):
        """Set a watcher option.

        This function set the watcher options. unknown keys are ignored.
        This function return an action number:

        - 0: trigger the process management
        - 1: trigger a graceful reload of the processes;
        """
        action = 0

        if key in self._options:
            self._options[key] = val
            action = -1    # XXX for now does not trigger a reload
        elif key == "numprocesses":
            val = int(val)
            if val < 0:
                val = 0
            if self.singleton and val > 1:
                raise ValueError('Singleton watcher has a single process')
            self.numprocesses = val
        elif key == "warmup_delay":
            self.warmup_delay = float(val)
        elif key == "working_dir":
            self.working_dir = val
            action = 1
        elif key == "uid":
            self.uid = util.to_uid(val)
            action = 1
        elif key == "gid":
            self.gid = util.to_gid(val)
            action = 1
        elif key == "send_hup":
            self.send_hup = val
        elif key == "stop_signal":
            self.stop_signal = util.to_signum(val)
        elif key == "stop_children":
            self.stop_children = util.to_bool(val)
        elif key == "shell":
            self.shell = val
            action = 1
        elif key == "env":
            if PY2 and IS_WINDOWS:
                # Windows on Python 2 does not accept Unicode values
                # in env dictionary
                self.env = dict((b(k), b(v)) for k, v in val.iteritems())
            else:
                self.env = val
            action = 1
        elif key == "cmd":
            self.cmd = val
            action = 1
        elif key == "args":
            self.args = val
            action = 1
        elif key == "graceful_timeout":
            self.graceful_timeout = float(val)
            action = -1
        elif key == "max_age":
            self.max_age = int(val)
            action = 1
        elif key == "max_age_variance":
            self.max_age_variance = int(val)
            action = 1
        elif (key.startswith('stdout_stream') or
              key.startswith('stderr_stream')):
            action = self._reload_stream(key, val)
        elif key.startswith('hooks'):
            val = val.split(',')
            if len(val) == 2:
                ignore_error = util.to_bool(val[1])
            else:
                ignore_error = False
            hook = val[0]
            self._reload_hook(key, hook, ignore_error)
            action = 0

        # send update event
        self.notify_event("updated", {"time": time.time()})
        return action