コード例 #1
0
ファイル: nginx.py プロジェクト: 3quarterstack/fabtools
def site(server_name, template_contents=None, template_source=None,
         enabled=True, check_config=True, **kwargs):
    """
    Require an nginx 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 = '''
        server {
            listen      %(port)d;
            server_name %(server_name)s %(server_alias)s;
            root        %(docroot)s;
            access_log  /var/log/nginx/%(server_name)s.log;
        }'''

        require.nginx.site('example.com', template_contents=CONFIG_TPL,
            port=80,
            server_alias='www.example.com',
            docroot='/var/www/mysite',
        )

    .. seealso:: :py:func:`fabtools.require.files.template_file`
    """
    if not is_installed('nginx-common'):
        # nginx-common is always installed if Nginx exists
        server()

    config_filename = '/etc/nginx/sites-available/%s.conf' % server_name

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

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

    link_filename = '/etc/nginx/sites-enabled/%s.conf' % server_name
    if enabled:
        if not is_link(link_filename):
            run_as_root("ln -s %(config_filename)s %(link_filename)s" % locals())

        # Make sure we don't break the config
        if check_config:
            with settings(hide('running', 'warnings'), warn_only=True):
                if run_as_root('nginx -t').failed:
                    run_as_root("rm %(link_filename)s" % locals())
                    message = red("Error in %(server_name)s nginx site config (disabling for safety)" % locals())
                    abort(message)
    else:
        if is_link(link_filename):
            run_as_root("rm %(link_filename)s" % locals())

    reload_service('nginx')
コード例 #2
0
ファイル: nginx.py プロジェクト: shiumachi/fabtools
def disabled(config):
    """
    Ensure link to /etc/nginx/sites-available/config doesn't exist and reload
    nginx configuration if needed.
    """
    disable(config)
    reload_service('nginx')
コード例 #3
0
ファイル: nginx.py プロジェクト: adamrt/fabtools
def disabled(config):
    """
    Ensure link to /etc/nginx/sites-available/config doesn't exist and reload
    nginx configuration if needed.
    """
    disable(config)
    reload_service('nginx')
コード例 #4
0
ファイル: apache.py プロジェクト: johnykov/fabtools
def site_disabled(config):
    """
    Ensure link to /etc/apache2/sites-available/config doesn't exist and reload
    apache2 configuration if needed.
    """
    disable_site(config)
    reload_service('apache2')
コード例 #5
0
ファイル: nginx.py プロジェクト: adamrt/fabtools
def enabled(config):
    """
    Ensure link to /etc/nginx/sites-available/config exists and reload nginx
    configuration if needed.
    """
    enable(config)
    reload_service('nginx')
コード例 #6
0
ファイル: apache.py プロジェクト: johnykov/fabtools
def module_disabled(module):
    """
    Ensure link to /etc/apache2/mods-available/module doesn't exist and reload
    apache2 configuration if needed.
    """
    disable_module(module)
    reload_service('apache2')
コード例 #7
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')
コード例 #8
0
ファイル: apache.py プロジェクト: ChrisMarinos/fabtools
def disabled(config):
    """
    Ensure link to /etc/apache2/sites-available/config doesn't exist and reload
    apache2 configuration if needed.
    """
    disable(config)
    reload_service('apache2')
コード例 #9
0
ファイル: apache.py プロジェクト: ChrisMarinos/fabtools
def enabled(config):
    """
    Ensure link to /etc/apache2/sites-available/config exists and reload apache2
    configuration if needed.
    """
    enable(config)
    reload_service('apache2')
コード例 #10
0
ファイル: nginx.py プロジェクト: shiumachi/fabtools
def enabled(config):
    """
    Ensure link to /etc/nginx/sites-available/config exists and reload nginx
    configuration if needed.
    """
    enable(config)
    reload_service('nginx')
コード例 #11
0
ファイル: apache.py プロジェクト: restanrm/fabtools
def module_disabled(module):
    """
    Ensure link to /etc/apache2/mods-available/module doesn't exist and reload
    apache2 configuration if needed.
    """
    disable_module(module)
    reload_service('apache2')
コード例 #12
0
ファイル: nginx.py プロジェクト: simonluijk/fabtools
def site(server_name, template_contents=None, template_source=None,
         enabled=True, check_config=True, **kwargs):
    """
    Require an nginx 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 = '''
        server {
            listen      %(port)d;
            server_name %(server_name)s %(server_alias)s;
            root        %(docroot)s;
            access_log  /var/log/nginx/%(server_name)s.log;
        }'''

        require.nginx.site('example.com', template_contents=CONFIG_TPL,
            port=80,
            server_alias='www.example.com',
            docroot='/var/www/mysite',
        )

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

    config_filename = '/etc/nginx/sites-available/%s.conf' % server_name

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

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

    link_filename = '/etc/nginx/sites-enabled/%s.conf' % server_name
    if enabled:
        if not is_link(link_filename):
            run_as_root("ln -s %(config_filename)s %(link_filename)s" % locals())

        # Make sure we don't break the config
        if check_config:
            with settings(hide('running', 'warnings'), warn_only=True):
                if run_as_root('nginx -t').failed:
                    run_as_root("rm %(link_filename)s" % locals())
                    message = red("Error in %(server_name)s nginx site config (disabling for safety)" % locals())
                    abort(message)
    else:
        if is_link(link_filename):
            run_as_root("rm %(link_filename)s" % locals())

    reload_service('nginx')
コード例 #13
0
ファイル: apache.py プロジェクト: xlqian/fabtools
def site_disabled(config):
    """
    Require an Apache site to be disabled.

    This will cause Apache to reload its configuration.

    ::

        from fabtools import require

        require.apache.site_disabled('default')

    """
    disable_site(config)
    reload_service('apache2')
コード例 #14
0
ファイル: apache.py プロジェクト: xlqian/fabtools
def module_disabled(module):
    """
    Require an Apache module to be disabled.

    This will cause Apache to reload its configuration.

    ::

        from fabtools import require

        require.apache.module_disabled('rewrite')

    """
    disable_module(module)
    reload_service('apache2')
コード例 #15
0
ファイル: nginx.py プロジェクト: 26lights/fabtools
def enabled(config):
    """
    Require an nginx site to be enabled.

    This will cause nginx to reload its configuration.

    ::

        from fabtools import require

        require.nginx.enabled('mysite')

    """
    enable(config)
    reload_service('nginx')
コード例 #16
0
ファイル: nginx.py プロジェクト: zeus911/fabtools
def disabled(config):
    """
    Require an nginx site to be disabled.

    This will cause nginx to reload its configuration.

    ::

        from fabtools import require

        require.nginx.site_disabled('default')

    """
    disable(config)
    reload_service('nginx')
コード例 #17
0
ファイル: nginx.py プロジェクト: 26lights/fabtools
def disabled(config):
    """
    Require an nginx site to be disabled.

    This will cause nginx to reload its configuration.

    ::

        from fabtools import require

        require.nginx.disabled('default')

    """
    disable(config)
    reload_service('nginx')
コード例 #18
0
ファイル: nginx.py プロジェクト: zeus911/fabtools
def enabled(config):
    """
    Require an nginx site to be enabled.

    This will cause nginx to reload its configuration.

    ::

        from fabtools import require

        require.nginx.enabled('mysite')

    """
    enable(config)
    reload_service('nginx')
コード例 #19
0
ファイル: apache.py プロジェクト: Friz-zy/fabtools
def site_disabled(config):
    """
    Require an Apache site to be disabled.

    This will cause Apache to reload its configuration.

    ::

        from fabtools import require

        require.apache.site_disabled('default')

    """
    disable_site(config)
    reload_service('apache2')
コード例 #20
0
ファイル: apache.py プロジェクト: Friz-zy/fabtools
def module_disabled(module):
    """
    Require an Apache module to be disabled.

    This will cause Apache to reload its configuration.

    ::

        from fabtools import require

        require.apache.module_disabled('rewrite')

    """
    disable_module(module)
    reload_service('apache2')
コード例 #21
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')
コード例 #22
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')