Exemplo n.º 1
0
def main(args=None, options=None):
    if options is None:
        options = ClientOptions()
    options.realize(args, doc=__doc__)
    c = Controller(options)
    if options.args:
        c.onecmd(" ".join(options.args))
    if options.interactive:
        try:
            import readline
            if options.history_file:
                try:
                    readline.read_history_file(options.history_file)
                except IOError:
                    pass
                def save():
                    try:
                        readline.write_history_file(options.history_file)
                    except IOError:
                        pass
                import atexit
                atexit.register(save)
        except ImportError:
            pass
        try:
            c.cmdqueue.append('status')
            c.cmdloop()
        except KeyboardInterrupt:
            c.output('')
            pass
Exemplo n.º 2
0
    def test_real_controller_initialization(self):
        from supervisor.options import ClientOptions
        args = []  # simulating starting without parameters
        options = ClientOptions()

        # No default config file search in case they would exist
        self.assertTrue(len(options.searchpaths) > 0)
        options.searchpaths = []

        options.realize(args, doc=__doc__)
        c = self._makeOne(options)
Exemplo n.º 3
0
    def test_real_controller_initialization(self):
        from supervisor.options import ClientOptions
        args = [] # simulating starting without parameters
        options = ClientOptions()

        # No default config file search in case they would exist
        self.assertTrue(len(options.searchpaths) > 0)
        options.searchpaths = []

        options.realize(args, doc=__doc__)
        c = self._makeOne(options)
Exemplo n.º 4
0
def main(args=None, options=None):
    if options is None:
        options = ClientOptions()

    options.realize(args, doc=__doc__)
    c = Controller(options)

    if options.args:
        c.onecmd(" ".join(options.args))

    if options.interactive:
        c.exec_cmdloop(args, options)
Exemplo n.º 5
0
def shutdown(**kwargs):
    supervisor_args = get_supervisor_args(kwargs)
    options = ClientOptions()
    options.realize(args=supervisor_args)
    try:
        rpc = get_rpc(options)
        rpc.supervisor.shutdown()
        print >> sys.stderr, "Shutting down supervisor"
    except socket.error:
        print >> sys.stderr, "Supervisor already shut down"
    except xmlrpclib.Fault as e:
        if e.faultString == 'SHUTDOWN_STATE':
            print >> sys.stderr, "Supervisor already shutting down"
Exemplo n.º 6
0
def shutdown(**kwargs):
    supervisor_args = get_supervisor_args(kwargs)
    options = ClientOptions()
    options.realize(args=supervisor_args)
    try:
        rpc = get_rpc(options)
        rpc.supervisor.shutdown()
        print >> sys.stderr, "Shutting down supervisor"
    except socket.error:
        print >> sys.stderr, "Supervisor already shut down"
    except xmlrpclib.Fault as e:
        if e.faultString == 'SHUTDOWN_STATE':
            print >> sys.stderr, "Supervisor already shutting down"
Exemplo n.º 7
0
def up(*args, **kwargs):
    if not args:
        args = sys.argv[1:]
    supervisor_args = get_supervisor_args(kwargs)
    options = ClientOptions()
    options.realize(args=supervisor_args)
    status = "init"
    while 1:
        try:
            rpc = get_rpc(options)
            rpc.supervisor.getPID()
            if status == 'shutdown':
                sys.stderr.write("\n")
            break
        except socket.error:
            if status == 'shutdown':
                sys.stderr.write("\n")
            sys.stderr.write("Starting supervisord\n")
            supervisord = find_supervisord()
            cmd = [supervisord] + supervisor_args
            retcode = subprocess.call(cmd)
            if retcode != 0:
                sys.exit(retcode)
            status = 'starting'
        except xmlrpclib.Fault as e:
            if e.faultString == 'SHUTDOWN_STATE':
                if status == 'init':
                    sys.stderr.write("Supervisor currently shutting down ")
                    sys.stderr.flush()
                    status = 'shutdown'
                else:
                    sys.stderr.write(".")
                    sys.stderr.flush()
                time.sleep(1)
    if len(args):
        for name in args:
            info = rpc.supervisor.getProcessInfo(name)
            if info['statename'] != 'RUNNING':
                print "Starting %s" % name
                try:
                    rpc.supervisor.startProcess(name)
                except xmlrpclib.Fault as e:
                    if e.faultCode == 60:  # already started
                        continue
                    print >> sys.stderr, e.faultCode, e.faultString
                    sys.exit(1)
            else:
                print >> sys.stderr, "%s is already running" % name
Exemplo n.º 8
0
def down(*args, **kwargs):
    if not args:
        args = sys.argv[1:]
    supervisor_args = get_supervisor_args(kwargs)
    options = ClientOptions()
    options.realize(args=supervisor_args)
    status = "init"
    while 1:
        try:
            rpc = get_rpc(options)
            rpc.supervisor.getPID()
            if status == 'shutdown':
                sys.stderr.write("\n")
            break
        except socket.error:
            if status == 'shutdown':
                sys.stderr.write("\n")
            sys.stderr.write("Starting supervisord\n")
            supervisord = find_supervisord()
            cmd = [supervisord] + supervisor_args
            retcode = subprocess.call(cmd)
            if retcode != 0:
                sys.exit(retcode)
            status = 'starting'
        except xmlrpclib.Fault as e:
            if e.faultString == 'SHUTDOWN_STATE':
                if status == 'init':
                    sys.stderr.write("Supervisor currently shutting down ")
                    sys.stderr.flush()
                    status = 'shutdown'
                else:
                    sys.stderr.write(".")
                    sys.stderr.flush()
                time.sleep(1)
    if len(args):
        for name in args:
            info = rpc.supervisor.getProcessInfo(name)
            if info['statename'] != 'STOPPED':
                print "Stopping %s" % name
                try:
                    rpc.supervisor.stopProcess(name)
                except xmlrpclib.Fault as e:
                    # if e.faultCode == 60:  # already stopped
                    #     continue
                    print >> sys.stderr, e.faultCode, e.faultString
                    sys.exit(1)
            else:
                print >> sys.stderr, "%s is already stopped" % name
def main(args=None,options=None):
  if options is None:
    options = ClientOptions()
  options.realize(args,doc=__doc__)
  ctl = Controller(options)
  if len(options.args) != 1:
    ctl.output_error('Invalid number of arguments (expected 1, got %d)' % len(options.args))
    sys.exit(5)
  ctl.upcheck()

  group = options.args[0].strip()
  restarter = ctl.get_restarter()
  result = None

  while 1:
    try:
      result = send_restart(group,options=options,ctl=ctl,restarter=restarter)
    except xmlrpclib.ProtocolError,e:
      if e.errcode == 401:
        if options.interactive:
          from getpass import getpass
          ctl.output('Server requires authentication')
          username = raw_input('Username:'******'Password:'******'')
          options.username = username
          options.password = password
          continue
        else:
          options.usage('Server requires authentication')
      else:
        ctl.output_error('%s: protocol error (%s)' % (group,e))
        sys.exit(10)
    break
Exemplo n.º 10
0
def main(args=None, options=None):
    if options is None:
        options = ClientOptions()
    options.realize(args, doc=__doc__)
    c = Controller(options)
    if options.args:
        c.onecmd(" ".join(options.args))
    if options.interactive:
        try:
            import readline

            delims = readline.get_completer_delims()
            delims = delims.replace(":", "")  # "group:process" as one word
            delims = delims.replace("*", "")  # "group:*" as one word
            delims = delims.replace("-", "")  # names with "-" as one word
            readline.set_completer_delims(delims)

            if options.history_file:
                try:
                    readline.read_history_file(options.history_file)
                except IOError:
                    pass

                def save():
                    try:
                        readline.write_history_file(options.history_file)
                    except IOError:
                        pass

                import atexit

                atexit.register(save)
        except ImportError:
            pass
        try:
            c.cmdqueue.append("status")
            c.cmdloop()
        except KeyboardInterrupt:
            c.output("")
            pass
Exemplo n.º 11
0
def supervisorctl_main(args=None, options=None, **kwargs):
    """
    Initializes the supervisorctl with input redirect (stdin),
     output (stdout), and errors (stderr)
    """
    if options is None:
        options = ClientOptions()

    stdout = kwargs.get('stdout')
    stderr = kwargs.get('stderr')
    stdin = kwargs.get('stdin')

    if stdout is not None:
        options.stdout = stdout

    if stderr is not None:
        options.stderr = stderr

    options.realize(args, doc=__doc__)
    c = Controller(options, stdin=stdin, stdout=stdout)
    if options.args:
        c.onecmd(" ".join(options.args))

    if options.interactive:
        c.exec_cmdloop(args, options)
Exemplo n.º 12
0
def main(args=None, options=None):
    if options is None:
        options = ClientOptions()
    options.realize(args, doc=__doc__)
    c = Controller(options)
    if options.args:
        c.onecmd(" ".join(options.args))
    if options.interactive:
        try:
            import readline
            delims = readline.get_completer_delims()
            delims = delims.replace(':', '')  # "group:process" as one word
            delims = delims.replace('*', '')  # "group:*" as one word
            delims = delims.replace('-', '')  # names with "-" as one word
            readline.set_completer_delims(delims)

            if options.history_file:
                try:
                    readline.read_history_file(options.history_file)
                except IOError:
                    pass

                def save():
                    try:
                        readline.write_history_file(options.history_file)
                    except IOError:
                        pass

                import atexit
                atexit.register(save)
        except ImportError:
            pass
        try:
            c.cmdqueue.append('status')
            c.cmdloop()
        except KeyboardInterrupt:
            c.output('')
            pass
Exemplo n.º 13
0
def start(program):
    args = ["start", program]
    options = ClientOptions()
    options.realize(args)
    c = Controller(options)
    c.onecmd(" ".join(options.args))
Exemplo n.º 14
0
 def __init__(self, context):
     options = ClientOptions()
     options.realize([])
     self.supervisor = options.getServerProxy().supervisor