示例#1
0
 def services_running(self, target):
     """
     Check all services are running
     :param target: Target to check
     :return: Boolean
     """
     try:
         if target == 'config':
             self.log_message(target, 'Testing configuration store...', 0)
             from source.tools.configuration.configuration import Configuration
             try:
                 Configuration.list('/')
             except Exception as ex:
                 self.log_message(target, '  Error during configuration store test: {0}'.format(ex), 2)
                 return False
             if Configuration.get_store() == 'arakoon':
                 from source.tools.configuration.arakoon_config import ArakoonConfiguration
                 from source.tools.pyrakoon.pyrakoon.compat import NoGuarantee
                 client = ArakoonConfiguration.get_client()
                 contents = client.get(Watcher.INTERNAL_CONFIG_KEY, consistency=NoGuarantee())
                 if Watcher.LOG_CONTENTS != contents:
                     try:
                         # Validate whether the contents are not corrupt
                         parser = RawConfigParser()
                         parser.readfp(StringIO(contents))
                     except Exception as ex:
                         self.log_message(target, '  Configuration stored in configuration store seems to be corrupt: {0}'.format(ex), 2)
                         return False
                     temp_filename = '{0}~'.format(ArakoonConfiguration.CACC_LOCATION)
                     with open(temp_filename, 'w') as config_file:
                         config_file.write(contents)
                         config_file.flush()
                         os.fsync(config_file)
                     os.rename(temp_filename, ArakoonConfiguration.CACC_LOCATION)
                     if Watcher.LOG_CONTENTS is not None:
                         self.log_message(target, '  Configuration changed, trigger restart', 1)
                         sys.exit(1)
                     Watcher.LOG_CONTENTS = contents
             self.log_message(target, '  Configuration store OK', 0)
             return True
     except Exception as ex:
         self.log_message(target, 'Unexpected exception: {0}'.format(ex), 2)
         return False