Пример #1
0
def site_disabled(server_name):
    if server_name != 'default':
        server_name += '.conf'

    link_filename = '/etc/nginx/sites-enabled/%s' % server_name
    if is_link(link_filename):
        root_run("rm %(link_filename)s" % locals())

    root_run("/etc/init.d/nginx reload")
Пример #2
0
def site_enabled(server_name):
    if server_name != 'default':
        server_name += '.conf'

    config_filename = '/etc/nginx/sites-available/%s' % server_name  # NOQA
    link_filename = '/etc/nginx/sites-enabled/%s' % server_name
    if not is_link(link_filename):
        root_run("ln -s %(config_filename)s %(link_filename)s" % locals())

    root_run("/etc/init.d/nginx reload")
Пример #3
0
def install(version='2.7.3'):
    fabtools.require.deb.packages([
        'libbz2-dev', 'build-essential', 'devscripts', 'libncurses5-dev',
        'libsqlite3-dev', 'libdb4.6-dev', 'libgdbm-dev',
        'libreadline5-dev', 'zlib1g-dev', 'curl', 'libssl-dev'
    ])

    if not is_pythonz_installed():
        root_run('curl -kL https://raw.github.com/saghul/pythonz/master/pythonz-install | bash')

    root_run('/usr/local/pythonz/bin/pythonz install %s' % version)
Пример #4
0
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):
            root_run("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 root_run("nginx -t").return_code > 0:
                    print red("Error in %(server_name)s nginx site config (disabling for safety)" % locals())
                    root_run("rm %(link_filename)s" % locals())
    else:
        if is_link(link_filename):
            root_run("rm %(link_filename)s" % locals())

    root_run("/etc/init.d/nginx reload")
Пример #5
0
def disable_site(site_name):
    if is_site_enabled(site_name):
        root_run('a2dissite %s' % _get_site_name(site_name))
Пример #6
0
def enable_site(site_name):
    if not is_site_enabled(site_name):
        root_run('a2ensite %s' % _get_site_name(site_name))
Пример #7
0
def is_started():
    """
    Check if Apache is started
    """
    ret = root_run('apache2ctl status')
    return ('Apache Server Status' in ret)
Пример #8
0
def restart():
    root_run('apache2ctl restart')
Пример #9
0
def stop():
    root_run('apache2ctl stop')
Пример #10
0
def start():
    root_run('apache2ctl start')
Пример #11
0
def install_virtualenv(version='2.7.3'):
    root_run('/usr/local/pythonz/pythons/CPython-%s/bin/pip install virtualenv' % version)
Пример #12
0
def install_pip(version='2.7.3'):
    root_run('curl http://python-distribute.org/distribute_setup.py | /usr/local/pythonz/pythons/CPython-%s/bin/python' % version)
    root_run('curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | /usr/local/pythonz/pythons/CPython-%s/bin/python' % version)