2015-09-11 22:27:08 +01:00
|
|
|
from inspect import isclass
|
2017-04-25 16:45:34 +01:00
|
|
|
from sys import maxint
|
|
|
|
|
|
|
|
from core.service import CoreService
|
|
|
|
|
2015-09-11 22:27:08 +01:00
|
|
|
|
|
|
|
class Startup(CoreService):
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
|
|
|
A CORE service to start other services in order, serially
|
|
|
|
"""
|
2018-06-15 22:03:27 +01:00
|
|
|
name = 'startup'
|
|
|
|
group = 'Utility'
|
|
|
|
depends = ()
|
|
|
|
dirs = ()
|
|
|
|
configs = ('startup.sh',)
|
|
|
|
startindex = maxint
|
|
|
|
startup = ('sh startup.sh',)
|
|
|
|
shutdown = ()
|
|
|
|
validate = ()
|
2015-09-11 22:27:08 +01:00
|
|
|
|
|
|
|
@staticmethod
|
2017-04-25 16:45:34 +01:00
|
|
|
def is_startup_service(s):
|
|
|
|
return isinstance(s, Startup) or (isclass(s) and issubclass(s, Startup))
|
2015-09-11 22:27:08 +01:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def generateconfig(cls, node, filename, services):
|
2018-06-15 22:03:27 +01:00
|
|
|
if filename != cls.configs[0]:
|
2015-09-11 22:27:08 +01:00
|
|
|
return ''
|
|
|
|
script = '#!/bin/sh\n' \
|
|
|
|
'# auto-generated by Startup (startup.py)\n\n' \
|
|
|
|
'exec > startup.log 2>&1\n\n'
|
2018-06-15 22:03:27 +01:00
|
|
|
for s in sorted(services, key=lambda x: x.startindex):
|
|
|
|
if cls.is_startup_service(s) or len(str(s.starttime)) > 0:
|
2015-09-11 22:27:08 +01:00
|
|
|
continue
|
|
|
|
start = '\n'.join(s.getstartup(node, services))
|
|
|
|
if start:
|
|
|
|
script += start + '\n'
|
|
|
|
return script
|