Пример #1
0
    def run(self):
        logger.debug('** Running Daemon **')
        set_proctitle('OGAgent')

        self.initialize()

        # Call modules initialization
        # They are called in sequence, no threading is done at this point, so ensure modules onActivate always returns
        

        # *********************
        # * Main Service loop *
        # *********************
        # Counter used to check ip changes only once every 10 seconds, for
        # example
        try:
            while self.isAlive:
                # In milliseconds, will break
                self.doWait(1000)
        except (KeyboardInterrupt, SystemExit) as e:
            logger.error('Requested exit of main loop')
        except Exception as e:
            logger.exception()
            logger.error('Caught exception on main loop: {}'.format(e))

        self.terminate()

        self.notifyStop()
Пример #2
0
 def deinitialize(self):
     for mod in reversed(
             self.modules):  # Deinitialize reversed of initialization
         try:
             logger.debug('Deactivating module {}'.format(mod.name))
             mod.deactivate()
         except Exception as e:
             logger.exception()
             logger.error("Deactivation of {} failed: {}".format(
                 mod.name, utils.exceptionToMessage(e)))
Пример #3
0
    def cleanup(self):
        logger.debug('Quit invoked')
        if self.stopped is False:
            self.stopped = True
            try:
                self.deinitialize()
            except Exception:
                logger.exception()
                logger.error('Got exception deinitializing modules')

            try:
                # If we close Client, send Logoff to Broker
                self.ipc.sendLogout(operations.getCurrentUser())
                time.sleep(1)
                self.timer.stop()
                self.ipc.stop()
            except Exception:
                # May we have lost connection with server, simply log and exit in that case
                logger.exception()
                logger.exception("Got an exception, processing quit")

            try:
                # operations.logoff()  # Uncomment this after testing to logoff user
                pass
            except Exception:
                pass
Пример #4
0
    def SvcDoRun(self):
        '''
        Main service loop
        '''
        try:
            logger.debug('running SvcDoRun')
            servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                                  servicemanager.PYS_SERVICE_STARTED,
                                  (self._svc_name_, ''))

            # call the CoInitialize to allow the registration to run in an other
            # thread
            logger.debug('Initializing com...')
            pythoncom.CoInitialize()

            # Initialize remaining service data
            self.initialize()
        except Exception:  # Any init exception wil be caught, service must be then restarted
            logger.exception()
            logger.debug('Exiting service with failure status')
            os._exit(-1)  # pylint: disable=protected-access

        # *********************
        # * Main Service loop *
        # *********************
        try:
            while self.isAlive:
                # Pumps & processes any waiting messages
                pythoncom.PumpWaitingMessages()
                win32event.WaitForSingleObject(self.hWaitStop, 1000)
        except Exception as e:
            logger.error('Caught exception on main loop: {}'.format(e))

        logger.debug('Exited main loop, deregistering SENS')

        self.terminate()  # Ends IPC servers

        self.notifyStop()
Пример #5
0
    def initialize(self):
        # Load modules and activate them
        # Also, sends "login" event to service
        self.modules = loadModules(self, client=True)
        logger.debug('Modules: {}'.format(list(v.name for v in self.modules)))

        # Send init to all modules
        validMods = []
        for mod in self.modules:
            try:
                logger.debug('Activating module {}'.format(mod.name))
                mod.activate()
                validMods.append(mod)
            except Exception as e:
                logger.exception()
                logger.error("Activation of {} failed: {}".format(
                    mod.name, utils.exceptionToMessage(e)))

        self.modules[:] = validMods  # copy instead of assignment

        # If this is running, it's because he have logged in, inform service of this fact
        self.ipc.sendLogin(operations.getCurrentUser(),
                           operations.getSessionLanguage())
Пример #6
0

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)

    if not QtGui.QSystemTrayIcon.isSystemTrayAvailable():
        # QtGui.QMessageBox.critical(None, "Systray", "I couldn't detect any system tray on this system.")
        sys.exit(1)

    # This is important so our app won't close on messages windows (alerts, etc...)
    QtGui.QApplication.setQuitOnLastWindowClosed(False)

    try:
        trayIcon = OGASystemTray(app)
    except Exception as e:
        logger.exception()
        logger.error(
            'OGA Service is not running, or it can\'t contact with OGA Server. User Tools stopped: {}'
            .format(utils.exceptionToMessage(e)))
        sys.exit(1)

    try:
        trayIcon.initialize()  # Initialize modules, etc..
    except Exception as e:
        logger.exception()
        logger.error('Exception initializing OpenGnsys User Agent {}'.format(
            utils.exceptionToMessage(e)))
        trayIcon.quit()
        sys.exit(1)

    app.aboutToQuit.connect(trayIcon.cleanup)