def Reload(self, serviceNames):
        """Reload services. Use names, not full guids."""
        self._BuildClassMap()
        if not serviceNames:
            return
        self.LogWarn('Reloading services: %s' % ', '.join(serviceNames))
        for each in serviceNames:
            if each not in self.services:
                continue
            if getattr(self.services[each], '__update_on_reload__', True):
                continue
            ms = blue.MemStream()
            try:
                try:
                    self.StopService(each, 0, ms)
                finally:
                    if self.services.has_key(each):
                        del self.services[each]

                self.GetService(each, ms)
            except Exception:
                log.LogException('Trying to reload service: %s' % each)
                sys.exc_clear()

        self.LogWarn('Reloading services - Done')
예제 #2
0
    def Reload(self, serviceList):
        import blue
        self._BuildClassMap()
        if len(serviceList):
            print 'Reloading services'
        for each in serviceList:
            if each not in self.services or each in self.services and getattr(
                    self.services[each], '__update_on_reload__', True):
                continue
            ms = blue.MemStream()
            try:
                try:
                    self.StopService(each, 0, ms)
                finally:
                    if self.services.has_key(each):
                        del self.services[each]

                self.GetService(each, ms)
            except Exception:
                log.LogException("Trying to reload service '%s" % each)
                sys.exc_clear()

        if len(serviceList):
            print 'Reloading services - Done'
예제 #3
0
 def HotStartService(self, serviceName):
     import blue
     ms = blue.MemStream()
     self.StopService(serviceName, ms)
     nasty.ReloadClass(self.ParseServiceClass(serviceName))
     self.StartService(serviceName, ms)
예제 #4
0
    def Stop(self):
        self.logChannel.Log('ServiceManager.Stop(), stopping services')
        dag = DAG()
        for k, v in self.services.iteritems():
            depends = v.__dependencies__ + getattr(
                v, '__exitdependencies__', []) + getattr(
                    v, '__startupdependencies__', [])
            for d in depends:
                if type(d) is not str:
                    d = d[0]
                if d in self.services:
                    dag.InsertEdge(k, d)

        dag.Invert()
        self.logChannel.Log('== BEGIN SERVICE LIST ==')
        order = []
        while dag.graph:
            leaves = dag.Leaves()
            if not leaves:
                break
            order.extend(leaves)
            for l in leaves:
                dag.RemoveNode(l)

            self.logChannel.Log('==leaves==')
            self.logChannel.Log(','.join(leaves))

        if dag.graph:
            leaves = dag.graph.keys()
            order.extend(leaves)
            self.logChannel.Log('==nonleaves==')
            self.logChannel.Log(','.join(leaves))
        self.logChannel.Log('== ENDOF SERVICE LIST ==')
        self.run = 0
        import blue
        old_block_trap = stackless.getcurrent().block_trap
        stackless.getcurrent().block_trap = 1
        self.state = service.SERVICE_STOP_PENDING
        try:
            for k in order:
                try:
                    v = self.services[k]
                except KeyError:
                    self.LogWarn(
                        'Warning, the service', k,
                        'has been stopped already but something that depends on it might still be running!'
                    )
                    sys.exc_clear()
                    continue

                if not hasattr(v, 'state'):
                    self.logChannel.Log(
                        "ServiceManager.Stop(), service '" + str(k) +
                        " doesn't have state therefore has already stopped")
                elif v.state not in (service.SERVICE_STOPPED,
                                     service.SERVICE_STOP_PENDING):
                    self.logChannel.Log(
                        "ServiceManager.Stop(), stopping service '" + str(k) +
                        "'")
                    try:
                        v.state = service.SERVICE_STOP_PENDING
                        for notify in v.__notifyevents__:
                            self.notify[notify].remove(v)

                        v.Stop(blue.MemStream())
                    except StandardError:
                        log.LogException()
                        sys.exc_clear()
                    finally:
                        v.state = service.SERVICE_STOPPED

                else:
                    self.logChannel.Log("ServiceManager.Stop(), service '" +
                                        str(k) + "' is already stopping")

        finally:
            stackless.getcurrent().block_trap = old_block_trap
            self.state = service.SERVICE_STOPPED

        for v in self.services.itervalues():
            for a in v.__dict__.keys():
                if a not in ('logChannel', 'logContexts', 'state'):
                    delattr(v, a)

        self.logChannel.Log('ServiceManager.Stop(), services stopped.')