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:
parent
2c8744f14e
commit
ac19cfa7ff
3 changed files with 51 additions and 7 deletions
|
@ -3,4 +3,4 @@
|
|||
Services available to nodes can be put in this directory. Everything listed in
|
||||
__all__ is automatically loaded by the main core module.
|
||||
"""
|
||||
__all__ = ["quagga", "nrl", "xorp", "bird", "utility", "security", "ucarp", "dockersvc"]
|
||||
__all__ = ["quagga", "nrl", "xorp", "bird", "utility", "security", "ucarp", "dockersvc", 'startup']
|
||||
|
|
37
daemon/core/services/startup.py
Normal file
37
daemon/core/services/startup.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
from core.service import CoreService, addservice
|
||||
from sys import maxint
|
||||
from inspect import isclass
|
||||
|
||||
class Startup(CoreService):
|
||||
'A CORE service to start other services in order, serially'
|
||||
_name = 'startup'
|
||||
_group = 'Utility'
|
||||
_depends = ()
|
||||
_dirs = ()
|
||||
_configs = ('startup.sh', )
|
||||
_startindex = maxint
|
||||
_startup = ('sh startup.sh', )
|
||||
_shutdown = ()
|
||||
_validate = ()
|
||||
|
||||
@staticmethod
|
||||
def isStartupService(s):
|
||||
return isinstance(s, Startup) or \
|
||||
(isclass(s) and issubclass(s, Startup))
|
||||
|
||||
@classmethod
|
||||
def generateconfig(cls, node, filename, services):
|
||||
if filename != cls._configs[0]:
|
||||
return ''
|
||||
script = '#!/bin/sh\n' \
|
||||
'# auto-generated by Startup (startup.py)\n\n' \
|
||||
'exec > startup.log 2>&1\n\n'
|
||||
for s in sorted(services, key = lambda x: x._startindex):
|
||||
if cls.isStartupService(s) or len(str(s._starttime)) > 0:
|
||||
continue
|
||||
start = '\n'.join(s.getstartup(node, services))
|
||||
if start:
|
||||
script += start + '\n'
|
||||
return script
|
||||
|
||||
addservice(Startup)
|
Loading…
Add table
Add a link
Reference in a new issue