def main():
    import argparse
    import os
    parser = argparse.ArgumentParser(executable_name,
                                     description="Supervisor event listener which restarts processes on TICK events.")
    parser.add_argument("-p", "--programs", type=str, nargs="*", metavar="PROGRAM",
                        help="Supervisor process name/s to be restarted if in RUNNING state.")
    parser.add_argument("-a", "--any-program", action="store_true",
                        help="Restart any supervisor processes in RUNNING state.")
    parser.add_argument("--dither", type=int, metavar="DITHER_MAX", dest="dither_max",
                        help="Add dither before restarting processes. Specify maximum time to dither in seconds.")
    args = parser.parse_args()
    if not(args.programs or args.any_program):
        parser.error("Must specify either -p/--programs or -a/--any-program.")

    try:
        rpc = childutils.getRPCInterface(os.environ)
    except KeyError as e:
        if e.args[0] == "SUPERVISOR_SERVER_URL":
            print("{0} must be run as a supervisor event listener.".format(executable_name), file=sys.stderr)
            sys.exit(1)
        else:
            raise

    listener = ProcessRestarter(rpc, args.programs or [], args.any_program)
    listener.runforever()
Ejemplo n.º 2
0
def main():
    memmon = memmon_from_args(sys.argv[1:])
    if memmon is None:
        # something went wrong or -h has been given
        usage()
    memmon.rpc = childutils.getRPCInterface(os.environ)
    memmon.runforever()
def main():
    import argparse
    import os
    import sys
    parser = argparse.ArgumentParser(executable_name,
                                     description="Supervisor event listener which executes a command when "
                                     "events are received and optionally restarts processes on non-zero exit status.")
    parser.add_argument("-e", "--execute", metavar="COMMAND", dest="command", required=True,
                        help="Command or script to execute on supervisor events.")
    parser.add_argument("-p", "--restart-programs", type=str, nargs="*", metavar="PROGRAM",
                        help="Supervisor process name/s to be restarted on non-zero exit status if in RUNNING state.")
    parser.add_argument("-a", "--restart-any-program", action="store_true",
                        help="Restart any supervisor processes in RUNNING state on non-zero exit status.")
    parser.add_argument("--dither", type=int, metavar="DITHER_MAX", dest="dither_max",
                        help="Add dither before restarting processes. Specify maximum time to dither in seconds.")
    args = parser.parse_args()

    try:
        rpc = childutils.getRPCInterface(os.environ)
    except KeyError as e:
        if e.args[0] == "SUPERVISOR_SERVER_URL":
            print("{0} must be run as a supervisor event listener.".format(executable_name), file=sys.stderr)
            sys.exit(1)
        else:
            raise

    listener = EventExec(rpc, args.restart_programs or [], args.restart_any_program, args.command)
    listener.runforever()
Ejemplo n.º 4
0
def start_timemon(group, interval, number, sleep=0):
    max_serial = 0
    while True:
        rpc = childutils.getRPCInterface(os.environ)
        hdrs, payload = childutils.listener.wait(sys.stdin, sys.stdout)
        if int(hdrs['serial']) <= max_serial:
            continue
        max_serial = int(hdrs['serial'])
        process_info = rpc.supervisor.getAllProcessInfo()
        should_restart = getattr(datetime.datetime.now(), interval) % int(number)
        if should_restart:
            for process in process_info:
                if process['group'] == group and \
                   should_restart:
                    try:
                        rpc.supervisor.stopProcess(':'.join([process['group'], process['name']]), True)
                    except Exception as e:
                        write_stderr(str(e) + "\n")
                    if sleep:
                        time.sleep(float(sleep))
                    try:
                        rpc.supervisor.startProcess(':'.join([process['group'], process['name']]), True)
                    except Exception as e:
                        write_stderr(str(e) + "\n")
        write_stdout("RESULT 2\nOK")
Ejemplo n.º 5
0
    def _restart_process(self, process_spec):
        """Restart a process.
        """

        name_spec = make_namespec(
            process_spec[GROUP_KEY], process_spec[NAME_KEY])

        rpc_client = childutils.getRPCInterface(self._environment)

        process_spec = rpc_client.supervisor.getProcessInfo(name_spec)
        if process_spec[STATE_KEY] is ProcessStates.RUNNING:
            self._log('Trying to stop process %s', name_spec)

            try:
                rpc_client.supervisor.stopProcess(name_spec)
                self._log('Stopped process %s', name_spec)
            except xmlrpclib.Fault as exc:
                self._log('Failed to stop process %s: %s', name_spec, exc)

            try:
                self._log('Starting process %s', name_spec)
                rpc_client.supervisor.startProcess(name_spec, False)
            except xmlrpclib.Fault as exc:
                self._log('Failed to start process %s: %s', name_spec, exc)

        else:
            self._log('%s not in RUNNING state, cannot restart', name_spec)
Ejemplo n.º 6
0
def main():
    memmon = memmon_from_args(sys.argv[1:])
    if memmon is help_request:  # --help
        usage(exitstatus=0)
    elif memmon is None:  # something went wrong
        usage()
    memmon.rpc = childutils.getRPCInterface(os.environ)
    memmon.runforever()
Ejemplo n.º 7
0
def get_last_lines_of_process_stdout_unwrapped(pheaders, stdout_lines):
    rpc = childutils.getRPCInterface(os.environ)
    proc_name = get_proc_name(pheaders)
    result = get_last_lines(
        proc_name,
        rpc.supervisor.tailProcessStdoutLog,
        rpc.supervisor.readProcessStdoutLog,
        stdout_lines)
    return result
Ejemplo n.º 8
0
def main():
    rpcinterface = childutils.getRPCInterface(os.environ)
    while 1:
        headers, payload = childutils.listener.wait()
        if headers['eventname'].startswith('PROCESS_COMMUNICATION'):
            pheaders, pdata = childutils.eventdata(payload)
            pname = '%s:%s' % (pheaders['processname'], pheaders['groupname'])
            rpcinterface.supervisor.sendProcessStdin(pname, 'Got it yo\n')
        childutils.listener.ok()
Ejemplo n.º 9
0
def main():
    rpcinterface = childutils.getRPCInterface(os.environ)
    while 1:
        headers, payload = childutils.listener.wait()
        if headers["eventname"].startswith("PROCESS_COMMUNICATION"):
            pheaders, pdata = childutils.eventdata(payload)
            pname = "%s:%s" % (pheaders["processname"], pheaders["groupname"])
            rpcinterface.supervisor.sendProcessStdin(pname, "Got it yo\n")
        childutils.listener.ok()
Ejemplo n.º 10
0
def main():
    import getopt
    short_args="hp:g:a:s:m:i:"
    long_args=[
        "help",
        "program=",
        "group=",
        "any=",
        "sendmail_program=",
        "email=",
        "pingport=",
        ]
    arguments = sys.argv[1:]
    if not arguments:
        usage()
    try:
        opts, args=getopt.getopt(arguments, short_args, long_args)
    except:
        print __doc__
        sys.exit(2)

    programs = {}
    groups = {}
    any = None
    sendmail = '/usr/sbin/sendmail -t -i'
    email = None
    pingport = None

    for option, value in opts:

        if option in ('-h', '--help'):
            usage()

        if option in ('-p', '--program'):
            name, size = parse_namesize(option, value)
            programs[name] = size

        if option in ('-g', '--group'):
            name, size = parse_namesize(option, value)
            groups[name] = size

        if option in ('-a', '--any'):
            size = parse_size(option, value)
            any = size

        if option in ('-s', '--sendmail_program'):
            sendmail = value

        if option in ('-m', '--email'):
            email = value

        if option in ('-i', '--pingport'):
            pingport = value

    rpc = childutils.getRPCInterface(os.environ)
    memmon = CustomMemmon(programs, groups, any, sendmail, email, rpc, pingport)
    memmon.runforever()
Ejemplo n.º 11
0
def main(cmd, arg):
    rpcinterface = childutils.getRPCInterface(conf)
    #while 1:
    #    headers, payload = childutils.listener.wait()
    #    if headers['eventname'].startswith('TICK'):

    print >>sys.stderr, childutils.get_asctime(), ':', cmd, arg
                
    rpcinterface.supervisor.sendRemoteCommEvent(cmd, arg + '\n')
Ejemplo n.º 12
0
 def tail(self, group, process, stream, chars):
     """Return the last lines from the process stream (stderr or stdout)."""
     rpc = childutils.getRPCInterface(os.environ)
     processname = '{group}{process}'.format(group=group + ':' if group else '', process=process)
     if stream == 'stdout':
         log, _, _ = rpc.supervisor.tailProcessStdoutLog(processname, 0, chars)
     else:
         log, _, _ = rpc.supervisor.tailProcessStderrLog(processname, 0, chars)
     log = '\n'.join(log.split('\n')[1:])
     return log
Ejemplo n.º 13
0
def main(argv=sys.argv):
    import getopt
    short_args="hp:o:n:m:"
    long_args=[
        "help",
        "program=",
        "offset=",
        "num=",
        "multiple="
        ]
    arguments = argv[1:]
    try:
        opts, args = getopt.getopt(arguments, short_args, long_args)
    except:
        usage()

    if not opts:
        usage()

    programs = []
    offset = 0
    num = -1
    multiple = 1

    for option, value in opts:

        if option in ('-h', '--help'):
            usage()

        if option in ('-p', '--program'):
            programs.append(value)

        if option in ('-o', '--offset'):
            offset = int(value)

        if option in ('-n', '--num'):
            if value == "auto":
                num = -1
            else:
                num = int(value)
	if option in ('-m', '--multiple'):
	    multiple = int(value)

    url = arguments[-1]

    try:
        rpc = childutils.getRPCInterface(os.environ)
    except KeyError, why:
        if why[0] != 'SUPERVISOR_SERVER_URL':
            raise
        sys.stderr.write('rubber must be run as a supervisor event '
                         'listener\n')
        sys.stderr.flush()
        return
Ejemplo n.º 14
0
 def setUp(self):
     """ The setUp starts the subscriber to the Supvisors events and
     get the event queues. """
     # get the addresses
     proxy = getRPCInterface(os.environ).supvisors
     addresses_info = proxy.get_all_addresses_info()
     self.HOST_01 = addresses_info[0]['address_name']
     self.HOST_02 = addresses_info[1]['address_name']
     self.HOST_03 = addresses_info[2]['address_name']
     self.HOST_04 = addresses_info[3]['address_name']
     # create a context
     self.context = Context()
     # create the thread of event subscriber
     self.evloop = SequenceChecker()
     self.evloop.start()
def main():
    import argparse
    import os
    import sys
    parser = argparse.ArgumentParser(executable_name,
                                     description="Supervisor TICK event listener which restarts processes "
                                     "if file system changes occur between ticks.")
    parser.add_argument("-p", "--programs", type=str, nargs="*", metavar="PROGRAM",
                        help="Supervisor process name/s to be restarted if in RUNNING state.")
    parser.add_argument("-a", "--any-program", action="store_true",
                        help="Restart any supervisor processes in RUNNING state.")
    parser.add_argument("-f", "--paths", type=str, nargs="+", metavar="PATH", required=True,
                        help="Path to watch for file system events.")
    parser.add_argument("-r", "--recursive", action="store_true",
                        help="Watch path/s recursively.")
    parser.add_argument("--watched-events", type=str, nargs="*", choices=["moved", "created", "deleted", "modified"],
                        help="Specify which file system events to watch, by default all events will be watched.")
    parser.add_argument("--dither", type=int, metavar="DITHER_MAX", dest="dither_max",
                        help="Add dither before restarting processes. Specify maximum time to dither in seconds.")
    args = parser.parse_args()
    if not(args.programs or args.any_program):
        parser.error("Must specify either -p/--programs or -a/--any-program.")
    for path in args.paths:
        if not(os.path.exists(path)):
            parser.error("Path {0} does not exits.".format(path))

    try:
        rpc = childutils.getRPCInterface(os.environ)
    except KeyError as e:
        if e.args[0] == "SUPERVISOR_SERVER_URL":
            print("{0} must be run as a supervisor event listener.".format(executable_name), file=sys.stderr)
            sys.exit(1)
        else:
            raise

    if args.watched_events:
        fs_event_handler = PollableFileSystemEventHandler(
            "moved" in args.watched_events, "created" in args.watched_events,
            "deleted" in args.watched_events, "modified" in args.watched_events)
    else:
        fs_event_handler = PollableFileSystemEventHandler(True, True, True, True)

    listener = FSEventWatcher(
        rpc, args.programs or [], args.any_program, args.paths, args.recursive, fs_event_handler, args.dither_max)
    listener.runforever()
Ejemplo n.º 16
0
    def __init__(self, check_name, process_group, checks_config, env=None):
        """Constructor.

        :param str check_name: the name of check to display in log.
        :param str process_group: the name of the process group.
        :param list checks_config: the list of check module configurations
               in format [(check_class, check_configuration_dictionary)]
        :param dict env: environment.
        """

        self._environment = env or os.environ
        self._name = check_name
        self._checks_config = checks_config
        self._checks = self._init_checks()
        self._process_group = process_group
        self._group_check_name = '%s_check' % (self._process_group,)
        self._rpc_client = childutils.getRPCInterface(self._environment)
        self._stop_event = threading.Event()
Ejemplo n.º 17
0
def main(argv=sys.argv):
    import getopt
    short_args="hp:b:"
    long_args=[
        "help",
        "program=",
        "body=",
        ]
    arguments = argv[1:]
    try:
        opts, args = getopt.getopt(arguments, short_args, long_args)
    except:
        usage()

    if not args:
        usage()
    if len(args) > 1:
        usage()

    programs = []
    inbody = None

    for option, value in opts:

        if option in ('-h', '--help'):
            usage()

        if option in ('-p', '--program'):
            programs.append(value)

        if option in ('-b', '--body'):
            inbody = value

    url = arguments[-1]

    try:
        rpc = childutils.getRPCInterface(os.environ)
    except KeyError, why:
        if why[0] != 'SUPERVISOR_SERVER_URL':
            raise
        sys.stderr.write('httpctrl must be run as a supervisor event '
                         'listener\n')
        sys.stderr.flush()
        return
Ejemplo n.º 18
0
 def setUp(self):
     """ Check that 3 running addresses are available. """
     # get a reference to the local RPC proxy
     self.local_proxy = childutils.getRPCInterface(os.environ)
     self.local_supervisor = self.local_proxy.supervisor
     self.local_supvisors = self.local_proxy.supvisors
     # check the number of running addresses
     addresses_info = self.local_supvisors.get_all_addresses_info()
     self.running_addresses = [info['address_name']
         for info in addresses_info
             if info['statecode'] == AddressStates.RUNNING]
     self.assertEqual(3, len(self.running_addresses))
     # assumption is made that this test is run on Supvisors Master address
     self.assertEqual(gethostname(),
                      self.local_supvisors.get_master_address())
     # keep a reference to all RPC proxies
     self.proxies = {address: rpcrequests.getRPCInterface(address, os.environ)
         for address in self.running_addresses}
     # create the thread of event subscriber
     self.evloop = SupvisorsEventQueues()
     # start the thread
     self.evloop.start()
Ejemplo n.º 19
0
 def test_sequencing(self):
     """ Test the whole sequencing of the starting of the test application.
     At this point, Supvisors is in OPERATION phase.
     This process is the first to be started. """
     # store a proxy to perform XML-RPC requests
     self.proxy = getRPCInterface(os.environ)
     # wait for address_queue to trigger
     self.get_addresses()
     # define the context to know which process is running
     self.create_context()
     # start a converter
     self.proxy.supvisors.start_args('my_movies:converter_05')
     # empty queues (pull STARTING / RUNNING events)
     self.check_converter_running()
     # send restart request
     self.proxy.supvisors.restart()
     # test the starting of web_movies application
     self.check_web_movies_stopping()
     # test the starting of my_movies application
     self.check_my_movies_stopping()
     # test the starting of database application
     self.check_database_stopping()
Ejemplo n.º 20
0
def main():
    import getopt

    short_args = "hp:g:"
    long_args = [
        "help",
        "program=",
        "group=",
        ]
    arguments = sys.argv[1:]
    if not arguments:
        usage()
    try:
        opts, args = getopt.getopt(arguments, short_args, long_args)
    except:
        usage()

    uptime_per_program = {}
    uptime_per_group = {}

    for option, value in opts:
        if option in ('-h', '--help'):
            usage()

        if option in ('-p', '--program'):
            name, uptime = parse_option(option, value)
            uptime_per_program[name] = uptime

        if option in ('-g', '--group'):
            name, uptime = parse_option(option, value)
            uptime_per_group[name] = uptime

    logging.basicConfig(
            level=logging.INFO,
            format='%(asctime)s %(levelname)s %(message)s')
    rpc = childutils.getRPCInterface(os.environ)
    uptimemon = Uptimemon(uptime_per_program, uptime_per_group, rpc)
    uptimemon.roundhouse_forever()
def main():
    import argparse
    import os
    parser = argparse.ArgumentParser("supervisor-event-exec")
    parser.add_argument("-e", "--execute", metavar="COMMAND", dest="command", required=True,
                        help="Command or script to execute on supervisor events.")
    parser.add_argument("-p", "--restart-programs", type=str, nargs="*", metavar="PROGRAM",
                        help="Supervisor process name/s to be restarted on non-zero exit status if in RUNNING state.")
    parser.add_argument("-a", "--restart-any-program", action="store_true",
                        help="Restart any supervisor processes in RUNNING state on non-zero exit status.")
    args = parser.parse_args()

    try:
        rpc = childutils.getRPCInterface(os.environ)
    except KeyError as e:
        if e.args[0] == "SUPERVISOR_SERVER_URL":
            print("supervisor-event-exec must be run as a supervisor event listener.", file=sys.stderr)
            sys.exit(1)
        else:
            raise

    event_exec = SupervisorEventExec(rpc, args.command, args.restart_programs, args.restart_any_program)
    event_exec.runforever()
Ejemplo n.º 22
0
def main():
    rpci = getRPCInterface(os.environ)

    while True:
        h, p = listener.wait()
        if not h['eventname'] == 'PROCESS_STATE_EXITED':
            listener.ok()
            continue

        ph, _pd = eventdata(p + '\n')
        if ph['processname'] == 'mongodb':
            if int(ph['expected']):
                listener.ok()
                continue

            listener.send("MONGODB HAS BEEN RESTARTED. SO WILL THE APP!")
            rpci.supervisor.stopProcessGroup('app')
            rpci.supervisor.startProcessGroup('app', True)
            listener.ok()
            now = datetime.now()
            send_twitter("[FATAL] %s - mongodb has been restarted" % now.isoformat())
            return

        listener.ok()
Ejemplo n.º 23
0
def main():
    import getopt
    short_args="hp:g:a:s:m:n:u:t"
    long_args=[
        "help",
        "program=",
        "group=",
        "any=",
        "sendmail_program=",
        "email=",
        "uptime=",
        "name=",
        ]
    arguments = sys.argv[1:]
    if not arguments:
        usage()
    try:
        opts, args=getopt.getopt(arguments, short_args, long_args)
    except:
        print __doc__
        sys.exit(2)

    programs = {}
    groups = {}
    any = None
    sendmail = '/usr/sbin/sendmail -t -i'
    email = None
    uptime = sys.maxint
    name = None
    tree = False

    for option, value in opts:

        if option in ('-h', '--help'):
            usage()

        if option in ('-p', '--program'):
            name, size = parse_namesize(option, value)
            programs[name] = size

        if option in ('-g', '--group'):
            name, size = parse_namesize(option, value)
            groups[name] = size

        if option in ('-a', '--any'):
            size = parse_size(option, value)
            any = size

        if option in ('-s', '--sendmail_program'):
            sendmail = value

        if option in ('-m', '--email'):
            email = value

        if option in ('-u', '--uptime'):
            uptime = parse_seconds(option, value)

        if option in ('-n', '--name'):
            name = value

        if option in ('-t', '--tree'):
            tree = True

    rpc = childutils.getRPCInterface(os.environ)
    memmon = Memmon(programs, groups, any, sendmail, email, name, uptime, rpc, tree)
    memmon.runforever()
Ejemplo n.º 24
0
def main(argv=sys.argv):
    import getopt
    short_args="hp:at:cC:b:s:m:g:d:eE"
    long_args=[
        "help",
        "program=",
        "any",
        "timeout=",
        "code=",
        "not-code=",
        "body=",
        "sendmail_program=",
        "email=",
        "gcore=",
        "coredir=",
        "eager",
        "not-eager",
        ]
    arguments = argv[1:]
    try:
        opts, args = getopt.getopt(arguments, short_args, long_args)
    except:
        usage()

    if not args:
        usage()
    if len(args) > 1:
        usage()

    programs = []
    any = False
    sendmail = '/usr/sbin/sendmail -t -i'
    gcore = '/usr/bin/gcore -o'
    coredir = None
    eager = True
    email = None
    timeout = 10
    status = '200'
    nstatus = ''
    inbody = None

    for option, value in opts:

        if option in ('-h', '--help'):
            usage()

        if option in ('-p', '--program'):
            programs.append(value)

        if option in ('-a', '--any'):
            any = True

        if option in ('-s', '--sendmail_program'):
            sendmail = value

        if option in ('-m', '--email'):
            email = value

        if option in ('-t', '--timeout'):
            timeout = int(value)

        if option in ('-c', '--code'):
            status = value
            
        if option in ('-C', '--not-code'):
            nstatus = value
            status = ''

        if option in ('-b', '--body'):
            inbody = value

        if option in ('-g', '--gcore'):
            gcore = value

        if option in ('-d', '--coredir'):
            coredir = value

        if option in ('-e', '--eager'):
            eager = True

        if option in ('-E', '--not-eager'):
            eager = False

    url = arguments[-1]

    try:
        rpc = childutils.getRPCInterface(os.environ)
    except KeyError, why:
        if why[0] != 'SUPERVISOR_SERVER_URL':
            raise
        sys.stderr.write('httpok must be run as a supervisor event '
                         'listener\n')
        sys.stderr.flush()
        return
Ejemplo n.º 25
0
 def test_getRPCInterface(self):
     from supervisor.childutils import getRPCInterface
     rpc = getRPCInterface({'SUPERVISOR_SERVER_URL':'http://localhost:9001'})
Ejemplo n.º 26
0
def main():
    import getopt
    short_args="hp:g:a:s:m:k:c:"
    long_args=[
        "help",
        "program=",
        "group=",
        "any=",
        "sendmail_program=",
        "email=",
        "aws_access_key=",
        "aws_secret_key=",
        "env_prefix="
        ]
    arguments = sys.argv[1:]
    if not arguments:
        usage()
    try:
        opts, args=getopt.getopt(arguments, short_args, long_args)
    except:
        print __doc__
        sys.exit(2)

    programs = {}
    groups = {}
    any = None
    sendmail = '/usr/sbin/sendmail -t -i'
    email = None
    aws_access_key = None
    aws_secret_key = None

    for option, value in opts:

        if option in ('-h', '--help'):
            usage()

        if option in ('-p', '--program'):
            name, size = parse_namesize(option, value)
            programs[name] = size

        if option in ('-g', '--group'):
            name, size = parse_namesize(option, value)
            groups[name] = size

        if option in ('-a', '--any'):
            size = parse_size(option, value)
            any = size

        if option in ('-s', '--sendmail_program'):
            sendmail = value

        if option in ('-m', '--email'):
            email = value
        
        if option in ('-k', '--aws_access_key'):
            aws_access_key = value
        
        if option in ('-c', '--aws_secret_key'):
            aws_secret_key = value
    
    log.debug('Starting memmon')
    log.debug('aws_access_key:%s' % (aws_access_key))
    log.debug('aws_secret_key:%s' % (aws_secret_key))
    
    rpc = childutils.getRPCInterface(os.environ)
    memmon = Memmon(programs, groups, any, sendmail, email, rpc, aws_access_key, aws_secret_key)
    memmon.runforever()
    from StringIO import StringIO
    config_file = StringIO()
    config_file.write(default_config)
    config_file.seek(0)

    (parser, options, argv) = configglue(
        config_file,
        args=sys.argv[1:],
        usage="%prog [options]",
        extra_parsers=[("comma_separated_list", comma_separated_list_parser)])

    if not options.groups or not options.interval or not options.timeout:
        parser.print_help()
        sys.exit(2)

    # configure the logger
    try:
        level = logging._levelNames[options.log_level]
    except KeyError:
        # if level doesn't exist fallback to DEBUG
        level = logging.DEBUG

    root_logger = logging.getLogger()
    configure_logger(logger=root_logger, filename=options.log_file,
                     level=level, log_format=options.log_format)

    rpc = childutils.getRPCInterface(os.environ)
    hbl = HeartbeatListener(options.timeout, options.interval, options.groups,
                            options.processes, rpc)
    hbl.runforever()
Ejemplo n.º 28
0
 def test_getRPCInterface(self):
     from supervisor.childutils import getRPCInterface
     rpc = getRPCInterface({'SUPERVISOR_SERVER_URL':'http://localhost:9001'})
     # we can't really test this thing; its a magic object
     self.assertTrue(rpc is not None)
Ejemplo n.º 29
0
    config_file.seek(0)

    (parser, options,
     argv) = configglue(config_file,
                        args=sys.argv[1:],
                        usage="%prog [options]",
                        extra_parsers=[("comma_separated_list",
                                        comma_separated_list_parser)])

    if not options.groups or not options.interval or not options.timeout:
        parser.print_help()
        sys.exit(2)

    # configure the logger
    try:
        level = logging._levelNames[options.log_level]
    except KeyError:
        # if level doesn't exist fallback to DEBUG
        level = logging.DEBUG

    root_logger = logging.getLogger()
    configure_logger(logger=root_logger,
                     filename=options.log_file,
                     level=level,
                     log_format=options.log_format)

    rpc = childutils.getRPCInterface(os.environ)
    hbl = HeartbeatListener(options.timeout, options.interval, options.groups,
                            options.processes, rpc)
    hbl.runforever()
Ejemplo n.º 30
0
def main(argv=sys.argv):
    short_args="hp:at:c:b:s:m:g:d:eEn:"
    long_args=[
        "help",
        "program=",
        "any",
        "timeout=",
        "code=",
        "body=",
        "sendmail_program=",
        "email=",
        "gcore=",
        "coredir=",
        "eager",
        "not-eager",
        "name=",
        ]
    arguments = argv[1:]
    try:
        opts, args = getopt.getopt(arguments, short_args, long_args)
    except:
        usage()

    # check for -h must be done before positional args check
    for option, value in opts:
        if option in ('-h', '--help'):
            usage(exitstatus=0)

    if not args:
        usage()
    if len(args) > 1:
        usage()

    programs = []
    any = False
    sendmail = '/usr/sbin/sendmail -t -i'
    gcore = '/usr/bin/gcore -o'
    coredir = None
    eager = True
    email = None
    timeout = 10
    retry_time = 10
    statuses = []
    inbody = None
    name = None

    for option, value in opts:

        if option in ('-p', '--program'):
            programs.append(value)

        if option in ('-a', '--any'):
            any = True

        if option in ('-s', '--sendmail_program'):
            sendmail = value

        if option in ('-m', '--email'):
            email = value

        if option in ('-t', '--timeout'):
            timeout = int(value)

        if option in ('-c', '--code'):
            statuses.append(int(value))

        if option in ('-b', '--body'):
            inbody = value

        if option in ('-g', '--gcore'):
            gcore = value

        if option in ('-d', '--coredir'):
            coredir = value

        if option in ('-e', '--eager'):
            eager = True

        if option in ('-E', '--not-eager'):
            eager = False

        if option in ('-n', '--name'):
            name = value

    if not statuses:
        statuses = [200]

    url = arguments[-1]

    try:
        rpc = childutils.getRPCInterface(os.environ)
    except KeyError as e:
        if e.args[0] != 'SUPERVISOR_SERVER_URL':
            raise
        sys.stderr.write('httpok must be run as a supervisor event '
                         'listener\n')
        sys.stderr.flush()
        return

    prog = HTTPOk(rpc, programs, any, url, timeout, statuses, inbody, email,
                  sendmail, coredir, gcore, eager, retry_time, name)
    prog.runforever()
Ejemplo n.º 31
0
 def test_getRPCInterface(self):
     from supervisor.childutils import getRPCInterface
     rpc = getRPCInterface(
         {'SUPERVISOR_SERVER_URL': 'http://localhost:9001'})
def main():
    logging.basicConfig(filename='ordered_startup.log', level=logging.DEBUG)
    log = logging.getLogger('ordered_startup_supervisord.main')
    try:
        config_file = None
        if len(sys.argv) > 1:
            config_file = sys.argv[1]
        if config_file is None:
            config_file = get_default_config_file()
        if config_file is None:
            print("Unable to find a config file!", file=sys.stderr)
            sys.exit(1)
        if not os.path.exists(config_file):
            print("Config path {} does not exist!".format(config_file),
                  file=sys.stderr)
            sys.exit(1)

        parser = UnhosedConfigParser()
        parser.read(get_all_configs(config_file))
        startup_plan = StartupPlan(parser)

        rpcinterface = childutils.getRPCInterface(os.environ)

        # get group for all processes
        processes = rpcinterface.supervisor.getAllProcessInfo()
        for proc in processes:
            # if group and name differ, process is in a group and startProcess needs "group:name" as arg
            if proc['name'] != proc['group']:
                for p in startup_plan.programs:
                    if p.name == proc['name']:
                        p.group = proc['group']
                        p.procname = "{}:{}".format(proc['group'],
                                                    proc['name'])
                        break

        log.info("programs in order: ")
        for prog in startup_plan.programs:
            log.info(prog.name)
        if not startup_plan.programs[0].options.autostart:
            rpcinterface.supervisor.startProcess(startup_plan.programs[0].name,
                                                 False)
        initial_start = 'STARTED'
        while 1:
            headers, payload = childutils.listener.wait()
            if headers['eventname'].startswith(
                    'PROCESS_STATE') and initial_start != 'FINISHED':
                pheaders = childutils.get_headers(payload)
                log.debug("headers = {}".format(repr(headers)))
                log.debug("payload = {}".format(repr(pheaders)))
                state = headers['eventname'][len('PROCESS_STATE_'):]
                start_next = False
                for program in startup_plan.programs:
                    if start_next:
                        log.info("Starting process: {}".format(
                            program.procname))
                        rpcinterface.supervisor.startProcess(program.procname)
                        start_next = False
                        break
                    if program.options.startinorder and program.name == pheaders[
                            'processname'] and program.options.startnextafter == state:
                        if program.options.startnext:
                            log.info(
                                "Recieved process state of {} from {}, starting next process."
                                .format(state, program.name))
                            start_next = True
                        else:
                            log.info(
                                "Recieved process state of {} from {}, with startnext set to false."
                                .format(state, program.name))
                            log.info(
                                "No more processes to start for initial startup, ignoring all future events."
                            )
                            initial_start = 'FINISHED'
                            break
                else:
                    if start_next:
                        log.info(
                            "No more processes to start for initial startup, ignoring all future events."
                        )
                        initial_start = 'FINISHED'
                #log.debug("data = {}".format(repr(pdata)))
            childutils.listener.ok()
    except:
        log.error("ERROR: ", exc_info=sys.exc_info())
Ejemplo n.º 33
0
def main(argv=sys.argv):
    import getopt
    short_args = "hp:at:c:b:s:m:g:d:eE"
    long_args = [
        "help",
        "program=",
        "any",
        "timeout=",
        "code=",
        "body=",
        "sendmail_program=",
        "email=",
        "gcore=",
        "coredir=",
        "eager",
        "not-eager",
    ]
    arguments = argv[1:]
    try:
        opts, args = getopt.getopt(arguments, short_args, long_args)
    except:
        usage()

    if not args:
        usage()
    if len(args) > 1:
        usage()

    programs = []
    any = False
    sendmail = '/usr/sbin/sendmail -t -i'
    gcore = '/usr/bin/gcore -o'
    coredir = None
    eager = True
    email = None
    timeout = 10
    retry_time = 10
    status = '200'
    inbody = None

    for option, value in opts:

        if option in ('-h', '--help'):
            usage()

        if option in ('-p', '--program'):
            programs.append(value)

        if option in ('-a', '--any'):
            any = True

        if option in ('-s', '--sendmail_program'):
            sendmail = value

        if option in ('-m', '--email'):
            email = value

        if option in ('-t', '--timeout'):
            timeout = int(value)

        if option in ('-c', '--code'):
            status = value

        if option in ('-b', '--body'):
            inbody = value

        if option in ('-g', '--gcore'):
            gcore = value

        if option in ('-d', '--coredir'):
            coredir = value

        if option in ('-e', '--eager'):
            eager = True

        if option in ('-E', '--not-eager'):
            eager = False

    url = arguments[-1]

    try:
        rpc = childutils.getRPCInterface(os.environ)
    except KeyError as e:
        if e.args[0] != 'SUPERVISOR_SERVER_URL':
            raise
        sys.stderr.write('httpok must be run as a supervisor event '
                         'listener\n')
        sys.stderr.flush()
        return

    prog = HTTPOk(rpc, programs, any, url, timeout, status, inbody, email,
                  sendmail, coredir, gcore, eager, retry_time)
    prog.runforever()
def get_supervisor():
    return childutils.getRPCInterface({
        'SUPERVISOR_SERVER_URL':
        'unix:///tmp/vpnsupervisor.sock'
    }).supervisor
Ejemplo n.º 35
0
def main():
    
    rpc = childutils.getRPCInterface(conf)
    prog = Dispatcher(rpc)
    prog.run()
Ejemplo n.º 36
0
def main():
    import getopt
    short_args = "hp:g:a:s:m:n:u:t"
    long_args = [
        "help",
        "program=",
        "group=",
        "any=",
        "sendmail_program=",
        "email=",
        "uptime=",
        "name=",
    ]
    arguments = sys.argv[1:]
    if not arguments:
        usage()
    try:
        opts, args = getopt.getopt(arguments, short_args, long_args)
    except:
        print __doc__
        sys.exit(2)

    programs = {}
    groups = {}
    any = None
    sendmail = '/usr/sbin/sendmail -t -i'
    email = None
    uptime = sys.maxint
    name = None
    tree = False

    for option, value in opts:

        if option in ('-h', '--help'):
            usage()

        if option in ('-p', '--program'):
            name, size = parse_namesize(option, value)
            programs[name] = size

        if option in ('-g', '--group'):
            name, size = parse_namesize(option, value)
            groups[name] = size

        if option in ('-a', '--any'):
            size = parse_size(option, value)
            any = size

        if option in ('-s', '--sendmail_program'):
            sendmail = value

        if option in ('-m', '--email'):
            email = value

        if option in ('-u', '--uptime'):
            uptime = parse_seconds(option, value)

        if option in ('-n', '--name'):
            name = value

        if option in ('-t', '--tree'):
            tree = True

    rpc = childutils.getRPCInterface(os.environ)
    memmon = Memmon(programs, groups, any, sendmail, email, name, uptime, rpc,
                    tree)
    memmon.runforever()
Ejemplo n.º 37
0
 def __init__(self, events: Dict[str, List[CronEvent]]):
     self.events = events
     self.rpc = childutils.getRPCInterface(os.environ)
     self.stdin = sys.stdin
     self.stdout = sys.stdout
     self.stderr = sys.stderr
Ejemplo n.º 38
0
 def test_getRPCInterface(self):
     from supervisor.childutils import getRPCInterface
     rpc = getRPCInterface(
         {'SUPERVISOR_SERVER_URL': 'http://localhost:9001'})
     # we can't really test this thing; its a magic object
     self.assertTrue(rpc is not None)