core-extra/daemon/core/services/startup.py

39 lines
1.1 KiB
Python
Raw Normal View History

from inspect import isclass
from sys import maxint
from core.service import CoreService
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 is_startup_service(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.is_startup_service(s) or len(str(s.starttime)) > 0:
continue
start = '\n'.join(s.getstartup(node, services))
if start:
script += start + '\n'
return script