コード例 #1
0
    def shutdown(self, service):
        ''' Controller to shutdown service '''
        LOG.info('shutdown for service(%s)', service)

        try:
            appGlobal = config['pylons.app_globals']

            if not os.path.exists(manifestutil.manifestPath(service,
                                                            'active')):
                return errorResult(request,
                                   response,
                                   Errors.ACTIVEMANIFEST_MANIFEST_MISSING,
                                   'Active Manifest(%s) path missing' %
                                   (service),
                                   controller=self)
            shutdownThread = StartStopService(appGlobal.threadMgr, service,
                                              StartStopService.ACTION_SHUTDOWN)
            self.injectJobCtx(shutdownThread)
            shutdownThread.start()
            shutdownThread.threadMgrEvent.wait()

            return statusResult(request,
                                response,
                                shutdownThread,
                                controller=self)

        except Exception as excep:
            return errorResult(
                request,
                response,
                error=Errors.UNKNOWN_ERROR,
                errorMsg='Unknown error for shutdown service(%s) - %s - %s' %
                (service, str(excep), traceback.format_exc(2)),
                controller=self)
コード例 #2
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)))
コード例 #3
0
ファイル: action.py プロジェクト: cronuspaas/cronusagent
    def shutdown(self, service):
        ''' Controller to shutdown service '''
        LOG.info('shutdown for service(%s)', service)

        try:
            appGlobal = config['pylons.app_globals']

            if not os.path.exists(manifestutil.manifestPath(service, 'active')):
                return errorResult(request, response, Errors.ACTIVEMANIFEST_MANIFEST_MISSING,
                                   'Active Manifest(%s) path missing' % (service),
                                   controller = self)
            shutdownThread = StartStopService(appGlobal.threadMgr, service, StartStopService.ACTION_SHUTDOWN)
            self.injectJobCtx(shutdownThread)
            shutdownThread.start()
            shutdownThread.threadMgrEvent.wait()

            return statusResult(request, response, shutdownThread, controller = self)

        except Exception as excep:
            return errorResult(request, response, error = Errors.UNKNOWN_ERROR,
                               errorMsg = 'Unknown error for shutdown service(%s) - %s - %s' %
                               (service, str(excep), traceback.format_exc(2)),
                               controller = self)
コード例 #4
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)))
コード例 #5
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))
                        )