daemon: Add a startup service.

When enabled, the startup service ensures that other node services
start in order (according to the service _startindex value) and that
the prior service completes before the next service starts.  It also
captures any output from startup commands in a file named
'startup.log'.
This commit is contained in:
Tom Goff 2015-09-11 17:27:08 -04:00
parent 2c8744f14e
commit ac19cfa7ff
3 changed files with 51 additions and 7 deletions

View file

@ -63,7 +63,8 @@ class CoreServices(ConfigurableManager):
for path in paths.split(','):
path = path.strip()
self.importcustom(path)
self.isStartupService = startup.Startup.isStartupService
def importcustom(self, path):
''' Import services from a myservices directory.
'''
@ -217,24 +218,25 @@ class CoreServices(ConfigurableManager):
'''
services = sorted(node.services,
key=lambda service: service._startindex)
useStartupService = any(map(self.isStartupService, services))
for s in services:
if len(str(s._starttime)) > 0:
try:
t = float(s._starttime)
if t > 0.0:
fn = self.bootnodeservice
self.session.evq.add_event(t, fn, node, s, services)
self.session.evq.add_event(t, fn, node, s, services, False)
continue
except ValueError:
pass
self.bootnodeservice(node, s, services)
self.bootnodeservice(node, s, services, useStartupService)
def bootnodeservice(self, node, s, services):
def bootnodeservice(self, node, s, services, useStartupService):
''' Start a service on a node. Create private dirs, generate config
files, and execute startup commands.
'''
if s._custom:
self.bootnodecustomservice(node, s, services)
self.bootnodecustomservice(node, s, services, useStartupService)
return
if node.verbose:
node.info("starting service %s (%s)" % (s._name, s._startindex))
@ -247,6 +249,8 @@ class CoreServices(ConfigurableManager):
for filename in s.getconfigfilenames(node.objid, services):
cfg = s.generateconfig(node, filename, services)
node.nodefile(filename, cfg)
if useStartupService and not self.isStartupService(s):
return
for cmd in s.getstartup(node, services):
try:
# NOTE: this wait=False can be problematic!
@ -254,7 +258,7 @@ class CoreServices(ConfigurableManager):
except Exception, e:
node.warn("error starting command %s: %s" % (cmd, e))
def bootnodecustomservice(self, node, s, services):
def bootnodecustomservice(self, node, s, services, useStartupService):
''' Start a custom service on a node. Create private dirs, use supplied
config files, and execute supplied startup commands.
'''
@ -284,6 +288,9 @@ class CoreServices(ConfigurableManager):
continue
node.nodefile(filename, cfg)
if useStartupService and not self.isStartupService(s):
return
for cmd in s._startup:
try:
# NOTE: this wait=False can be problematic!