Exemple #1
0
def database(name, owner, template='template0', encoding='UTF8',
             locale='en_US.UTF-8', allow_restart=False):
    """
    Require a PostgreSQL database.

    ::

        from fabtools import require

        require.postgres.database('myapp', owner='dbuser')
    """

    locale_transform = lambda l: l.strip().lower().replace('-', '')

    if not database_exists(name):
        locales = map(
            locale_transform,
            run('locale -a').split()
        )
        if locale_transform(locale) not in locales:
            if not allow_restart:
                abort(
                    'New locale "{}" must be installed and '
                    'postgres must be restarted after that'.format(
                        locale
                    )
                )
            require_locale(locale)
            restarted(_service_name())

        create_database(name, owner, template=template, encoding=encoding,
                        locale=locale)
def install():
    packages([
        'build-essential',
        'php5',
        'php5-mysql',
    ], update=False)

    mysql(password="******")

    apache()
    stopped('apache2')
    site_disabled('default')
    site(
        'mylampvm.dev',
        template_source=full_path + '/templates/apache2/vhost.tpl',
        port=80,
        server_name='mylampvm.dev',
        document_root='/srv',
    )

    template_file(
        template_source = full_path + '/templates/apache2/envvars.tpl',
        path='/etc/apache2/envvars',
        context = {
            'apache_run_user': '******',
            'apache_run_group': 'vagrant',
        },
        owner = 'root',
        group = 'root',
        use_sudo=True
    )
    directory('/var/lock/apache2', True, 'vagrant', 'vagrant')
    
    # site_enabled('mylampvm.dev')
    restarted('apache2')
Exemple #3
0
def install():
    packages([
        'build-essential',
        'php5',
        'php5-mysql',
    ], update=False)

    mysql(password="******")

    apache()
    stopped('apache2')
    site_disabled('default')
    site(
        'mylampvm.dev',
        template_source=full_path + '/templates/apache2/vhost.tpl',
        port=80,
        server_name='mylampvm.dev',
        document_root='/srv',
    )

    template_file(template_source=full_path + '/templates/apache2/envvars.tpl',
                  path='/etc/apache2/envvars',
                  context={
                      'apache_run_user': '******',
                      'apache_run_group': 'vagrant',
                  },
                  owner='root',
                  group='root',
                  use_sudo=True)
    directory('/var/lock/apache2', True, 'vagrant', 'vagrant')

    # site_enabled('mylampvm.dev')
    restarted('apache2')
Exemple #4
0
def database(name,
             owner,
             template='template0',
             encoding='UTF8',
             locale='en_US.UTF-8'):
    """
    Require a PostgreSQL database.

    ::

        from fabtools import require

        require.postgres.database('myapp', owner='dbuser')

    """
    if not database_exists(name):

        if locale not in run('locale -a').split():
            require_locale(locale)
            restarted(_service_name())

        create_database(name,
                        owner,
                        template=template,
                        encoding=encoding,
                        locale=locale)
Exemple #5
0
def database(name,
             owner,
             template='template0',
             encoding='UTF8',
             locale='en_US.UTF-8'):
    """
    Require a PostgreSQL database.

    ::

        from fabtools import require

        require.postgres.database('myapp', owner='dbuser')

    """
    if not database_exists(name):

        with watch('/etc/locale.gen') as locales:
            require_locale(locale)
        if locales.changed:
            restarted(_service_name())

        create_database(name,
                        owner,
                        template=template,
                        encoding=encoding,
                        locale=locale)
Exemple #6
0
def database(name, owner, template="template0", encoding="UTF8", locale="en_US.UTF-8"):
    """
    Require a PostgreSQL database.

    ::

        from fabtools import require

        require.postgres.database('myapp', owner='dbuser')

    """
    if not database_exists(name):

        if locale not in run("locale -a").split():
            require_locale(locale)
            restarted(_service_name())

        create_database(name, owner, template=template, encoding=encoding, locale=locale)
Exemple #7
0
def database(name, owner, template='template0', encoding='UTF8',
             locale='en_US.UTF-8'):
    """
    Require a PostgreSQL database.

    ::

        from fabtools import require

        require.postgres.database('myapp', owner='dbuser')

    """
    if not database_exists(name):

        with watch('/etc/locale.gen') as locales:
            require_locale(locale)
        if locales.changed:
            restarted(_service_name())

        create_database(name, owner, template=template, encoding=encoding,
                        locale=locale)
Exemple #8
0
def site(server_name, template_contents=None, template_source=None, enabled=True, check_config=True, **kwargs):
    """
    Require an apache2 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

        VHOST_SITE_TEMPLATE = '''
        NameVirtualHost %(server_name)s:%(port)s
        <VirtualHost %(server_name)s:%(port)s>
          ServerName %(server_name)s
          ServerAdmin webmaster@%(server_name)s
          DocumentRoot %(docroot)s
          <Directory %(docroot)s>
            AllowOverride all
            Order allow,deny
            allow from all
          </Directory>
          ErrorLog /var/log/apache2/%(server_name)s.error.log
          CustomLog /var/log/apache2/%(server_name)s.access.log combined
          LogLevel warn
          ServerSignature Off
        </VirtualHost>
        '''

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

    .. seealso:: :py:func:`fabtools.require.files.template_file`
    """

    server()

    config_filename = "/etc/apache2/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/apache2/sites-enabled/%s.conf" % server_name
    if enabled:
        if not is_link(link_filename):
            sudo("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 not sudo("apache2ctl configtest" % locals()) == "Syntax OK":
                    print red("Error in %(server_name)s apache2 site config (disabling for safety)" % locals())
                    sudo("rm %(link_filename)s" % locals())
    else:
        if is_link(link_filename):
            sudo("rm %(link_filename)s" % locals())

    restarted("apache2")