def main(): localCfg = LocalConfiguration() localCfg.setUsageMessage(__doc__) positionalArgs = localCfg.getPositionalArguments() if len(positionalArgs) == 0: gLogger.fatal("You must specify which agent to run!") sys.exit(1) agentName = positionalArgs[0] localCfg.setConfigurationForAgent(agentName) localCfg.addMandatoryEntry("/DIRAC/Setup") localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes") localCfg.addDefaultEntry("LogLevel", "INFO") localCfg.addDefaultEntry("LogColor", True) resultDict = localCfg.loadUserData() if not resultDict['OK']: gLogger.error("There were errors when loading configuration", resultDict['Message']) sys.exit(1) includeExtensionErrors() agentReactor = AgentReactor(positionalArgs[0]) result = agentReactor.loadAgentModules(positionalArgs) if result['OK']: agentReactor.go() else: gLogger.error("Error while loading agent module", result['Message']) sys.exit(2)
def main(): localCfg = LocalConfiguration() localCfg.setUsageMessage(__doc__) positionalArgs = localCfg.getPositionalArguments() if len(positionalArgs) == 0: gLogger.fatal("You must specify which server to run!") sys.exit(1) serverName = positionalArgs[0] localCfg.setConfigurationForServer(serverName) localCfg.addMandatoryEntry("Port") # localCfg.addMandatoryEntry( "HandlerPath" ) localCfg.addMandatoryEntry("/DIRAC/Setup") localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes") localCfg.addDefaultEntry("LogLevel", "INFO") localCfg.addDefaultEntry("LogColor", True) resultDict = localCfg.loadUserData() if not resultDict['OK']: gLogger.initialize(serverName, "/") gLogger.error("There were errors when loading configuration", resultDict['Message']) sys.exit(1) includeExtensionErrors() serverToLaunch = ServiceReactor() result = serverToLaunch.initialize(positionalArgs) if not result['OK']: gLogger.error(result['Message']) sys.exit(1) result = serverToLaunch.serve() if not result['OK']: gLogger.error(result['Message']) sys.exit(1)
def main(): Script.registerArgument(["Agent: specify which agent to run"]) positionalArgs = Script.getPositionalArgs(group=True) localCfg = Script.localCfg agentName = positionalArgs[0] localCfg.setConfigurationForAgent(agentName) localCfg.addMandatoryEntry("/DIRAC/Setup") localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes") localCfg.addDefaultEntry("LogLevel", "INFO") localCfg.addDefaultEntry("LogColor", True) resultDict = localCfg.loadUserData() if not resultDict["OK"]: gLogger.error("There were errors when loading configuration", resultDict["Message"]) sys.exit(1) includeExtensionErrors() agentReactor = AgentReactor(positionalArgs[0]) result = agentReactor.loadAgentModules(positionalArgs) if result["OK"]: agentReactor.go() # dirac_agent might interact with ARC library which cannot be closed using a simple sys.exit(0) # See https://bugzilla.nordugrid.org/show_bug.cgi?id=4022 for further details os._exit(0) else: gLogger.error("Error while loading agent module", result["Message"]) sys.exit(2)
def main(): Script.registerArgument(["Agent: specify which agent to run"]) positionalArgs = Script.getPositionalArgs(group=True) localCfg = Script.localCfg agentName = positionalArgs[0] localCfg.setConfigurationForAgent(agentName) localCfg.addMandatoryEntry("/DIRAC/Setup") localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes") localCfg.addDefaultEntry("LogLevel", "INFO") localCfg.addDefaultEntry("LogColor", True) resultDict = localCfg.loadUserData() if not resultDict["OK"]: gLogger.error("There were errors when loading configuration", resultDict["Message"]) sys.exit(1) includeExtensionErrors() agentReactor = AgentReactor(positionalArgs[0]) result = agentReactor.loadAgentModules(positionalArgs) if result["OK"]: agentReactor.go() else: gLogger.error("Error while loading agent module", result["Message"]) sys.exit(2)
def main(): if os.environ.get("DIRAC_USE_TORNADO_IOLOOP", "false").lower() not in ("yes", "true"): raise RuntimeError( "DIRAC_USE_TORNADO_IOLOOP is not defined in the environment." + "\n" + "It is necessary to run with Tornado." + "\n" + "https://dirac.readthedocs.io/en/latest/DeveloperGuide/TornadoServices/index.html" ) from DIRAC.ConfigurationSystem.Client.PathFinder import getServiceSection from DIRAC.ConfigurationSystem.Client.ConfigurationData import gConfigurationData from DIRAC.ConfigurationSystem.private.Refresher import gRefresher from DIRAC.Core.Utilities.DErrno import includeExtensionErrors from DIRAC.Core.Tornado.Server.TornadoServer import TornadoServer from DIRAC.FrameworkSystem.Client.Logger import gLogger if gConfigurationData.isMaster(): gRefresher.disable() localCfg = Script.localCfg localCfg.addMandatoryEntry("/DIRAC/Setup") localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes") localCfg.addDefaultEntry("LogLevel", "INFO") localCfg.addDefaultEntry("LogColor", True) resultDict = localCfg.loadUserData() if not resultDict["OK"]: gLogger.initialize("Tornado-CS", "/") gLogger.error("There were errors when loading configuration", resultDict["Message"]) sys.exit(1) includeExtensionErrors() gLogger.initialize("Tornado-CS", "/") # get the specific master CS port try: csPort = int( gConfigurationData.extractOptionFromCFG( "%s/Port" % getServiceSection("Configuration/Server"))) except TypeError: csPort = None serverToLaunch = TornadoServer(services="Configuration/Server", port=csPort) serverToLaunch.startTornado()
def main(): if os.environ.get("DIRAC_USE_TORNADO_IOLOOP", "false").lower() not in ("yes", "true"): raise RuntimeError( "DIRAC_USE_TORNADO_IOLOOP is not defined in the environment." + "\n" + "It is necessary to run with Tornado." + "\n" + "https://dirac.readthedocs.io/en/latest/DeveloperGuide/TornadoServices/index.html" ) from DIRAC import gConfig from DIRAC.ConfigurationSystem.Client import PathFinder from DIRAC.ConfigurationSystem.Client.ConfigurationData import gConfigurationData from DIRAC.Core.Tornado.Server.TornadoServer import TornadoServer from DIRAC.Core.Utilities.DErrno import includeExtensionErrors from DIRAC.FrameworkSystem.Client.Logger import gLogger localCfg = Script.localCfg localCfg.setConfigurationForServer("Tornado/Tornado") localCfg.addMandatoryEntry("/DIRAC/Setup") localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes") localCfg.addDefaultEntry("LogLevel", "INFO") localCfg.addDefaultEntry("LogColor", True) resultDict = localCfg.loadUserData() if not resultDict["OK"]: gLogger.initialize("Tornado", "/") gLogger.error("There were errors when loading configuration", resultDict["Message"]) sys.exit(1) includeExtensionErrors() gLogger.initialize("Tornado", "/") # We check if there is no configuration server started as master # If you want to start a master CS you should use Configuration_Server.cfg and # use tornado-start-CS.py key = "/Systems/Configuration/%s/Services/Server/Protocol" % PathFinder.getSystemInstance( "Configuration") if gConfigurationData.isMaster() and gConfig.getValue( key, "dips").lower() == "https": gLogger.fatal("You can't run the CS and services in the same server!") sys.exit(0) serverToLaunch = TornadoServer(endpoints=True) serverToLaunch.startTornado()
def initialize(cls, script=False, ignoreErrors=False, initializeMonitor=False, enableCommandLine=False): """initialization :param str script: script name :param bool ignoreErrors: ignore errors when loading configuration :param bool initializeMonitor: to use monitoring :param bool enableCommandLine: enable parse command line """ # Please do not call initialize in every file if cls.alreadyInitialized: return False userDisabled = not cls.localCfg.isCSEnabled() cls.alreadyInitialized = True if not userDisabled: cls.localCfg.disableCS() if not enableCommandLine: cls.localCfg.disableParsingCommandLine() if script: cls.scriptName = script cls.localCfg.setConfigurationForScript(cls.scriptName) if not ignoreErrors: cls.localCfg.addMandatoryEntry("/DIRAC/Setup") resultDict = cls.localCfg.loadUserData() if not ignoreErrors and not resultDict["OK"]: gLogger.error("There were errors when loading configuration", resultDict["Message"]) sys.exit(1) if not userDisabled: cls.localCfg.enableCS() if initializeMonitor: gMonitor.setComponentType(gMonitor.COMPONENT_SCRIPT) gMonitor.setComponentName(cls.scriptName) gMonitor.setComponentLocation("script") gMonitor.initialize() else: gMonitor.disable() includeExtensionErrors() return True
def initialize(script=False, ignoreErrors=False, initializeMonitor=False, enableCommandLine=False): global scriptName, gIsAlreadyInitialized #Please do not call initialize in every file if gIsAlreadyInitialized: return False gIsAlreadyInitialized = True userDisabled = not localCfg.isCSEnabled() if not userDisabled: localCfg.disableCS() if not enableCommandLine: localCfg.disableParsingCommandLine() if script: scriptName = script localCfg.setConfigurationForScript(scriptName) if not ignoreErrors: localCfg.addMandatoryEntry("/DIRAC/Setup") resultDict = localCfg.loadUserData() if not ignoreErrors and not resultDict['OK']: gLogger.error("There were errors when loading configuration", resultDict['Message']) sys.exit(1) if not userDisabled: localCfg.enableCS() if initializeMonitor: gMonitor.setComponentType(gMonitor.COMPONENT_SCRIPT) gMonitor.setComponentName(scriptName) gMonitor.setComponentLocation("script") gMonitor.initialize() else: gMonitor.disable() includeExtensionErrors() return True
def main(): # Must be defined BEFORE any dirac import os.environ['DIRAC_USE_TORNADO_IOLOOP'] = "True" from DIRAC.ConfigurationSystem.Client.PathFinder import getServiceSection from DIRAC.ConfigurationSystem.Client.ConfigurationData import gConfigurationData from DIRAC.ConfigurationSystem.Client.LocalConfiguration import LocalConfiguration from DIRAC.ConfigurationSystem.private.Refresher import gRefresher from DIRAC.Core.Utilities.DErrno import includeExtensionErrors from DIRAC.Core.Tornado.Server.TornadoServer import TornadoServer from DIRAC.FrameworkSystem.Client.Logger import gLogger if gConfigurationData.isMaster(): gRefresher.disable() localCfg = LocalConfiguration() localCfg.addMandatoryEntry("/DIRAC/Setup") localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes") localCfg.addDefaultEntry("LogLevel", "INFO") localCfg.addDefaultEntry("LogColor", True) resultDict = localCfg.loadUserData() if not resultDict['OK']: gLogger.initialize("Tornado-CS", "/") gLogger.error("There were errors when loading configuration", resultDict['Message']) sys.exit(1) includeExtensionErrors() gLogger.initialize('Tornado-CS', "/") # get the specific master CS port try: csPort = int( gConfigurationData.extractOptionFromCFG( '%s/Port' % getServiceSection('Configuration/Server'))) except TypeError: csPort = None serverToLaunch = TornadoServer(services='Configuration/Server', port=csPort) serverToLaunch.startTornado()
def main(): localCfg = LocalConfiguration() localCfg.setUsageMessage(__doc__) positionalArgs = localCfg.getPositionalArguments() if len(positionalArgs) == 0: gLogger.fatal("You must specify which executor to run!") sys.exit(1) if len(positionalArgs) == 1 and positionalArgs[0].find("/") > -1: mainName = positionalArgs[0] else: mainName = "Framework/MultiExecutor" localCfg.setConfigurationForExecutor(mainName) localCfg.addMandatoryEntry("/DIRAC/Setup") localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes") localCfg.addDefaultEntry("LogLevel", "INFO") localCfg.addDefaultEntry("LogColor", True) resultDict = localCfg.loadUserData() if not resultDict['OK']: gLogger.fatal("There were errors when loading configuration", resultDict['Message']) sys.exit(1) includeExtensionErrors() executorReactor = ExecutorReactor() result = executorReactor.loadModules(positionalArgs) if not result['OK']: gLogger.fatal("Error while loading executor", result['Message']) sys.exit(1) result = executorReactor.go() if not result['OK']: gLogger.fatal(result['Message']) sys.exit(1) gLogger.notice("Graceful exit. Bye!") sys.exit(0)
def initialize(script=False, ignoreErrors=False, initializeMonitor=False, enableCommandLine=False): global scriptName, gIsAlreadyInitialized # Please do not call initialize in every file if gIsAlreadyInitialized: return False gIsAlreadyInitialized = True userDisabled = not localCfg.isCSEnabled() if not userDisabled: localCfg.disableCS() if not enableCommandLine: localCfg.disableParsingCommandLine() if script: scriptName = script localCfg.setConfigurationForScript(scriptName) if not ignoreErrors: localCfg.addMandatoryEntry("/DIRAC/Setup") resultDict = localCfg.loadUserData() if not ignoreErrors and not resultDict['OK']: gLogger.error("There were errors when loading configuration", resultDict['Message']) sys.exit(1) if not userDisabled: localCfg.enableCS() if initializeMonitor: gMonitor.setComponentType(gMonitor.COMPONENT_SCRIPT) gMonitor.setComponentName(scriptName) gMonitor.setComponentLocation("script") gMonitor.initialize() else: gMonitor.disable() includeExtensionErrors() return True
def main(): # Must be defined BEFORE any dirac import os.environ['DIRAC_USE_TORNADO_IOLOOP'] = "True" from DIRAC import gConfig from DIRAC.ConfigurationSystem.Client import PathFinder from DIRAC.ConfigurationSystem.Client.ConfigurationData import gConfigurationData from DIRAC.ConfigurationSystem.Client.LocalConfiguration import LocalConfiguration from DIRAC.Core.Tornado.Server.TornadoServer import TornadoServer from DIRAC.Core.Utilities.DErrno import includeExtensionErrors from DIRAC.FrameworkSystem.Client.Logger import gLogger # We check if there is no configuration server started as master # If you want to start a master CS you should use Configuration_Server.cfg and # use tornado-start-CS.py key = '/Systems/Configuration/%s/Services/Server/Protocol' % PathFinder.getSystemInstance('Configuration') if gConfigurationData.isMaster() and gConfig.getValue(key, 'dips').lower() == 'https': gLogger.fatal("You can't run the CS and services in the same server!") sys.exit(0) localCfg = LocalConfiguration() localCfg.setConfigurationForServer('Tornado/Tornado') localCfg.addMandatoryEntry("/DIRAC/Setup") localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes") localCfg.addDefaultEntry("LogLevel", "INFO") localCfg.addDefaultEntry("LogColor", True) resultDict = localCfg.loadUserData() if not resultDict['OK']: gLogger.initialize("Tornado", "/") gLogger.error("There were errors when loading configuration", resultDict['Message']) sys.exit(1) includeExtensionErrors() gLogger.initialize('Tornado', "/") serverToLaunch = TornadoServer() serverToLaunch.startTornado()
def main(): # Registering arguments will automatically add their description to the help menu Script.registerArgument(["executor: specify which executor to run"]) positionalArgs = Script.getPositionalArgs() localCfg = Script.localCfg if len(positionalArgs) == 1 and positionalArgs[0].find("/") > -1: mainName = positionalArgs[0] else: mainName = "Framework/MultiExecutor" localCfg.setConfigurationForExecutor(mainName) localCfg.addMandatoryEntry("/DIRAC/Setup") localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes") localCfg.addDefaultEntry("LogLevel", "INFO") localCfg.addDefaultEntry("LogColor", True) resultDict = localCfg.loadUserData() if not resultDict["OK"]: gLogger.fatal("There were errors when loading configuration", resultDict["Message"]) sys.exit(1) includeExtensionErrors() executorReactor = ExecutorReactor() result = executorReactor.loadModules(positionalArgs) if not result["OK"]: gLogger.fatal("Error while loading executor", result["Message"]) sys.exit(1) result = executorReactor.go() if not result["OK"]: gLogger.fatal(result["Message"]) sys.exit(1) gLogger.notice("Graceful exit. Bye!") sys.exit(0)
gLogger.fatal("You must specify which server to run!") sys.exit(1) serverName = positionalArgs[0] localCfg.setConfigurationForServer(serverName) localCfg.addMandatoryEntry("Port") # localCfg.addMandatoryEntry( "HandlerPath" ) localCfg.addMandatoryEntry("/DIRAC/Setup") localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes") localCfg.addDefaultEntry("LogLevel", "INFO") localCfg.addDefaultEntry("LogColor", True) resultDict = localCfg.loadUserData() if not resultDict['OK']: gLogger.initialize(serverName, "/") gLogger.error("There were errors when loading configuration", resultDict['Message']) sys.exit(1) includeExtensionErrors() serverToLaunch = ServiceReactor() result = serverToLaunch.initialize(positionalArgs) if not result['OK']: gLogger.error(result['Message']) sys.exit(1) result = serverToLaunch.serve() if not result['OK']: gLogger.error(result['Message']) sys.exit(1)
if len( positionalArgs ) == 1 and positionalArgs[0].find( "/" ) > -1: mainName = positionalArgs[0] else: mainName = "Framework/MultiExecutor" localCfg.setConfigurationForExecutor( mainName ) localCfg.addMandatoryEntry( "/DIRAC/Setup" ) localCfg.addDefaultEntry( "/DIRAC/Security/UseServerCertificate", "yes" ) localCfg.addDefaultEntry( "LogLevel", "INFO" ) localCfg.addDefaultEntry( "LogColor", True ) resultDict = localCfg.loadUserData() if not resultDict[ 'OK' ]: gLogger.fatal( "There were errors when loading configuration", resultDict[ 'Message' ] ) sys.exit( 1 ) includeExtensionErrors() executorReactor = ExecutorReactor() result = executorReactor.loadModules( positionalArgs ) if not result[ 'OK' ]: gLogger.fatal( "Error while loading executor", result[ 'Message' ] ) sys.exit( 1 ) result = executorReactor.go() if not result[ 'OK' ]: gLogger.fatal( result[ 'Message' ] ) sys.exit( 1 ) gLogger.notice( "Graceful exit. Bye!" ) sys.exit(0)