Beispiel #1
0
    def run(self):
        """
        Main loop
        """
        self.log.info("Running")
        while 1:
            try:
                # Rotate logs
                self.logrotate()
                # (re)start new processes as necessary
                if self.shouldrun:
                    self.procmanager.checkARCClusters()
                    self.procmanager.checkCondorClusters()
                # sleep
                aCTUtils.sleep(10)

            except aCTSignal.ExceptInterrupt:
                break
            except:
                self.log.critical("*** Unexpected exception! ***")
                self.log.critical(traceback.format_exc())
                # Reconnect database, in case there was a DB interruption
                try:
                    self.procmanager.reconnectDB()
                except:
                    self.log.critical(traceback.format_exc())
                aCTUtils.sleep(10)
Beispiel #2
0
    def stop(self):
        """
        Stop daemon
        """
        pidfile = self.conf.get(['actlocation', 'pidfile'])
        pid = None
        try:
            with open(pidfile) as f:
                pid = f.read()
        except IOError:
            pass

        if not pid:
            print('aCT already stopped')
            return 1

        try:
            os.kill(int(pid), signal.SIGTERM)
        except OSError: # already stopped
            pass

        os.remove(pidfile)
        print('Stopping aCT... ', end=' ')
        sys.stdout.flush()
        while True:
            try:
                aCTUtils.sleep(1)
                os.kill(int(pid), 0)
            except OSError as err:
                if err.errno == errno.ESRCH:
                    break
        print('stopped')
        return 0
Beispiel #3
0
 def run(self):
     '''
     Main loop
     '''
     try:
         while 1:
             # parse config file
             self.conf.parse()
             self.arcconf.parse()
             # do class-specific things
             self.process()
             # sleep
             aCTUtils.sleep(2)
             # restart periodically in case of hangs
             #ip=int(self.conf.get(['periodicrestart', self.name.lower()]))
             #if time.time()-self.starttime > ip and ip != 0 :
             #    self.log.info("%s for %s exited for periodic restart", self.name, self.cluster)
             #    return
     except aCTSignal.ExceptInterrupt as x:
         self.log.info("Received interrupt %s, exiting", str(x))
     except:
         self.log.critical("*** Unexpected exception! ***")
         self.log.critical(traceback.format_exc())
         self.log.critical("*** Process exiting ***")
         self.criticallog.critical(traceback.format_exc())
Beispiel #4
0
    def getCursor(self):
        # make sure cursor reads newest db state
        try:
            self.conn.commit()
        except (mysql.errors.InternalError, MySQLInterfaceError) as e:
            # Unread result, force reconnection
            self.log.warning(str(e))
            self.conn.close()
            self._connect(self.dbname)

        for _ in range(3):
            try:
                cur = self.conn.cursor(dictionary=True)
                return cur
            except mysql.errors.OperationalError as err:
                self.log.warning("Error getting cursor: %s" % str(err))
                aCTUtils.sleep(1)
        raise Exception("Could not get cursor")
Beispiel #5
0
 def run(self):
     '''
     Main loop
     '''
     try:
         while 1:
             # parse config file
             self.conf.parse()
             self.arcconf.parse()
             self.setSites()
             # do class-specific things
             self.process()
             # sleep
             aCTUtils.sleep(2)
     except aCTSignal.ExceptInterrupt as x:
         self.log.info("Received interrupt %s, exiting", str(x))
     except:
         self.log.critical("*** Unexpected exception! ***")
         self.log.critical(traceback.format_exc())
         self.log.critical("*** Process exiting ***")
         self.criticallog.critical(traceback.format_exc())