def startService(self): if self.loop != -1 or self._state == 'started': msg(self.name, 'start fail - already started', system='-') # Already started return # State self._state = 'starting' # Show info msg(self.name, 'start', system='-') # Cancel stop if self._stopCall: self._stopCall.cancel() self._stopCall = None # Call stop self._stopDeferred.callback(0) self._stopDeferred = None Service.startService(self) self.loop = 0 self._state = 'started' # Start for name, (run, interval) in self._runs.iteritems(): run.start(interval, now=False) # Show info msg(self.name, 'started', system='-')
def stopService(self): print 'Stop PullRequest service: %s ...' % self.context.name Service.stopService(self) if self.watchLoop: self.watchLoop.stop() if self.schedulerLoop: self.schedulerLoop.stop()
def s2(code, self=self): try: if code != 1: # Cancel stop return if not (self._state == 'stopping' and (self._process + self._workers) == 0): err(RuntimeError('{0} stop error: state-{1} p{2} w{3}'.format( self.name, self._state, self._process, self._workers, ))) self._stopCall = None self._stopDeferred = None # Inside Service.stopService(self) self._state = 'stopped' # Show info msg(self.name, 'stopped', system='-') except: err()
def startService(self, _reactor=reactor): assert not self._already_started, "can start the PullRequest service once" self._already_started = True Service.startService(self) print 'PullRequest service starting: %s ...' % self.context.name d = defer.Deferred() _reactor.callWhenRunning(d.callback, None) yield d try: from .serviceloops import PullRequestsWatchLoop, SchedulerLoop self.watchLoop = PullRequestsWatchLoop(self.context) yield self.watchLoop.start() self.schedulerLoop = SchedulerLoop(self.context) yield self.schedulerLoop.start(); except: f = failure.Failure() log.err(f, 'while starting PullRequest service: %s' % self.context.name) _reactor.stop() log.msg('PullRequest service is running: %s' % self.context.name)
def stopService(self): ntasks = len(self._tasks) for task in self.iterTasks(): task.close() self._tasks = set() Service.stopService(self) logger.debug("stopped scheduler (%i tasks killed)" % ntasks)
def startService(self): """ Called when the plugin is started. If a plugin needs to perform any startup tasks, they should override this method (be sure to chain up to the parent method) and perform them here. """ Service.startService(self)
def stopService(self): if self.running: Service.stopService(self) log.info("Stopping master heartbeat service...") return self._hb.stop() else: return defer.succeed(None)
def startService(self): """ Make sure that the necessary properties are set on the root Flocker zfs storage pool. """ Service.startService(self) # These next things are logically part of the storage pool creation # process. Since Flocker itself doesn't yet have any involvement with # that process, it's difficult to find a better time/place to set these # properties than here - ie, "every time we're about to interact with # the storage pool". In the future it would be better if we could do # these things one-off - sometime around when the pool is created or # when Flocker is first installed, for example. Then we could get rid # of these operations from this method (which eliminates the motivation # for StoragePool being an IService implementation). # https://clusterhq.atlassian.net/browse/FLOC-635 # Set the root dataset to be read only; IService.startService # doesn't support Deferred results, and in any case startup can be # synchronous with no ill effects. _sync_command_error_squashed( [b"zfs", b"set", b"readonly=on", self._name], self.logger) # If the root dataset is read-only then it's not possible to create # mountpoints in it for its child datasets. Avoid mounting it to avoid # this problem. This should be fine since we don't ever intend to put # any actual data into the root dataset. _sync_command_error_squashed( [b"zfs", b"set", b"canmount=off", self._name], self.logger)
def startService(self): Service.startService(self) self.configuration.load() self.connectionRegistry = \ ConnectionRegistry( self.createConfiguredDeviceMap()) self.timer.start(self.updateInterval).addErrback(log.err) self.statusIcon.show()
def startService(self): Service.startService(self) log.info("Starting RPC service...") self.cleanSocket(None) self._localPort=reactor.listenUNIX(core.cfg['UNIX_PORT'], pb.PBServerFactory(LocalRPC(self._master))) self._remotePort=reactor.listenTCP(core.cfg['TCP_PORT'], pb.PBServerFactory(RemoteRPC(self._master)))
def stopService(self): """ Stop the service by calling stored function """ Service.stopService(self) if self._stop: return self._stop()
def startService(self): """ Start the service by calling stored function """ Service.startService(self) if self._start: return self._start()
def __init__(self): Service.__init__(self) self.seq = -1 self.freq = 4000 self.mag = 15.0 self.tamb = 3 self.tsky = self.tamb - 30
def startService(self): Service.startService(self) self._registered = False self._timer_service = TimerService( self.check_interval.total_seconds(), self._check_certs) self._timer_service.clock = self._clock self._timer_service.startService()
def stopService(self): Service.stopService(self) try: self.app.close() except Exception: logger.error('Error while closing application', exc_info=True) self._close_database()
def startService(self): Service.startService(self) # Now we're ready to build the command lines and actualy add the # processes to procmon. This step must be done prior to setting # active to 1 for processObject, env in self.processObjects: name = processObject.getName() self.addProcess( name, processObject.getCommandLine(), env=env ) self._extraFDs[name] = processObject.getFileDescriptors() self.active = 1 delay = 0 if config.MultiProcess.StaggeredStartup.Enabled: delay_interval = config.MultiProcess.StaggeredStartup.Interval else: delay_interval = 0 for name in self.processes.keys(): if name.startswith("caldav"): when = delay delay += delay_interval else: when = 0 callLater(when, self.startProcess, name) self.consistency = callLater( self.consistencyDelay, self._checkConsistency )
def stopService(self): """ Stop service by stopping the timerservice and disconnecting cass client """ Service.stopService(self) d = self._service.stopService() return d.addCallback(lambda _: self._client.disconnect())
def startService(self): app = self._prov_service.app dhcp_request_processing_service = self._dhcp_process_service.dhcp_request_processing_service if self._config['general.rest_authentication']: credentials = (self._config['general.rest_username'], self._config['general.rest_password']) server_resource = new_restricted_server_resource(app, dhcp_request_processing_service, credentials) logger.info('Authentication is required for REST API') else: server_resource = new_server_resource(app, dhcp_request_processing_service) logger.warning('No authentication is required for REST API') root_resource = Resource() root_resource.putChild('provd', server_resource) rest_site = Site(root_resource) port = self._config['general.rest_port'] interface = self._config['general.rest_ip'] if interface == '*': interface = '' logger.info('Binding HTTP REST API service to "%s:%s"', interface, port) if self._config['general.rest_ssl']: logger.info('SSL enabled for REST API') context_factory = ssl.DefaultOpenSSLContextFactory(self._config['general.rest_ssl_keyfile'], self._config['general.rest_ssl_certfile']) self._tcp_server = internet.SSLServer(port, rest_site, context_factory, interface=interface) else: self._tcp_server = internet.TCPServer(port, rest_site, interface=interface) self._tcp_server.startService() Service.startService(self)
def main(self): """Parse arguments and run the script's main function via ``react``.""" # If e.g. --version is called this may throw a SystemExit, so we # always do this first before any side-effecty code is run: options = self._parse_options(self.sys_module.argv[1:]) if self.logging: log_writer = eliot_logging_service( options.eliot_destination, self._reactor, True ) else: log_writer = Service() log_writer.startService() # XXX: We shouldn't be using this private _reactor API. See # https://twistedmatrix.com/trac/ticket/6200 and # https://twistedmatrix.com/trac/ticket/7527 def run_and_log(reactor): d = maybeDeferred(self.script.main, reactor, options) def got_error(failure): if not failure.check(SystemExit): err(failure) return failure d.addErrback(got_error) return d try: self._react(run_and_log, [], _reactor=self._reactor) finally: log_writer.stopService()
def startService(self): log.info("starting DBase Service") yield self.schema() self.startTasks() # Remainder Service initialization Service.startService(self) log.info("Database operational.")
def startService(self): ## this implementation of startService overrides the original if self.running: return Service.startService(self) pingFunc, args, kwargs = self.call def pingFail(failure): failure.trap(defer.TimeoutError) #print 'Call to %s timed out. Calling onTimeout and stopping service.' % (pingFunc.__name__,) self.onTimeout() self.stopService() def sendPing(): self.ping = defer.Deferred() ## the pingFunc is assumed to be a syncronous function that ## sends the request along to the client and returns immediately. ## TODO: maybe assume that this returns a deferred that is fired when ## the response is received? pingFunc(*args, **kwargs) self.ping.addErrback(pingFail) self.ping.setTimeout(self.step - 1) # timeout if no response before next iteration return self.ping ## LoopingCall will reschedule as soon as this fires self._loop = LoopingCall(sendPing) self._loop.start(self.step, now=self.now).addErrback(self._failed)
def stopService(self): try: file_cache_idxs = MetricCache.getAllFileCaches() writeCachedDataPointsWhenStop(file_cache_idxs) except Exception as e: log.err('write error when stopping service: %s' % e) Service.stopService(self)
def startService(self): """ """ Service.startService(self) from twisted.internet import reactor logger.debug("performing initial registration") for uri,system in self.known.items(): self.register_system(uri, system)
def startService(self): Service.startService(self) if self.clock is None: from twisted.internet import reactor self.clock = reactor self._connect()
def startService(self): # Pre: hasattr(self._prov_service, 'app') self.request_processing = provd.devices.ident.RequestProcessingService(self._prov_service.app) request_config_dir = self._config['general.request_config_dir'] for name in ['info_extractor', 'retriever', 'updater', 'router']: setattr(self.request_processing, 'dev_' + name, self._create_processor(request_config_dir, name, self._config['general.' + name])) Service.startService(self)
def startService(self): if 'signal' in globals().keys(): log.debug("Installing SIG_IGN for SIGHUP") signal.signal(signal.SIGHUP, signal.SIG_IGN) Service.startService(self) for factory in self.client_factories.values(): if not factory.started: factory.startConnecting()
def stopService(self): Service.stopService(self) self.ready = False self._registered = False for d in list(self._waiting): d.cancel() self._waiting = [] return self._timer_service.stopService()
def stopService(self): """ Stops the loop that fetches mail. """ if self._loop and self._loop.running is True: self._loop.stop() self._loop = None Service.stopService(self)
def startService(self): """ Start the writer thread. """ Service.startService(self) self._thread = threading.Thread(target=self._writer) self._thread.start() addDestination(self)
def stopService(self): Service.stopService(self) if self.__ws_port_obj is None: raise Exception('Not started, cannot stop') # TODO: Does Twisted already have something to bundle up a bunch of ports for shutdown? return defer.DeferredList([ self.__http_port_obj.stopListening(), self.__ws_port_obj.stopListening()])
def startService(self): self.storage_reload_task.start(60, False) self.aggregation_reload_task.start(60, False) reactor.addSystemEventTrigger('before', 'shutdown', shutdownModifyUpdateSpeed) reactor.callInThread(writeForever) Service.startService(self)
def stopService(self): self.reload_task.stop() Service.stopService(self)
def stopService(self): Service.stopService(self) self.clearAllTimers()
def startService(self): if settings.CARBON_METRIC_INTERVAL > 0: self.record_task.start(settings.CARBON_METRIC_INTERVAL, False) Service.startService(self)
def test_realService(self): """ Service implements IService. """ myService = Service() verifyObject(IService, myService)
def startService(self): Service.startService(self) for task, interval in self.tasks: task.start(interval, now=False)
def stopService(self): self.inspector.stop() Service.stopService(self)
def stopService(self): for task, interval in self.tasks: task.stop() Service.stopService(self)
def startService(self): self.logger.addObserver(self.sentry_log_observer) return Service.startService(self)
def stopService(self): for dest in self.destinations: remove_destination(dest) globalLogPublisher.removeObserver(self.twisted_observer) self.stdlib_cleanup() return Service.stopService(self)
def startService(self): self.stdlib_cleanup = _stdlib_logging_to_eliot_configuration(getLogger()) self.twisted_observer = _TwistedLoggerToEliotObserver() globalLogPublisher.addObserver(self.twisted_observer) add_destinations(*self.destinations) return Service.startService(self)
def _tub_maker(self, overrides): return Service()
def stopService(self): self.storage_reload_task.stop() self.aggregation_reload_task.stop() Service.stopService(self)
def startService(self): Service.startService(self) self.inspector.start()
def stopService(self): Service.stopService(self) return self.stop_result
def stopService(self): if settings.CARBON_METRIC_INTERVAL > 0: self.record_task.stop() Service.stopService(self)
def startService(self): Service.startService(self) if self.__ws_port_obj is not None: raise Exception('Already started') self.__ws_port_obj = strports.listen(self.__ws_port, self.__ws_protocol) self.__http_port_obj = strports.listen(self.__http_port, self.__site)
def stopService(self): # We don't need to call port.stopListening(), because the reactor # shutdown sequence will do that for us. Service.stopService(self) logging.info("%s stopped with config %s" % ( self.service_name.capitalize(), self.config.get_config_filename()))
class TestHTTPBootResource(MAASTestCase): run_tests_with = MAASTwistedRunTest.make_factory(timeout=5) def setUp(self): super().setUp() self.tftp = Service() self.tftp.setName("tftp") self.tftp.backend = Mock() self.tftp.backend.get_reader = Mock() self.tftp.setServiceParent(services) def teardown(): if self.tftp: self.tftp.disownServiceParent() self.tftp = None self.addCleanup(teardown) def render_GET(self, resource, request): result = resource.render_GET(request) if isinstance(result, bytes): request.write(result) request.finish() return succeed(None) elif result is NOT_DONE_YET: if request.finished: return succeed(None) else: return request.notifyFinish() else: raise ValueError("Unexpected return value: %r" % (result,)) @inlineCallbacks def test_render_GET_503_when_no_tftp_service(self): # Remove the fake 'tftp' service. self.tftp.disownServiceParent() self.tftp = None path = factory.make_name("path") ip = factory.make_ip_address() request = DummyRequest([path.encode("utf-8")]) request.requestHeaders = Headers( { "X-Server-Addr": ["192.168.1.1"], "X-Server-Port": ["5248"], "X-Forwarded-For": [ip], "X-Forwarded-Port": ["%s" % factory.pick_port()], } ) self.patch(http.log, "info") mock_deferLater = self.patch(http, "deferLater") mock_deferLater.side_effect = always_succeed_with(None) resource = http.HTTPBootResource() yield self.render_GET(resource, request) self.assertEquals(503, request.responseCode) self.assertEquals( b"HTTP boot service not ready.", b"".join(request.written) ) @inlineCallbacks def test_render_GET_400_when_no_local_addr(self): path = factory.make_name("path") ip = factory.make_ip_address() request = DummyRequest([path.encode("utf-8")]) request.requestHeaders = Headers( { "X-Forwarded-For": [ip], "X-Forwarded-Port": ["%s" % factory.pick_port()], } ) self.patch(http.log, "info") mock_deferLater = self.patch(http, "deferLater") mock_deferLater.side_effect = always_succeed_with(None) resource = http.HTTPBootResource() yield self.render_GET(resource, request) self.assertEquals(400, request.responseCode) self.assertEquals( b"Missing X-Server-Addr and X-Forwarded-For HTTP headers.", b"".join(request.written), ) @inlineCallbacks def test_render_GET_400_when_no_remote_addr(self): path = factory.make_name("path") request = DummyRequest([path.encode("utf-8")]) request.requestHeaders = Headers( {"X-Server-Addr": ["192.168.1.1"], "X-Server-Port": ["5248"]} ) self.patch(http.log, "info") mock_deferLater = self.patch(http, "deferLater") mock_deferLater.side_effect = always_succeed_with(None) resource = http.HTTPBootResource() yield self.render_GET(resource, request) self.assertEquals(400, request.responseCode) self.assertEquals( b"Missing X-Server-Addr and X-Forwarded-For HTTP headers.", b"".join(request.written), ) @inlineCallbacks def test_render_GET_403_access_violation(self): path = factory.make_name("path") ip = factory.make_ip_address() request = DummyRequest([path.encode("utf-8")]) request.requestHeaders = Headers( { "X-Server-Addr": ["192.168.1.1"], "X-Server-Port": ["5248"], "X-Forwarded-For": [ip], "X-Forwarded-Port": ["%s" % factory.pick_port()], } ) self.patch(http.log, "info") mock_deferLater = self.patch(http, "deferLater") mock_deferLater.side_effect = always_succeed_with(None) self.tftp.backend.get_reader.return_value = fail(AccessViolation()) resource = http.HTTPBootResource() yield self.render_GET(resource, request) self.assertEquals(403, request.responseCode) self.assertEquals(b"", b"".join(request.written)) @inlineCallbacks def test_render_GET_404_file_not_found(self): path = factory.make_name("path") ip = factory.make_ip_address() request = DummyRequest([path.encode("utf-8")]) request.requestHeaders = Headers( { "X-Server-Addr": ["192.168.1.1"], "X-Server-Port": ["5248"], "X-Forwarded-For": [ip], "X-Forwarded-Port": ["%s" % factory.pick_port()], } ) self.patch(http.log, "info") mock_deferLater = self.patch(http, "deferLater") mock_deferLater.side_effect = always_succeed_with(None) self.tftp.backend.get_reader.return_value = fail(FileNotFound(path)) resource = http.HTTPBootResource() yield self.render_GET(resource, request) self.assertEquals(404, request.responseCode) self.assertEquals(b"", b"".join(request.written)) @inlineCallbacks def test_render_GET_500_server_error(self): path = factory.make_name("path") ip = factory.make_ip_address() request = DummyRequest([path.encode("utf-8")]) request.requestHeaders = Headers( { "X-Server-Addr": ["192.168.1.1"], "X-Server-Port": ["5248"], "X-Forwarded-For": [ip], "X-Forwarded-Port": ["%s" % factory.pick_port()], } ) self.patch(http.log, "info") mock_deferLater = self.patch(http, "deferLater") mock_deferLater.side_effect = always_succeed_with(None) exc = factory.make_exception("internal error") self.tftp.backend.get_reader.return_value = fail(exc) resource = http.HTTPBootResource() yield self.render_GET(resource, request) self.assertEquals(500, request.responseCode) self.assertEquals(str(exc).encode("utf-8"), b"".join(request.written)) @inlineCallbacks def test_render_GET_produces_from_reader(self): path = factory.make_name("path") ip = factory.make_ip_address() request = DummyRequest([path.encode("utf-8")]) request.requestHeaders = Headers( { "X-Server-Addr": ["192.168.1.1"], "X-Server-Port": ["5248"], "X-Forwarded-For": [ip], "X-Forwarded-Port": ["%s" % factory.pick_port()], } ) self.patch(http.log, "info") mock_deferLater = self.patch(http, "deferLater") mock_deferLater.side_effect = always_succeed_with(None) content = factory.make_string(size=100).encode("utf-8") reader = BytesReader(content) self.tftp.backend.get_reader.return_value = succeed(reader) resource = http.HTTPBootResource() yield self.render_GET(resource, request) self.assertEquals( [100], request.responseHeaders.getRawHeaders(b"Content-Length") ) self.assertEquals(content, b"".join(request.written)) @inlineCallbacks def test_render_GET_logs_node_event_with_original_path_ip(self): path = factory.make_name("path") ip = factory.make_ip_address() request = DummyRequest([path.encode("utf-8")]) request.requestHeaders = Headers( { "X-Server-Addr": ["192.168.1.1"], "X-Server-Port": ["5248"], "X-Forwarded-For": [ip], "X-Forwarded-Port": ["%s" % factory.pick_port()], } ) log_info = self.patch(http.log, "info") mock_deferLater = self.patch(http, "deferLater") mock_deferLater.side_effect = always_succeed_with(None) self.tftp.backend.get_reader.return_value = fail(AccessViolation()) resource = http.HTTPBootResource() yield self.render_GET(resource, request) self.assertThat( log_info, MockCalledOnceWith( "{path} requested by {remoteHost}", path=path, remoteHost=ip ), ) self.assertThat( mock_deferLater, MockCalledOnceWith( ANY, 0, http.send_node_event_ip_address, event_type=EVENT_TYPES.NODE_HTTP_REQUEST, ip_address=ip, description=path, ), )
def stopService(self): if self.running: self.logger.removeObserver(self.sentry_log_observer) return self.client.teardown() return Service.stopService(self)
def startService(self): Service.startService(self) if not self._sender._started: self._sender.startConnecting()
def stopService(self): Service.stopService(self) log.msg('Service stopping')
def startService(self): Service.startService(self) logging.info("%s started with config %s" % ( self.service_name.capitalize(), self.config.get_config_filename()))
def stopService(self): Service.stopService(self) self._sender.stopConnecting()
def startService(self): self.reload_task.start(60, False) reactor.callInThread(writeForever) Service.startService(self)
def startService(self): self.storage_reload_task.start(60, False) self.aggregation_reload_task.start(60, False) reactor.callInThread(writeForever) Service.startService(self)
def startService(self): Service.startService(self) now = time.time() startDelta = now // self.interval * self.interval + self.interval - now self._delayedCall = self.clock.callLater(startDelta, self._startLooping)
def startService(self): Service.startService(self)
def stopService(self): Service.stopService(self) return self.stopAllClients()
def startService(self): """ Start this service by starting internal TimerService """ Service.startService(self) return self._service.startService()