How to use the supervisor.childutils.listener function in supervisor

To help you get started, we’ve selected a few supervisor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PaloAltoNetworks / minemeld-core / minemeld / supervisord / listener.py View on Github external
SR = redis.StrictRedis.from_url(
        os.environ.get('REDIS_URL', 'unix:///var/run/redis/redis.sock')
    )

    while True:
        hdrs, payload = childutils.listener.wait(sys.stdin, sys.stdout)
        LOG.info('hdr: {!r} payload: {!r}'.format(hdrs, payload))

        try:
            _handle_event(SR, engine_process_name, hdrs, payload)

        except:
            LOG.exception('Exception in handling event')

        finally:
            childutils.listener.ok(sys.stdout)
github Supervisor / supervisor / src / supervisor / memmon.py View on Github external
def runforever(self, test=False):
        while 1:
            # we explicitly use self.stdin, self.stdout, and self.stderr
            # instead of sys.* so we can unit test this code
            headers, payload = childutils.listener.wait(self.stdin, self.stdout)

            if not headers['eventname'].startswith('TICK'):
                # do nothing with non-TICK events
                childutils.listener.ok(self.stdout)
                if test:
                    break
                continue

            status = []
            if self.programs:
                status.append(
                    'Checking programs %s' % ', '.join(
                    [ '%s=%s' % x for x in self.programs.items() ] )
                    )

            if self.groups:
github collective / mr.rubber / mrrubber / rubber.py View on Github external
def runforever(self, test=False):
        # Do it when we first run
        self.checkProcesses()

        while 1:
            # we explicitly use self.stdin, self.stdout, and self.stderr
            # instead of sys.* so we can unit test this code
            headers, payload = childutils.listener.wait(self.stdin, self.stdout)

            if not headers['eventname'].startswith('SUPERVISOR_STATE_CHANGE_RUNNING'):
                # do nothing with supervisor events
                childutils.listener.ok(self.stdout)
                if test:
                    break
                continue

            self.checkProcesses()
            if test:
                break
github XiaoMi / minos / supervisor / superlance / process_exit_monitor.py View on Github external
def main():
  process_state_events = ['PROCESS_STATE_STOPPED', 'PROCESS_STATE_BACKOFF',
    'PROCESS_STATE_EXITED', 'PROCESS_STATE_FATAL']
  while True:
    headers, payload = childutils.listener.wait()

    if headers['eventname'] in process_state_events:
      handle_event(payload)

    childutils.listener.ok()
github Supervisor / superlance / superlance / process_state_monitor.py View on Github external
def run(self):
        while 1:
            hdrs, payload = childutils.listener.wait(self.stdin, self.stdout)
            self.handle_event(hdrs, payload)
            childutils.listener.ok(self.stdout)
github Supervisor / superlance / superlance / crashmail.py View on Github external
def runforever(self, test=False):
        while 1:
            # we explicitly use self.stdin, self.stdout, and self.stderr
            # instead of sys.* so we can unit test this code
            headers, payload = childutils.listener.wait(
                self.stdin, self.stdout)

            if not headers['eventname'] == 'PROCESS_STATE_EXITED':
                # do nothing with non-TICK events
                childutils.listener.ok(self.stdout)
                if test:
                    self.stderr.write('non-exited event\n')
                    self.stderr.flush()
                    break
                continue

            pheaders, pdata = childutils.eventdata(payload+'\n')

            if int(pheaders['expected']):
                childutils.listener.ok(self.stdout)
                if test:
                    self.stderr.write('expected exit\n')
                    self.stderr.flush()
                    break
                continue
github FORTH-ICS-INSPIRE / artemis / monitor / core / listener.py View on Github external
def run():
    db_conn = create_connect_db()
    db_cursor = db_conn.cursor()
    while True:
        headers, body = listener.wait(sys.stdin, sys.stdout)
        body = dict([pair.split(":") for pair in body.split(" ")])
        # write_stderr('{} | {}'.format(headers, body))

        if headers["eventname"] in ("PROCESS_STATE_RUNNING", "PROCESS_STATE_STOPPED"):
            process = body["processname"]
            if process != "listener":
                new_state = headers["eventname"] == "PROCESS_STATE_RUNNING"
                while True:
                    try:
                        write_stderr("{} -> {}".format(process, new_state))
                        db_cursor.execute(query, (process, new_state))
                        db_conn.commit()
                        break
                    except (psycopg2.InterfaceError, psycopg2.OperationalError):
                        db_conn = create_connect_db()
                        db_cursor = db_conn.cursor()
github rahiel / supervisor-alert / supervisor_alert.py View on Github external
if args.configure:
        return configure()

    s = "PROCESS_STATE_"

    hostname = gethostname()

    if args.telegram:
        alert = telegram
    elif args.command:
        alert = partial(send, command=shlex.split(args.command))
    else:
        raise Exception("No command specified.")

    while True:
        headers, payload = listener.wait()
        event_name = headers["eventname"]

        if event_name.startswith(s):
            event_name = event_name[len(s):].lower()
            data = get_headers(payload)  # keys: from_state, pid, processname
            process_name = data["processname"]
            message = process_name + " has entered state " + event_name
            if args.show_hostname:
                message = hostname + ": " + message
            alert(message=message)
        else:
            listener.ok()
github Supervisor / supervisor / src / supervisor / memmon.py View on Github external
continue

                if group in self.groups:
                    self.stderr.write('RSS of %s is %s\n' % (pname, rss))
                    if rss > self.groups[group]:
                        self.restart(pname, rss)
                        continue

                if self.any is not None:
                    self.stderr.write('RSS of %s is %s\n' % (pname, rss))
                    if rss > self.any:
                        self.restart(pname, rss)
                        continue

            self.stderr.flush()
            childutils.listener.ok(self.stdout)
            if test:
                break
github rahiel / supervisor-alert / supervisor_alert.py View on Github external
def telegram(message):
    """Send message with telegram-send."""
    try:
        check_call(["telegram-send", message] + telegram_conf_args)
        listener.ok()
    except OSError:     # command not found
        cmd = expanduser("~/.local/bin/telegram-send")
        check_call([cmd, message] + telegram_conf_args)
        listener.ok()
    except CalledProcessError:
        listener.fail()