def __init__(self): if self.service_name == '': raise RequireSubclass() if self.service_name in services().keys(): raise ServiceAlreadyExist(self.service_name) self.result_deferred = None automat.Automat.__init__(self, self.service_name, 'OFF', 12)
def doStartService(self, arg): """ Action method. """ if not self.installed(): self.automat('service-not-installed') return depends_results = [] for depend_name in self.dependent_on(): depend_service = services().get(depend_name, None) if depend_service is None: depends_results.append((depend_name, 'not found')) continue if depend_service.state != 'ON': depends_results.append((depend_name, 'not started')) continue if len(depends_results) > 0: self.automat('service-depend-off', depends_results) return lg.out(2, '[%s] STARTING' % self.service_name) try: result = self.start() except: lg.exc() self.automat('service-failed', 'exception when starting') return if isinstance(result, Deferred): result.addCallback(lambda x: self.automat('service-started')) result.addErrback(lambda x: self.automat('service-failed', x)) return if result: self.automat('service-started') else: self.automat('service-failed', 'result is %r' % result)
def __init__(self): if self.service_name == '': raise RequireSubclass() if self.service_name in services().keys(): raise ServiceAlreadyExist(self.service_name) self.result_deferred = None automat.Automat.__init__(self, self.service_name, 'OFF', _DebugLevel, _Debug)
def isAllDependsStopped(self, arg): """ Condition method. """ for svc in services().values(): if self.service_name in svc.dependent_on(): if svc.state != 'OFF' and \ svc.state != 'DEPENDS_OFF' and \ svc.state != 'NOT_INSTALLED': return False return True
def doStopDependentServices(self, arg): """ Action method. """ count = 0 for svc in services().values(): if self.service_name in svc.dependent_on(): lg.out(6, '%r sends "stop" to %r' % (self, svc)) svc.automat('stop') count += 1 if count == 0: self.automat('depend-service-stopped')
def __init__(self): if self.service_name == '': raise RequireSubclass() if self.service_name in services().keys(): raise ServiceAlreadyExist(self.service_name) self.result_deferred = None automat.Automat.__init__( self, name=self.service_name, state='OFF', debug_level=_DebugLevel, log_events=_Debug, log_transitions=_Debug, )