コード例 #1
0
ファイル: applog.py プロジェクト: cronuspaas/cronusagent
 def listServices(self):
     """ list services """
     packageList = getServices()
     return ApplogController.prepareOutput(
                     packageList, 
                     "/applog/packages?service=", 
                     serviceRootPath(), 
                     "List Of Services")
コード例 #2
0
ファイル: packagemgr.py プロジェクト: anzarafaq/cronusagent
 def cleanRogueService():
     """ delete rogue services """
     try:
         services = manifestutil.getServices()
         for service in services:
             path = manifestutil.servicePath(service)
             for idx in range(3):
                 if os.path.exists(os.path.join(path, 'manifests')):
                     break
                 time.sleep(2)
                 if idx == 2:
                     appGlobal = pylons.config['pylons.app_globals']
                     LOG.info('service %s does not have manifests folder, cleanup the rogue service' % service)
                     deleteThread = ServiceDelete(appGlobal.threadMgr, service, path)
                     deleteThread.run()
                     LOG.info('service %s cleaned up' % service)
                     break
     except Exception:
         LOG.error('failed to check and cleanup rogue service' + traceback.format_exc(5))            
コード例 #3
0
ファイル: service.py プロジェクト: cronuspaas/cronusagent
    def startServicesOnAgentStartup():
        """
        when agent is restarted,
        0. check for agent selfupdate
        1. start all service with active manifest, this requires service startup script be idempotent
        2. load dynamic controllers and routes if any
        """
        # check for agent update
        from agent.lib.agenthealth import checkAgentVersion
        checkAgentVersion(True)

        # startup services
        from agent.lib.agent_thread.startstop_service import StartStopService
        appGlobal = config['pylons.app_globals']
        appdelay = int(config['app_restart_init_delay']) if 'app_restart_init_delay' in config else 0
        if appdelay > 0:
            time.sleep(appdelay)
            
        # check if this is agent restart or system restart
        if os.path.exists("/proc/uptime"):
            uptime, _ = [float(f) for f in open("/proc/uptime").read().split()]
        else:
            uptime = 500

        systemRestartTimeThreshold = pylons.config['system_restart_time_threshold']
        if (int(systemRestartTimeThreshold) <= uptime):
            LOG.info('agent recover from agent restart, not goint to restart managed apps')
            return
            
        LOG.info('agent recover from system reboot, restart all managed apps')
        for service in manifestutil.getServices():
            if service != 'agent':
                if manifestutil.hasActiveManifest(service):
                    try:
                        LOG.info('startup for service(%s)', service)

                        startupThread = StartStopService(appGlobal.threadMgr, service, StartStopService.ACTION_STARTUP)
                        startupThread.start()
                        startupThread.threadMgrEvent.wait()

                    except Exception as excep:
                        LOG.error('Unknown error starting service(%s) - %s - %s' % (service, str(excep), traceback.format_exc(2)))
コード例 #4
0
 def cleanRogueService():
     """ delete rogue services """
     try:
         services = manifestutil.getServices()
         for service in services:
             path = manifestutil.servicePath(service)
             for idx in range(3):
                 if os.path.exists(os.path.join(path, 'manifests')):
                     break
                 time.sleep(2)
                 if idx == 2:
                     appGlobal = pylons.config['pylons.app_globals']
                     LOG.info(
                         'service %s does not have manifests folder, cleanup the rogue service'
                         % service)
                     deleteThread = ServiceDelete(appGlobal.threadMgr,
                                                  service, path)
                     deleteThread.run()
                     LOG.info('service %s cleaned up' % service)
                     break
     except Exception:
         LOG.error('failed to check and cleanup rogue service' +
                   traceback.format_exc(5))
コード例 #5
0
ファイル: modulelog.py プロジェクト: anzarafaq/cronusagent
 def listServices(self):
     """ listServices """
     packageList = getServices()
     return ModulelogController.prepareOutput(
         packageList, "/log/list/packages?service=", serviceRootPath(),
         "List Of Services")
コード例 #6
0
 def testGetServices(self):
     createManifest(self, manifest = 'bar', service = 'foo')
     assert 'foo' in manifestutil.getServices()
     assert manifestutil.servicePath('foo').endswith('foo')
コード例 #7
0
ファイル: service.py プロジェクト: anzarafaq/cronusagent
    def startServicesOnAgentStartup():
        """
        when agent is restarted,
        0. check for agent selfupdate
        1. start all service with active manifest, this requires service startup script be idempotent
        2. load dynamic controllers and routes if any
        """
        # check for agent update
        from agent.lib.agenthealth import checkAgentVersion
        checkAgentVersion(True)

        # startup services
        from agent.lib.agent_thread.startstop_service import StartStopService
        appGlobal = config['pylons.app_globals']
        appdelay = int(
            config['appinitdelay']) if 'appinitdelay' in config else 0
        if appdelay > 0:
            time.sleep(appdelay)

        # check if this is agent restart or system restart
        if os.name != 'nt' and os.path.exists("/proc/uptime"):
            uptime, _ = [float(f) for f in open("/proc/uptime").read().split()]
        else:
            uptime = 500
        systemRestartTimeThreshold = pylons.config[
            'system_restart_time_threshold']
        actionType = StartStopService.ACTION_RESTART
        if (int(systemRestartTimeThreshold) > uptime):
            actionType = StartStopService.ACTION_REBOOT

        for service in manifestutil.getServices():

            appDataDir = manifestutil.appDataPath(service)
            if not os.path.exists(appDataDir):
                os.makedirs(appDataDir)
                import pwd
                uname = pylons.config['app_user_account']
                uid = pwd.getpwnam(uname).pw_uid
                gid = pwd.getpwnam(uname).pw_gid
                utils.rchown(appDataDir, uid, gid)

            dataDir = manifestutil.dataPath(service)
            if not os.path.exists(dataDir):
                os.makedirs(dataDir)

            if service != 'agent':
                try:
                    manifestutil.updateServiceMetaFile(
                        service, {
                            'servicePath': manifestutil.servicePath(service),
                            'serviceName': service
                        })
                except Exception as excep:
                    LOG.error(
                        'Unknown error updating local metadata service(%s) - %s - %s'
                        % (service, str(excep), traceback.format_exc(2)))

                if manifestutil.hasActiveManifest(service):
                    try:
                        LOG.info('startup for service(%s)', service)

                        startupThread = StartStopService(
                            appGlobal.threadMgr, service, actionType)
                        startupThread.start()
                        startupThread.threadMgrEvent.wait()

                    except Exception as excep:
                        LOG.error(
                            'Unknown error starting service(%s) - %s - %s' %
                            (service, str(excep), traceback.format_exc(2)))

                    try:
                        LOG.info('load controllers and routes for service(%s)',
                                 service)
                        manifestutil.processControllerInPackage(service)

                    except Exception as excep:
                        LOG.error(
                            'Unknown error loading controllers for service(%s) - %s - %s'
                            % (service, str(excep), traceback.format_exc(2)))
コード例 #8
0
 def testGetServices(self):
     createManifest(self, manifest='bar', service='foo')
     assert 'foo' in manifestutil.getServices()
     assert manifestutil.servicePath('foo').endswith('foo')
コード例 #9
0
ファイル: service.py プロジェクト: arunkumar-m/cronus-agent
    def startServicesOnAgentStartup():
        """
        when agent is restarted,
        0. check for agent selfupdate
        1. start all service with active manifest, this requires service startup script be idempotent
        2. load dynamic controllers and routes if any
        """
        # check for agent update
        from agent.lib.agenthealth import checkAgentVersion

        checkAgentVersion(True)

        # startup services
        from agent.lib.agent_thread.startstop_service import StartStopService

        appGlobal = config["pylons.app_globals"]
        appdelay = int(config["appinitdelay"]) if "appinitdelay" in config else 0
        if appdelay > 0:
            time.sleep(appdelay)

        # check if this is agent restart or system restart
        if os.name != "nt" and os.path.exists("/proc/uptime"):
            uptime, _ = [float(f) for f in open("/proc/uptime").read().split()]
        else:
            uptime = 500
        systemRestartTimeThreshold = pylons.config["system_restart_time_threshold"]
        actionType = StartStopService.ACTION_RESTART
        if int(systemRestartTimeThreshold) > uptime:
            actionType = StartStopService.ACTION_REBOOT

        for service in manifestutil.getServices():

            appDataDir = manifestutil.appDataPath(service)
            if not os.path.exists(appDataDir):
                os.makedirs(appDataDir)
                import pwd

                uname = pylons.config["app_user_account"]
                uid = pwd.getpwnam(uname).pw_uid
                gid = pwd.getpwnam(uname).pw_gid
                utils.rchown(appDataDir, uid, gid)

            dataDir = manifestutil.dataPath(service)
            if not os.path.exists(dataDir):
                os.makedirs(dataDir)

            if service != "agent":
                try:
                    manifestutil.updateServiceMetaFile(
                        service, {"servicePath": manifestutil.servicePath(service), "serviceName": service}
                    )
                except Exception as excep:
                    LOG.error(
                        "Unknown error updating local metadata service(%s) - %s - %s"
                        % (service, str(excep), traceback.format_exc(2))
                    )

                if manifestutil.hasActiveManifest(service):
                    try:
                        LOG.info("startup for service(%s)", service)

                        startupThread = StartStopService(appGlobal.threadMgr, service, actionType)
                        startupThread.start()
                        startupThread.threadMgrEvent.wait()

                    except Exception as excep:
                        LOG.error(
                            "Unknown error starting service(%s) - %s - %s"
                            % (service, str(excep), traceback.format_exc(2))
                        )

                    try:
                        LOG.info("load controllers and routes for service(%s)", service)
                        manifestutil.processControllerInPackage(service)

                    except Exception as excep:
                        LOG.error(
                            "Unknown error loading controllers for service(%s) - %s - %s"
                            % (service, str(excep), traceback.format_exc(2))
                        )