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(): 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 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(): # 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 initDIRAC( rootPath, enableDebug = False ): # CONFIGURATION OPTIONS HERE (note: all config options will override # any Pylons config options) configDict = { 'webConfig' : {} } configDict[ 'webConfig' ]['dirac.webroot'] = rootPath diracRootPath = os.path.realpath( os.path.dirname( os.path.dirname( rootPath ) ) ) configDict[ 'webConfig' ]['dirac.root'] = diracRootPath if diracRootPath not in sys.path: sys.path.append( diracRootPath ) from DIRAC.FrameworkSystem.Client.Logger import gLogger gLogger.registerBackends( [ 'stderr' ] ) from DIRAC.Core.Base import Script Script.registerSwitch( "r", "reload", "Reload for pylons" ) Script.localCfg.addDefaultEntry( "/DIRAC/Security/UseServerCertificate", "yes" ) Script.localCfg.addDefaultEntry( "LogColor", True ) Script.initialize( script = "Website", ignoreErrors = True, initializeMonitor = False ) gLogger._systemName = "Framework" gLogger.initialize( "Web", "/Website" ) gLogger.setLevel( "VERBOSE" ) from DIRAC import gMonitor, gConfig, rootPath as droot from DIRAC.Core.Utilities import CFG from DIRAC.ConfigurationSystem.Client.Helpers import getCSExtensions gMonitor.setComponentType( gMonitor.COMPONENT_WEB ) gMonitor.initialize() gMonitor.registerActivity( "pagesServed", "Pages served", "Framework", "pages", gMonitor.OP_SUM ) gLogger.info( "DIRAC Initialized" ) configDict['portalVersion'] = portalVersion( rootPath ) gLogger.info( "DIRAC portal version: %s" % configDict['portalVersion'] ) extModules = [ '%sDIRAC' % module for module in getCSExtensions() ] #Load web.cfg of modules cfgFilePaths = [ os.path.join( droot, "etc", "web.cfg" ) ] for extModule in extModules: gLogger.info( "Adding web.cfg for %s extension" % extModule ) extModulePath = os.path.join( diracRootPath, extModule ) webCFGPath = os.path.join( extModulePath, "Web", "web.cfg" ) cfgFilePaths.append( webCFGPath ) for systemDir in os.listdir( extModulePath ): webCFGSystemPath = os.path.join( extModulePath, systemDir, "Web", "web.cfg" ) cfgFilePaths.append( webCFGSystemPath ) webCFG = CFG.CFG() for webCFGPath in cfgFilePaths: if not os.path.isfile( webCFGPath ): gLogger.warn( "%s does not exist" % webCFGPath ) else: gLogger.info( "Loading %s" % webCFGPath ) modCFG = CFG.CFG().loadFromFile( webCFGPath ) if modCFG.getOption( 'Website/AbsoluteDefinition', False ): gLogger.info( "CFG %s is absolute" % webCFGPath ) webCFG = modCFG else: webCFG = webCFG.mergeWith( modCFG ) gConfig.loadCFG( webCFG ) gLogger.showHeaders( True ) gLogger._gLogger__initialized = False gLogger.initialize( "Web", "/Website" ) #Define the controllers, templates and public directories for type in ( 'controllers', 'templates', 'public' ): configDict[ type ] = [] for extModule in extModules: extModulePath = os.path.join( diracRootPath, extModule ) typePath = os.path.join( extModulePath, "Web", type ) if os.path.isdir( typePath ): gLogger.info( "Adding %s path for module %s" % ( type, extModule ) ) configDict[ type ].append( typePath ) for systemDir in os.listdir( extModulePath ): systemTypePath = os.path.join( extModulePath, systemDir, "Web", type ) if os.path.isdir( systemTypePath ): gLogger.info( "Adding %s path for system %s in module %s" % ( type, systemDir, extModule ) ) configDict[ type ].append( systemTypePath ) #End of extensions configDict[ type ].append( os.path.join( rootPath, type ) ) #Load debug.cfg? if enableDebug: debugCFGPath = os.path.join( rootPath, "debug.cfg" ) if os.path.isfile( debugCFGPath ): gLogger.info( "Loading debug cfg file at %s" % debugCFGPath ) gConfig.loadFile( debugCFGPath ) gLogger.info( "Extension modules loaded" ) return configDict
import tornado from DIRAC.Core.Base import Script from DIRAC.ConfigurationSystem.Client.LocalConfiguration import LocalConfiguration from DIRAC.FrameworkSystem.Client.Logger import gLogger from WebAppDIRAC.Core.App import App if __name__ == "__main__": localCfg = LocalConfiguration() localCfg.setConfigurationForWeb( "WebApp" ) localCfg.addMandatoryEntry( "/DIRAC/Setup" ) localCfg.addDefaultEntry( "/DIRAC/Security/UseServerCertificate", "yes" ) localCfg.addDefaultEntry( "LogLevel", "INFO" ) localCfg.addDefaultEntry( "LogColor", True ) result = localCfg.loadUserData() if not result[ 'OK' ]: gLogger.initialize( serverName, "/" ) gLogger.fatal( "There were errors when loading configuration", result[ 'Message' ] ) sys.exit( 1 ) app = App() result = app.bootstrap() if not result[ 'OK' ]: gLogger.fatal( result[ 'Message' ] ) sys.exit( 1 ) app.run()
def initDIRAC(rootPath, enableDebug=False): # CONFIGURATION OPTIONS HERE (note: all config options will override # any Pylons config options) configDict = {'webConfig': {}} configDict['webConfig']['dirac.webroot'] = rootPath diracRootPath = os.path.realpath(os.path.dirname( os.path.dirname(rootPath))) configDict['webConfig']['dirac.root'] = diracRootPath if diracRootPath not in sys.path: sys.path.append(diracRootPath) from DIRAC.FrameworkSystem.Client.Logger import gLogger gLogger.registerBackends(['stderr']) from DIRAC.Core.Base import Script Script.registerSwitch("r", "reload", "Reload for pylons") Script.localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes") Script.localCfg.addDefaultEntry("LogColor", True) Script.initialize(script="Website", ignoreErrors=True, initializeMonitor=False) gLogger._systemName = "Framework" gLogger.initialize("Web", "/Website") gLogger.setLevel("VERBOSE") from DIRAC import gMonitor, gConfig, rootPath as droot from DIRAC.Core.Utilities import CFG from DIRAC.ConfigurationSystem.Client.Helpers import getCSExtensions gMonitor.setComponentType(gMonitor.COMPONENT_WEB) gMonitor.initialize() gMonitor.registerActivity("pagesServed", "Pages served", "Framework", "pages", gMonitor.OP_SUM) gLogger.info("DIRAC Initialized") configDict['portalVersion'] = portalVersion(rootPath) gLogger.info("DIRAC portal version: %s" % configDict['portalVersion']) extModules = ['%sDIRAC' % module for module in getCSExtensions()] #Load web.cfg of modules cfgFilePaths = [os.path.join(droot, "etc", "web.cfg")] for extModule in extModules: gLogger.info("Adding web.cfg for %s extension" % extModule) extModulePath = os.path.join(diracRootPath, extModule) webCFGPath = os.path.join(extModulePath, "Web", "web.cfg") cfgFilePaths.append(webCFGPath) for systemDir in os.listdir(extModulePath): webCFGSystemPath = os.path.join(extModulePath, systemDir, "Web", "web.cfg") cfgFilePaths.append(webCFGSystemPath) webCFG = CFG.CFG() for webCFGPath in cfgFilePaths: if not os.path.isfile(webCFGPath): gLogger.warn("%s does not exist" % webCFGPath) else: gLogger.info("Loading %s" % webCFGPath) modCFG = CFG.CFG().loadFromFile(webCFGPath) if modCFG.getOption('Website/AbsoluteDefinition', False): gLogger.info("CFG %s is absolute" % webCFGPath) webCFG = modCFG else: webCFG = webCFG.mergeWith(modCFG) gConfig.loadCFG(webCFG) gLogger.showHeaders(True) gLogger._gLogger__initialized = False gLogger.initialize("Web", "/Website") #Define the controllers, templates and public directories for type in ('controllers', 'templates', 'public'): configDict[type] = [] for extModule in extModules: extModulePath = os.path.join(diracRootPath, extModule) typePath = os.path.join(extModulePath, "Web", type) if os.path.isdir(typePath): gLogger.info("Adding %s path for module %s" % (type, extModule)) configDict[type].append(typePath) for systemDir in os.listdir(extModulePath): systemTypePath = os.path.join(extModulePath, systemDir, "Web", type) if os.path.isdir(systemTypePath): gLogger.info("Adding %s path for system %s in module %s" % (type, systemDir, extModule)) configDict[type].append(systemTypePath) #End of extensions configDict[type].append(os.path.join(rootPath, type)) #Load debug.cfg? if enableDebug: debugCFGPath = os.path.join(rootPath, "debug.cfg") if os.path.isfile(debugCFGPath): gLogger.info("Loading debug cfg file at %s" % debugCFGPath) gConfig.loadFile(debugCFGPath) gLogger.info("Extension modules loaded") return configDict
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) 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)
# File : dirac-service # Author : Adria Casajus ######################################################################## __RCSID__ = "$Id$" import sys import DIRAC from DIRAC.ConfigurationSystem.Client.LocalConfiguration import LocalConfiguration from DIRAC.FrameworkSystem.Client.Logger import gLogger from DIRAC.Core.DISET.ServiceReactor import ServiceReactor localCfg = LocalConfiguration() positionalArgs = localCfg.getPositionalArguments() if len(positionalArgs) == 0: gLogger.initialize("NOT SPECIFIED", "/") 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") resultDict = localCfg.loadUserData() if not resultDict['OK']: gLogger.initialize(serverName, "/") gLogger.error("There were errors when loading configuration", resultDict['Message']) sys.exit(1)
# File : dirac-service # Author : Adria Casajus ######################################################################## __RCSID__ = "$Id$" import sys import DIRAC from DIRAC.ConfigurationSystem.Client.LocalConfiguration import LocalConfiguration from DIRAC.FrameworkSystem.Client.Logger import gLogger from DIRAC.Core.DISET.ServiceReactor import ServiceReactor localCfg = LocalConfiguration() positionalArgs = localCfg.getPositionalArguments() if len( positionalArgs ) == 0: gLogger.initialize( "NOT SPECIFIED", "/" ) 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" ) resultDict = localCfg.loadUserData() if not resultDict[ 'OK' ]: gLogger.initialize( serverName, "/" ) gLogger.error( "There were errors when loading configuration", resultDict[ 'Message' ] ) sys.exit( 1 )
if __name__ == "__main__": def disableDevMode( op ): gConfig.setOptionValue( "/WebApp/DevelopMode", "False" ) return S_OK() localCfg = LocalConfiguration() localCfg.setConfigurationForWeb( "WebApp" ) localCfg.addMandatoryEntry( "/DIRAC/Setup" ) localCfg.addDefaultEntry( "/DIRAC/Security/UseServerCertificate", "yes" ) localCfg.addDefaultEntry( "LogLevel", "INFO" ) localCfg.addDefaultEntry( "LogColor", True ) localCfg.registerCmdOpt( "p", "production", "Enable production mode", disableDevMode ) result = localCfg.loadUserData() if not result[ 'OK' ]: gLogger.initialize( "WebApp", "/" ) gLogger.fatal( "There were errors when loading configuration", result[ 'Message' ] ) sys.exit( 1 ) app = App() result = app.bootstrap() if not result[ 'OK' ]: gLogger.fatal( result[ 'Message' ] ) sys.exit( 1 ) app.run()
if __name__ == "__main__": def disableDevMode(op): gConfig.setOptionValue("/WebApp/DevelopMode", "False") return S_OK() localCfg = LocalConfiguration() localCfg.setConfigurationForWeb("EiscatWeb") localCfg.addMandatoryEntry("/DIRAC/Setup") localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes") localCfg.addDefaultEntry("LogLevel", "INFO") localCfg.addDefaultEntry("LogColor", True) localCfg.registerCmdOpt("p", "production", "Enable production mode", disableDevMode) result = localCfg.loadUserData() if not result['OK']: gLogger.initialize("EiscatWeb", "/") gLogger.fatal("There were errors when loading configuration", result['Message']) sys.exit(1) app = App() result = app.bootstrap() if not result['OK']: gLogger.fatal(result['Message']) sys.exit(1) app.run()