예제 #1
0
파일: apache.py 프로젝트: johnykov/fabtools
def site_enabled(config):
    """
    Ensure link to /etc/apache2/sites-available/config exists and reload apache2
    configuration if needed.
    """
    enable_site(config)
    reload_service('apache2')
예제 #2
0
파일: apache.py 프로젝트: restanrm/fabtools
def site_enabled(config):
    """
    Ensure link to /etc/apache2/sites-available/config exists and reload apache2
    configuration if needed.
    """
    enable_site(config)
    reload_service('apache2')
예제 #3
0
파일: apache.py 프로젝트: Friz-zy/fabtools
def site_enabled(config):
    """
    Require an Apache site to be enabled.

    This will cause Apache to reload its configuration.

    ::

        from fabtools import require

        require.apache.site_enabled('mysite')

    """
    enable_site(config)
    reload_service('apache2')
예제 #4
0
파일: apache.py 프로젝트: xlqian/fabtools
def site_enabled(config):
    """
    Require an Apache site to be enabled.

    This will cause Apache to reload its configuration.

    ::

        from fabtools import require

        require.apache.site_enabled('mysite')

    """
    enable_site(config)
    reload_service('apache2')
예제 #5
0
def site(site_name, template_contents=None, template_source=None, enabled=True, check_config=True, **kwargs):
    server()

    config_filename = '/etc/apache2/sites-available/%s.conf' % site_name
    if template_contents:
        tmpl = tempita.Template(template_contents)
    elif template_source:
        f = open(template_source, 'r')
        tmpl = tempita.Template(f.read())
        f.close()

    _file(
        path=config_filename,
        contents=tmpl.substitute(kwargs)
    )

    if enabled:
        apache.enable_site(site_name)
예제 #6
0
파일: apache.py 프로젝트: Friz-zy/fabtools
def site(config_name, template_contents=None, template_source=None, enabled=True, check_config=True, **kwargs):
    """
    Require an Apache site.

    You must provide a template for the site configuration, either as a
    string (*template_contents*) or as the path to a local template
    file (*template_source*).

    ::

        from fabtools import require

        CONFIG_TPL = '''
        <VirtualHost *:%(port)s>
            ServerName %(hostname})s

            DocumentRoot %(document_root)s

            <Directory %(document_root)s>
                Options Indexes FollowSymLinks MultiViews

                AllowOverride All

                Order allow,deny
                allow from all
            </Directory>
        </VirtualHost>
        '''

        require.apache.site(
            'example.com',
            template_contents=CONFIG_TPL,
            port=80,
            hostname='www.example.com',
            document_root='/var/www/mysite',
        )

    .. seealso:: :py:func:`fabtools.require.files.template_file`
    """
    server()

    config_filename = '/etc/apache2/sites-available/%s' % _get_config_name(config_name)

    context = {
        'port': 80,
    }
    context.update(kwargs)
    context['config_name'] = config_name

    template_file(config_filename, template_contents, template_source, context, use_sudo=True)

    if enabled:
        enable_site(config_name)
    else:
        disable_site(config_name)

    if check_config:
        with settings(hide('running', 'warnings'), warn_only=True):
            if run_as_root('apache2ctl configtest').failed:
                disable_site(config_name)
                message = red("Error in %(config_name)s apache site config (disabling for safety)" % locals())
                abort(message)

    reload_service('apache2')
예제 #7
0
파일: apache.py 프로젝트: xlqian/fabtools
def site(config_name,
         template_contents=None,
         template_source=None,
         enabled=True,
         check_config=True,
         **kwargs):
    """
    Require an Apache site.

    You must provide a template for the site configuration, either as a
    string (*template_contents*) or as the path to a local template
    file (*template_source*).

    ::

        from fabtools import require

        CONFIG_TPL = '''
        <VirtualHost *:%(port)s>
            ServerName %(hostname})s

            DocumentRoot %(document_root)s

            <Directory %(document_root)s>
                Options Indexes FollowSymLinks MultiViews

                AllowOverride All

                Order allow,deny
                allow from all
            </Directory>
        </VirtualHost>
        '''

        require.apache.site(
            'example.com',
            template_contents=CONFIG_TPL,
            port=80,
            hostname='www.example.com',
            document_root='/var/www/mysite',
        )

    .. seealso:: :py:func:`fabtools.require.files.template_file`
    """
    server()

    config_filename = '/etc/apache2/sites-available/%s' % _get_config_name(
        config_name)

    context = {
        'port': 80,
    }
    context.update(kwargs)
    context['config_name'] = config_name

    template_file(config_filename,
                  template_contents,
                  template_source,
                  context,
                  use_sudo=True)

    if enabled:
        enable_site(config_name)
    else:
        disable_site(config_name)

    if check_config:
        with settings(hide('running', 'warnings'), warn_only=True):
            if run_as_root('apache2ctl configtest').failed:
                disable_site(config_name)
                message = red(
                    "Error in %(config_name)s apache site config (disabling for safety)"
                    % locals())
                abort(message)

    reload_service('apache2')