Ejemplo n.º 1
0
 def _assertInState(self, *states):
     if self.state not in states:
         current_state = getProcessStateDescription(self.state)
         allowable_states = " ".join(map(getProcessStateDescription, states))
         raise AssertionError(
             "Assertion failed for %s: %s not in %s" % (self.config.name, current_state, allowable_states)
         )
Ejemplo n.º 2
0
 def _assertInState(self, *states):
     if self.state not in states:
         current_state = getProcessStateDescription(self.state)
         allowable_states = ' '.join(map(getProcessStateDescription, states))
         processname = as_string(self.config.name)
         raise AssertionError('Assertion failed for %s: %s not in %s' %  (
             processname, current_state, allowable_states))
Ejemplo n.º 3
0
 def _assertInState(self, *states):
     if self.state not in states:
         current_state = getProcessStateDescription(self.state)
         allowable_states = ' '.join(map(getProcessStateDescription, states))
         self.config.options.logger.error("Assertion ERROR: current_state(%s) not in expected(%s)" % current_state, allowable_states)
         raise AssertionError('Assertion failed for %s: %s not in %s' %  (
             self.config.name, current_state, allowable_states))
Ejemplo n.º 4
0
 def payload(self):
     groupname = ''
     if self.process.group is not None:
         groupname = self.process.group.config.name
     L = [('processname', self.process.config.name), ('groupname', groupname),
          ('from_state', getProcessStateDescription(self.from_state))]
     L.extend(self.extra_values)
     s = ' '.join( [ '%s:%s' % (name, val) for (name, val) in L ] )
     return s
Ejemplo n.º 5
0
 def __repr__(self):
     # repr can't return anything other than a native string,
     # but the name might be unicode - a problem on Python 2.
     name = self.config.name
     if PY2:
         name = as_string(name).encode('unicode-escape')
     return '<Subprocess at %s with name %s in state %s>' % (
         id(self),
         name,
         getProcessStateDescription(self.get_state()))
Ejemplo n.º 6
0
 def __str__(self):
     groupname = ''
     if self.process.group is not None:
         groupname = self.process.group.config.name
     L = []
     L.append(('processname', self.process.config.name))
     L.append(('groupname', groupname))
     L.append(('from_state', getProcessStateDescription(self.from_state)))
     L.extend(self.extra_values)
     s = ' '.join(['%s:%s' % (name, val) for (name, val) in L])
     return s
Ejemplo n.º 7
0
    def updateProcess(self, process, state, pid):
        if not self.connection.connected:
            return
        if process.group.config.name in self.deletedGroups:
            self.logger.warn("Not updating process %s in deleted group %s" %
                             (process.config.name, process.group.config.name))
            return
        newstate = state if state is not None else process.get_state()
        newpid = pid or process.pid

        self.logger.info("Updating process %s %s %s" %
                         (process.config.name,
                          states.getProcessStateDescription(newstate), newpid))

        p = Process(self.supervisorid, self.host, self.env, self.subEnv,
                    process, newstate, newpid)
        self.connection.updateProcess(p)
Ejemplo n.º 8
0
    def __init__(self,
                 supervisorid=None,
                 host=None,
                 env=None,
                 subEnv=None,
                 process=None,
                 state=None,
                 pid=None):
        # Note: changing member variable names will change the json object property names used in the server messages
        self.supervisorid = supervisorid
        self.host = host
        self.env = env
        self.subEnv = subEnv
        self.since = time.time() * 1000
        self.updateTime = time.time() * 1000

        if process is not None:
            pconfig = process.config
            gconfig = process.group.config

            self.group = gconfig.name
            self.name = pconfig.name
            self.pid = pid or process.pid
            self.childpids = ""
            self.start = process.laststart * 1000
            self.stop = process.laststop * 1000
            self.state = state if state is not None else process.get_state()
            self.since = max(process.laststart, process.laststop) * 1000
            self.statename = states.getProcessStateDescription(self.state)
            self.spawnerr = process.spawnerr or ''
            self.exitstatus = process.exitstatus or 0
            self.command = pconfig.command
            self.uid = pconfig.uid or os.getuid()
            self.username = self.resolveUsername(self.uid)
            self.directory = pconfig.directory
            self.autostart = pconfig.autostart
            self.startsecs = pconfig.startsecs
            self.startretries = pconfig.startretries
            self.stopsignal = pconfig.stopsignal
            self.stopwaitsecs = pconfig.stopwaitsecs
            self.exitcodes = str(pconfig.exitcodes)
            self.stdout_logfile = pconfig.stdout_logfile
            self.stderr_logfile = pconfig.stderr_logfile
            self.environmentVars = pconfig.environment
            self.subEnv = pconfig.environment.get("SUPER_SUB_ENV", subEnv)
Ejemplo n.º 9
0
    def getProcessInfo(self, name):
        """ Get info about a process named name

        @param string name The name of the process (or 'group:name')
        @return struct result     A structure containing data about the process
        """
        self._update('getProcessInfo')

        group, process = self._getGroupAndProcess(name)

        if process is None:
            raise RPCError(Faults.BAD_NAME, name)

        # TODO timestamps are returned as xml-rpc integers for b/c but will
        # saturate the xml-rpc integer type in jan 2038 ("year 2038 problem").
        # future api versions should return timestamps as a different type.
        start = capped_int(process.laststart)
        stop = capped_int(process.laststop)
        now = capped_int(self._now())

        state = process.get_state()
        spawnerr = process.spawnerr or ''
        exitstatus = process.exitstatus or 0
        stdout_logfile = process.config.stdout_logfile or ''
        stderr_logfile = process.config.stderr_logfile or ''

        info = {
            'name':process.config.name,
            'group':group.config.name,
            'start':start,
            'stop':stop,
            'now':now,
            'state':state,
            'statename':getProcessStateDescription(state),
            'spawnerr':spawnerr,
            'exitstatus':exitstatus,
            'logfile':stdout_logfile, # b/c alias
            'stdout_logfile':stdout_logfile,
            'stderr_logfile':stderr_logfile,
            'pid':process.pid,
            }

        description = self._interpretProcessInfo(info)
        info['description'] = description
        return info
Ejemplo n.º 10
0
    def getProcessInfo(self, name):
        """ Get info about a process named name

        @param string name The name of the process (or 'group:name')
        @return struct result     A structure containing data about the process
        """
        self._update('getProcessInfo')

        group, process = self._getGroupAndProcess(name)

        if process is None:
            raise RPCError(Faults.BAD_NAME, name)

        # TODO timestamps are returned as xml-rpc integers for b/c but will
        # saturate the xml-rpc integer type in jan 2038 ("year 2038 problem").
        # future api versions should return timestamps as a different type.
        start = capped_int(process.laststart)
        stop = capped_int(process.laststop)
        now = capped_int(self._now())

        state = process.get_state()
        spawnerr = process.spawnerr or ''
        exitstatus = process.exitstatus or 0
        stdout_logfile = process.config.stdout_logfile or ''
        stderr_logfile = process.config.stderr_logfile or ''

        info = {
            'name':process.config.name,
            'group':group.config.name,
            'start':start,
            'stop':stop,
            'now':now,
            'state':state,
            'statename':getProcessStateDescription(state),
            'spawnerr':spawnerr,
            'exitstatus':exitstatus,
            'logfile':stdout_logfile, # b/c alias
            'stdout_logfile':stdout_logfile,
            'stderr_logfile':stderr_logfile,
            'pid':process.pid,
            }

        description = self._interpretProcessInfo(info)
        info['description'] = description
        return info
Ejemplo n.º 11
0
    def shutdown_report(self):
        unstopped = []

        for group in self.process_groups.values():
            unstopped.extend(group.get_unstopped_processes())

        if unstopped:
            # throttle 'waiting for x to die' reports
            now = time.time()
            if now > (self.lastshutdownreport + 3):  # every 3 secs
                names = [p.config.name for p in unstopped]
                namestr = ', '.join(names)
                self.options.logger.info('waiting for %s to die' % namestr)
                self.lastshutdownreport = now
                for proc in unstopped:
                    state = getProcessStateDescription(proc.get_state())
                    self.options.logger.blather('%s state: %s' % (proc.config.name, state))
        return unstopped
Ejemplo n.º 12
0
    def getProcessInfo(self, name):
        """ Get info about a process named name

        :param name: The name of the process (or 'group:name')
        :type name: string
        :return: A structure containing data about the process
        :rtype: struct
        """
        self._update('getProcessInfo')

        group, process = self._getGroupAndProcess(name)

        if process is None:
            raise RPCError(Faults.BAD_NAME, name)

        start = int(process.laststart)
        stop = int(process.laststop)
        now = int(time.time())

        state = process.get_state()
        spawnerr = process.spawnerr or ''
        exitstatus = process.exitstatus or 0
        stdout_logfile = process.config.stdout_logfile or ''
        stderr_logfile = process.config.stderr_logfile or ''

        info = {
            'name':process.config.name,
            'group':group.config.name,
            'start':start,
            'stop':stop,
            'now':now,
            'state':state,
            'statename':getProcessStateDescription(state),
            'spawnerr':spawnerr,
            'exitstatus':exitstatus,
            'logfile':stdout_logfile, # b/c alias
            'stdout_logfile':stdout_logfile,
            'stderr_logfile':stderr_logfile,
            'pid':process.pid,
            }

        description = self._interpretProcessInfo(info)
        info['description'] = description
        return info
Ejemplo n.º 13
0
    def getProcessInfo(self, name):
        """ Get info about a process named name

        @param string name The name of the process (or 'group:name')
        @return struct result     A structure containing data about the process
        """
        self._update('getProcessInfo')

        group, process = self._getGroupAndProcess(name)
        if process is None:
            return self._getGroupProcessInfo(group)

        if process is None:
            raise RPCError(Faults.BAD_NAME, name)

        start = int(process.laststart)
        stop = int(process.laststop)
        now = int(time.time())

        state = process.get_state()
        spawnerr = process.spawnerr or ''
        exitstatus = process.exitstatus or 0
        stdout_logfile = process.config.stdout_logfile or ''
        stderr_logfile = process.config.stderr_logfile or ''

        info = {
            'name': process.config.name,
            'group': group.config.name,
            'start': start,
            'stop': stop,
            'now': now,
            'state': state,
            'statename': getProcessStateDescription(state),
            'spawnerr': spawnerr,
            'exitstatus': exitstatus,
            'logfile': stdout_logfile,  # b/c alias
            'stdout_logfile': stdout_logfile,
            'stderr_logfile': stderr_logfile,
            'pid': process.pid,
        }

        description = self._interpretProcessInfo(info)
        info['description'] = description
        return info
Ejemplo n.º 14
0
    def shutdown_report(self):
        unstopped = []

        for group in self.process_groups.values():
            unstopped.extend(group.get_unstopped_processes())

        if unstopped:
            # throttle 'waiting for x to die' reports
            now = time.time()
            if now > (self.lastshutdownreport + 3): # every 3 secs
                names = [ as_string(p.config.name) for p in unstopped ]
                namestr = ', '.join(names)
                self.options.logger.info('waiting for %s to die' % namestr)
                self.lastshutdownreport = now
                for proc in unstopped:
                    state = getProcessStateDescription(proc.get_state())
                    self.options.logger.blather(
                        '%s state: %s' % (proc.config.name, state))
        return unstopped
Ejemplo n.º 15
0
    def getProcessInfo(self, name):
        """ Get info about a process named name

        @param string name The name of the process (or 'group:name')
        @return struct result     A structure containing data about the process
        """
        self._update("getProcessInfo")

        group, process = self._getGroupAndProcess(name)

        if process is None:
            raise RPCError(Faults.BAD_NAME, name)

        start = int(process.laststart)
        stop = int(process.laststop)
        now = int(time.time())

        state = process.get_state()
        spawnerr = process.spawnerr or ""
        exitstatus = process.exitstatus or 0
        stdout_logfile = process.config.stdout_logfile or ""
        stderr_logfile = process.config.stderr_logfile or ""

        info = {
            "name": process.config.name,
            "group": group.config.name,
            "start": start,
            "stop": stop,
            "now": now,
            "state": state,
            "statename": getProcessStateDescription(state),
            "spawnerr": spawnerr,
            "exitstatus": exitstatus,
            "logfile": stdout_logfile,  # b/c alias
            "stdout_logfile": stdout_logfile,
            "stderr_logfile": stderr_logfile,
            "pid": process.pid,
        }

        description = self._interpretProcessInfo(info)
        info["description"] = description
        return info
Ejemplo n.º 16
0
    def getProcessInfo(self, name):
        """ Get info about a process named name

        @param string name The name of the process (or 'group:name')
        @return struct result     A structure containing data about the process
        """
        self._update('getProcessInfo')

        group, process = self._getGroupAndProcess(name)

        start = int(process.laststart)
        stop = int(process.laststop)
        now = int(time.time())
        
        state = process.get_state()
        spawnerr = process.spawnerr or ''
        exitstatus = process.exitstatus or 0
        stdout_logfile = process.config.stdout_logfile or ''
        stderr_logfile = process.config.stderr_logfile or ''

        info = {
            'name':process.config.name,
            'group':group.config.name,
            'start':start,
            'stop':stop,
            'now':now,
            'state':state,
            'statename':getProcessStateDescription(state),
            'spawnerr':spawnerr,
            'exitstatus':exitstatus,
            'logfile':stdout_logfile, # b/c alias
            'stdout_logfile':stdout_logfile,
            'stderr_logfile':stderr_logfile,
            'restartsignal': process.config.restartsignal,
            'pid':process.pid,
            }
        
        description = self._interpretProcessInfo(info)
        info['description'] = description
        return info
Ejemplo n.º 17
0
def _get_state_desc(state):
  desc = getProcessStateDescription(state)
  if desc:
    return desc
  return str(state)
Ejemplo n.º 18
0
 def __repr__(self):
     return '<Subprocess at %s with name %s in state %s>' % (
         id(self),
         self.config.name,
         getProcessStateDescription(self.get_state()))
Ejemplo n.º 19
0
 def _assertInState(self, *states):
     if self.state not in states:
         current_state = getProcessStateDescription(self.state)
         allowable_states = ' '.join(map(getProcessStateDescription, states))
         raise AssertionError('Assertion failed for %s: %s not in %s' %  (
             self.config.name, current_state, allowable_states))
 def getProcessStateDescription(self, process=None, state=None):  # noqa: N802 (lowercase)
     if process is not None:
         return getProcessStateDescription(self.processes[process].state)
     else:
         return getProcessStateDescription(state)
Ejemplo n.º 21
0
 def test_getProcessStateDescription_returns_string_when_found(self):
     state = states.ProcessStates.STARTING
     self.assertEqual(states.getProcessStateDescription(state),
         'STARTING')
Ejemplo n.º 22
0
 def test_getProcessStateDescription_returns_None_when_not_found(self):
     self.assertEqual(states.getProcessStateDescription(3.14159),
         None)
Ejemplo n.º 23
0
 def test_getProcessStateDescription_returns_string_when_found(self):
     state = states.ProcessStates.STARTING
     self.assertEqual(states.getProcessStateDescription(state), 'STARTING')
Ejemplo n.º 24
0
 def __repr__(self):
     return '<Subprocess at %s with name %s in state %s>' % (
         id(self), self.config.name,
         getProcessStateDescription(self.get_state()))
Ejemplo n.º 25
0
 def test_getProcessStateDescription_returns_None_when_not_found(self):
     self.assertEqual(states.getProcessStateDescription(3.14159), None)