Пример #1
0
 def __init__(self, daemonType, daemonId, callback):
     coreConfig = CoreConfig()
     self.logFile = coreConfig.getLogFile(daemonType)  #, daemonId)
     self.pidFile = coreConfig.getPidFile(daemonType)  #, daemonId)
     self.name = 'chains-%s-%s' % (daemonType, daemonId)
     self.daemonType = daemonType
     self.daemonId = daemonId
     self.callback = callback
Пример #2
0
def main(daemonType, fork=True):
    coreConfig = CoreConfig()
    conf = coreConfig.data(daemonType)
    if not conf:
        raise Exception('No section "daemon_%s" in config' % id)
    conf['id'] = resolveDaemonId(conf['id'])
    for k in conf:
        if k[0:4] == 'env_':
            log.info('Set ENV.%s = %s' % (k[4:], conf[k]))
            os.environ[k[4:]] = conf[k]
    d = Daemon(daemonType, conf['id'], getDaemonMainFunction(daemonType))
    if fork:
        d.fork()
    else:
        d.main()
Пример #3
0
'''
Process manager for services using subprocess
'''

from chains.common import log
from chains.common.config import CoreConfig
from chains import service
import os, signal, time, subprocess, json, psutil, types

processes = {}
config = CoreConfig()
'''
todo:
 * capture stdout/stderr? --> no, do it in service-runner
 - option for relative path in config.command? then need servicedir config or something
 * move pidfile stuff here, so non-py devs does not have to do it themselves
 - some duplicate code here and in daemon/__init__.py - consolidate?
'''


def start(serviceConfig):

    serviceId = serviceConfig['main'].get('id')

    log.info('Start service: %s' % serviceId)

    pid = isRunning(serviceId)

    if pid:
        log.error(
            "Could not start service %s because already running on pid %s" %
Пример #4
0
 def test_When_getting_pidfile_It_returns_the_correct_path(self):
     conf = CoreConfig(file=self.path)
     path = conf.getPidFile('manager')
     self.assertEquals('/var/run/chains/manager.pid', path)
Пример #5
0
 def test_When_getting_logfile_It_returns_the_correct_path(self):
     conf = CoreConfig(file=self.path)
     path = conf.getLogFile('manager')
     self.assertEquals('/var/log/chains/manager.log', path)
Пример #6
0
 def test_When_config_is_missing_It_is_auto_created(self):
     conf = CoreConfig(file=self.path)
     self.assertEquals('/etc/chains', conf.get('confdir'))
     self.assertEquals('{hostname}', conf.get('id', 'manager'))