Exemplo n.º 1
0
    def __deactivateManifest(self, service, manifest):
        """ deactive a manifest.  This means calling stop then deactive on the manifest
        @param service - service of manifest to deactivate
        @param manifest - manifest to deactivate
        @param stack - stack for recovery
        """
        self.__LOG.debug("Deactivate Manifest %s-%s" % (service, manifest))
        if (manifest == None):
            return

        self._execPackages('shutdown',
                           service,
                           manifest,
                           11,
                           25,
                           activateFlow=False)
        self._execPackages('deactivate',
                           service,
                           manifest,
                           26,
                           50,
                           activateFlow=False)
        manifestutil.processControllerInPackage(service,
                                                manifest,
                                                activateFlow=False)
Exemplo n.º 2
0
    def __activateManifest(self, service, manifest):
        """ deactive a manifest.  This means calling stop then deactive on the manifest
        @param service - service of manifest to activate
        @param manifest - manifest to activate
        @param stack - stack for recovery
        """
        self.__LOG.debug("Activate Manifest %s-%s" % (service, manifest))
        if (manifest == None):
            return

        self._activationStage = ActivateManifest.STAGE_ACTIVATION
        self._execPackages('activate',
                           service,
                           manifest,
                           51,
                           65,
                           activateFlow=True)
        self._activationStage = ActivateManifest.STAGE_STARTUP
        self._execPackages('startup',
                           service,
                           manifest,
                           66,
                           80,
                           activateFlow=True)
        manifestutil.processControllerInPackage(self._service,
                                                self._manifest,
                                                activateFlow=True)
Exemplo n.º 3
0
    def __deactivateManifest(self, service, manifest):
        """ deactive a manifest.  This means calling stop then deactive on the manifest
        @param service - service of manifest to deactivate
        @param manifest - manifest to deactivate
        @param stack - stack for recovery
        """
        self.__LOG.debug("Deactivate Manifest %s-%s" % (service, manifest))
        if (manifest == None):
            return

        self._execPackages('shutdown', service, manifest, 11, 25, activateFlow = False)
        self._execPackages('deactivate', service, manifest, 26, 50, activateFlow = False)
        manifestutil.processControllerInPackage(service, manifest, activateFlow = False)
Exemplo n.º 4
0
    def __activateManifest(self, service, manifest):
        """ deactive a manifest.  This means calling stop then deactive on the manifest
        @param service - service of manifest to activate
        @param manifest - manifest to activate
        @param stack - stack for recovery
        """
        self.__LOG.debug("Activate Manifest %s-%s" % (service, manifest))
        if (manifest == None):
            return

        self._activationStage = ActivateManifest.STAGE_ACTIVATION
        self._execPackages('activate', service, manifest, 51, 65, activateFlow = True)
        self._activationStage = ActivateManifest.STAGE_STARTUP
        self._execPackages('startup', service, manifest, 66, 80, activateFlow = True)
        manifestutil.processControllerInPackage(self._service, self._manifest, activateFlow = True)
Exemplo n.º 5
0
 def __deactivateFailedManifest(self, service, manifest):
     """ best effort to deactive a failed manifest.  This means calling stop then deactive on the manifest, and ignore any errors
     @param service - service of manifest to deactivate
     @param manifest - manifest to deactivate
     @param stack - stack for recovery
     """
     self.__LOG.debug("Deactivate Manifest %s-%s" % (service, manifest))
     if (manifest == None):
         return
     needShutdown = (self._activationStage == ActivateManifest.STAGE_STARTUP)
     needDeactivate = (needShutdown | (self._activationStage == ActivateManifest.STAGE_ACTIVATION))
     if needShutdown:
         try:
             self._execPackages('shutdown', service, manifest, 81, 90, activateFlow = False)
         except Exception:
             pass
     if needDeactivate:
         try:
             self._execPackages('deactivate', service, manifest, 91, 99, activateFlow = False)
             manifestutil.processControllerInPackage(self._service, self._manifest, activateFlow = False)
         except Exception:
             pass
Exemplo n.º 6
0
 def __deactivateFailedManifest(self, service, manifest):
     """ best effort to deactive a failed manifest.  This means calling stop then deactive on the manifest, and ignore any errors
     @param service - service of manifest to deactivate
     @param manifest - manifest to deactivate
     @param stack - stack for recovery
     """
     self.__LOG.debug("Deactivate Manifest %s-%s" % (service, manifest))
     if (manifest == None):
         return
     needShutdown = (
         self._activationStage == ActivateManifest.STAGE_STARTUP)
     needDeactivate = (needShutdown |
                       (self._activationStage
                        == ActivateManifest.STAGE_ACTIVATION))
     if needShutdown:
         try:
             self._execPackages('shutdown',
                                service,
                                manifest,
                                81,
                                90,
                                activateFlow=False)
         except Exception:
             pass
     if needDeactivate:
         try:
             self._execPackages('deactivate',
                                service,
                                manifest,
                                91,
                                99,
                                activateFlow=False)
             manifestutil.processControllerInPackage(self._service,
                                                     self._manifest,
                                                     activateFlow=False)
         except Exception:
             pass
Exemplo n.º 7
0
    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)))
Exemplo n.º 8
0
    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))
                        )