Esempio n. 1
0
 def use_linked_cdm_force():
     try: import application
     except ImportError: raise SetupError('Cannot access the application module')
     ioc.activate(application.assembly)
     force = server_type() == 'mongrel2'
     ioc.deactivate()
     if force: support.force(use_linked_cdm, False)
Esempio n. 2
0
@copyright: 2012 Sourcefabric o.p.s.
@license: http://www.gnu.org/licenses/gpl-3.0.txt
@author: Gabriel Nistor

Configuration to add multiprocessing abilities to the database.
'''

from __setup__.ally_core_http import server_type
from ally.container import ioc
import ally_deploy_application
import logging

# --------------------------------------------------------------------

log = logging.getLogger(__name__)

# --------------------------------------------------------------------

ioc.activate(ally_deploy_application.assembly)
if server_type() == 'production':
    try:
        from sql_alchemy.multiprocess_config import enableMultiProcessPool
    except ImportError:
        # Probably there is no sql alchemy available.
        log.warning(
            'Cannot enable multiple processors support for database connection pools',
            exc_info=True)
    else:
        enableMultiProcessPool()
ioc.deactivate()
Esempio n. 3
0
Created on Oct 18, 2012

@package: ally core http
@copyright: 2012 Sourcefabric o.p.s.
@license: http://www.gnu.org/licenses/gpl-3.0.txt
@author: Gabriel Nistor

Configuration to add multiprocessing abilities to the database.
'''

from __setup__.ally_core_http import server_type
from ally.container import ioc
import ally_deploy_application
import logging

# --------------------------------------------------------------------

log = logging.getLogger(__name__)

# --------------------------------------------------------------------

ioc.activate(ally_deploy_application.assembly)
if server_type() == 'production':
    try:
        from sql_alchemy.multiprocess_config import enableMultiProcessPool
    except ImportError:
        # Probably there is no sql alchemy available.
        log.warning('Cannot enable multiple processors support for database connection pools', exc_info=True)
    else: enableMultiProcessPool()
ioc.deactivate()
Esempio n. 4
0
Created on Oct 18, 2012

@package: ally core http
@copyright: 2012 Sourcefabric o.p.s.
@license: http://www.gnu.org/licenses/gpl-3.0.txt
@author: Gabriel Nistor

Configuration to add multiprocessing abilities to the database.
'''

from __setup__.ally_core_http import server_type
from ally.container import ioc
import ally_deploy_application
import logging

# --------------------------------------------------------------------

log = logging.getLogger(__name__)

# --------------------------------------------------------------------

ioc.activate(ally_deploy_application.assembly)
if server_type() == 'proxy':
    try:
        from sql_alchemy.multiprocess_config import enableMultiProcessPool
    except ImportError:
        # Probably there is no sql alchemy available.
        log.warning('Cannot enable multiple processors support for database connection pools', exc_info=True)
    else: enableMultiProcessPool()
ioc.deactivate()
Esempio n. 5
0
@copyright: 2012 Sourcefabric o.p.s.
@license: http://www.gnu.org/licenses/gpl-3.0.txt
@author: Gabriel Nistor

Configuration to add multiprocessing abilities to the database.
'''

from __setup__.ally_core_http import server_type
from ally.container import ioc
import ally_deploy_application
import logging

# --------------------------------------------------------------------

log = logging.getLogger(__name__)

# --------------------------------------------------------------------

ioc.activate(ally_deploy_application.assembly)
if server_type() == 'proxy':
    try:
        from sql_alchemy.multiprocess_config import enableMultiProcessPool
    except ImportError:
        # Probably there is no sql alchemy available.
        log.warning(
            'Cannot enable multiple processors support for database connection pools',
            exc_info=True)
    else:
        enableMultiProcessPool()
ioc.deactivate()
Esempio n. 6
0
def config():
    assert isinstance(application.options, OptionsMongrel2), 'Invalid application options %s' % application.options
    if not application.options.configMongrel2: return
    workspace = application.options.configMongrel2
    folders = [path.join('mongrel2', name) for name in ('logs', 'run', 'tmp')]
    folders.append(path.join('shared', 'upload'))

    for name in folders:
        folder = path.join(workspace, name)
        if not path.isdir(folder): makedirs(folder)
    
    configFile = application.options.configurationPath
    if path.isfile(configFile):
        with open(configFile, 'r') as f: config = load(f)
    else:
        print('The configuration file "%s" doesn\'t exist, create one by running the the application '
              'with "-dump" option, also change the application properties "server_type" configuration to "mongrel2" '
              'and also adjust the "recv_spec", "send_spec" and "server_port" accordingly' % configFile, file=sys.stderr)
        sys.exit(1)
        
    try:
        assembly = application.assembly = ioc.open(aop.modulesIn('__setup__.**'), config=config)
        assert isinstance(assembly, Assembly), 'Invalid assembly %s' % assembly
    
        updateConfig = False
        if server_type() != 'mongrel2':
            updateConfig = True
            support.persist(server_type, 'mongrel2')
        
        sendIdent = send_ident()
        if sendIdent is None:
            updateConfig = True
            sendIdent = str(uuid4())
            support.persist(send_ident, sendIdent)
        
        replace = {}
        try:
            replace['${send_spec}'] = send_spec()
            replace['${send_ident}'] = sendIdent
            replace['${recv_spec}'] = recv_spec()
            replace['${recv_ident}'] = recv_ident()
            replace['${server_port}'] = str(server_port())
        
            if updateConfig:
                if path.isfile(configFile): renames(configFile, configFile + '.bak')
                for config in assembly.configurations: assembly.processForName(config)
                # Forcing the processing of all configurations
                with open(configFile, 'w') as f: save(assembly.trimmedConfigurations(), f)
                print('Updated the "%s" configuration file' % configFile)
        finally: ioc.deactivate()
    except SystemExit: raise
    except:
        print('-' * 150, file=sys.stderr)
        print('A problem occurred while configuring Mongrel2', file=sys.stderr)
        traceback.print_exc(file=sys.stderr)
        print('-' * 150, file=sys.stderr)
    else:
        conf = openURI(path.join(pythonPath(), 'resources', 'ally.conf'))
        conf = codecs.getreader('utf8')(conf)
        conf = ReplaceInFile(conf, replace)
        with open(path.join(workspace, 'ally.conf'), 'w') as f: pipe(conf, f)
        with open(path.join(workspace, 'README-Mongrel2.txt'), 'wb') as f:
            pipe(openURI(path.join(pythonPath(), 'resources', 'README-Mongrel2.txt')), f)
        
        print('Configured "%s" mongrel2 workspace' % workspace)