예제 #1
0
def configure_tomcat(path, overwrite=False):
    from fabric.contrib.files import append
    startup_script = """
#!/bin/sh
### BEGIN INIT INFO
# Provides:          tomcat
# Required-Start:    $local_fs $remote_fs $network $syslog $named
# Required-Stop:     $local_fs $remote_fs $network $syslog $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Tomcat
# Description:       Start Tomcat
### END INIT INFO

case $1 in
start)
sh %(path)s/bin/startup.sh
;;
stop)
sh %(path)s/bin/shutdown.sh
;;
restart)
sh %(path)s/bin/shutdown.sh
sh %(path)s/bin/startup.sh
;;
esac
exit 0""" % {
        'path': path
    }

    # Check for existing files and overwrite.
    if is_file('/etc/init.d/tomcat'):
        if overwrite is False:
            raise OSError(
                "/etc/init.d/tomcat already exists and not overwriting.")
        else:
            run_as_root("rm -f /etc/init.d/tomcat")

    # Now create the file and symlinks.
    append('/etc/init.d/tomcat', startup_script, use_sudo=True)
    run_as_root('chmod 755 /etc/init.d/tomcat')

    if not is_link('/etc/rc1.d/K99tomcat'):
        run_as_root('ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat')

    if not is_link('/etc/rc2.d/S99tomcat'):
        run_as_root('ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat')
예제 #2
0
def test_site_enabled(nginx_server):

    from burlap.require.nginx import enabled as require_nginx_site_enabled
    from burlap.files import is_link

    require_nginx_site_enabled('default')
    assert is_link('/etc/nginx/sites-enabled/default')
예제 #3
0
def install_from_oracle_site(version=DEFAULT_VERSION):
    """
    Download tarball from Oracle site and install JDK.

    ::

        import burlap

        # Install Oracle JDK
        burlap.oracle_jdk.install_from_oracle_site()

    """

    prefix = '/opt'

    release, build = version.split('-')
    major, update = release.split('u')
    if len(update) == 1:
        update = '0' + update

    arch = _required_jdk_arch()

    self_extracting_archive = (major == '6')

    extension = 'bin' if self_extracting_archive else 'tar.gz'
    filename = 'jdk-%(release)s-linux-%(arch)s.%(extension)s' % locals()
    download_path = posixpath.join('/tmp', filename)
    url = 'http://download.oracle.com/otn-pub/java/jdk/%(version)s/%(filename)s' % locals()

    _download(url, download_path)

    # Prepare install dir
    install_dir = 'jdk1.%(major)s.0_%(update)s' % locals()
    with cd(prefix):
        if is_dir(install_dir):
            run_as_root('rm -rf %s' % quote(install_dir))

    # Extract
    if self_extracting_archive:
        run('chmod u+x %s' % quote(download_path))
        with cd('/tmp'):
            run_as_root('rm -rf %s' % quote(install_dir))
            run_as_root('./%s' % filename)
            run_as_root('mv %s %s' % (quote(install_dir), quote(prefix)))
    else:
        with cd(prefix):
            run_as_root('tar xzvf %s' % quote(download_path))

    # Set up link
    link_path = posixpath.join(prefix, 'jdk')
    if is_link(link_path):
        run_as_root('rm -f %s' % quote(link_path))
    run_as_root('ln -s %s %s' % (quote(install_dir), quote(link_path)))

    # Remove archive
    run('rm -f %s' % quote(download_path))

    _create_profile_d_file(prefix)
예제 #4
0
def configure_tomcat(path, overwrite=False):
    from fabric.contrib.files import append
    startup_script = """
#!/bin/sh
### BEGIN INIT INFO
# Provides:          tomcat
# Required-Start:    $local_fs $remote_fs $network $syslog $named
# Required-Stop:     $local_fs $remote_fs $network $syslog $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Tomcat
# Description:       Start Tomcat
### END INIT INFO

case $1 in
start)
sh %(path)s/bin/startup.sh
;;
stop)
sh %(path)s/bin/shutdown.sh
;;
restart)
sh %(path)s/bin/shutdown.sh
sh %(path)s/bin/startup.sh
;;
esac
exit 0""" % {'path': path}

    # Check for existing files and overwrite.
    if is_file('/etc/init.d/tomcat'):
        if overwrite is False:
            raise OSError("/etc/init.d/tomcat already exists and not overwriting.")
        else:
            run_as_root("rm -f /etc/init.d/tomcat")

    # Now create the file and symlinks.
    append('/etc/init.d/tomcat', startup_script, use_sudo=True)
    run_as_root('chmod 755 /etc/init.d/tomcat')

    if not is_link('/etc/rc1.d/K99tomcat'):
        run_as_root('ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat')

    if not is_link('/etc/rc2.d/S99tomcat'):
        run_as_root('ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat')
예제 #5
0
파일: nginx.py 프로젝트: noeldvictor/burlap
def disable(config):
    """
    Delete link in /etc/nginx/sites-enabled/

    (does not reload nginx config)

    ::
        from burlap import require

        require.nginx.disable('default')

    .. seealso:: :py:func:`burlap.require.nginx.disabled`
    """
    link_filename = '/etc/nginx/sites-enabled/%s' % config

    if is_link(link_filename):
        run_as_root("rm %(link_filename)s" % locals())
예제 #6
0
파일: nginx.py 프로젝트: noeldvictor/burlap
def disable(config):
    """
    Delete link in /etc/nginx/sites-enabled/

    (does not reload nginx config)

    ::
        from burlap import require

        require.nginx.disable('default')

    .. seealso:: :py:func:`burlap.require.nginx.disabled`
    """
    link_filename = '/etc/nginx/sites-enabled/%s' % config

    if is_link(link_filename):
        run_as_root("rm %(link_filename)s" % locals())
예제 #7
0
파일: nginx.py 프로젝트: noeldvictor/burlap
def enable(config):
    """
    Create link from /etc/nginx/sites-available/ in /etc/nginx/sites-enabled/

    (does not reload nginx config)

    ::
        from burlap import require

        require.nginx.enable('default')

    .. seealso:: :py:func:`burlap.require.nginx.enabled`
    """
    config_filename = '/etc/nginx/sites-available/%s' % config
    link_filename = '/etc/nginx/sites-enabled/%s' % config

    if not is_link(link_filename):
        run_as_root("ln -s %(config_filename)s %(link_filename)s" % {
            'config_filename': quote(config_filename),
            'link_filename': quote(link_filename),
        })
예제 #8
0
파일: nginx.py 프로젝트: noeldvictor/burlap
def enable(config):
    """
    Create link from /etc/nginx/sites-available/ in /etc/nginx/sites-enabled/

    (does not reload nginx config)

    ::
        from burlap import require

        require.nginx.enable('default')

    .. seealso:: :py:func:`burlap.require.nginx.enabled`
    """
    config_filename = '/etc/nginx/sites-available/%s' % config
    link_filename = '/etc/nginx/sites-enabled/%s' % config

    if not is_link(link_filename):
        run_as_root(
            "ln -s %(config_filename)s %(link_filename)s" % {
                'config_filename': quote(config_filename),
                'link_filename': quote(link_filename),
            })
예제 #9
0
def is_site_enabled(site_name):
    """
    Check if an Apache site is enabled.
    """
    return is_link(_site_link_path(site_name))
예제 #10
0
def is_site_enabled(site_name):
    """
    Check if an Apache site is enabled.
    """
    return is_link(_site_link_path(site_name))
예제 #11
0
def is_module_enabled(module):
    """
    Check if an Apache module is enabled.
    """
    return is_link('/etc/apache2/mods-enabled/%s.load' % module)
예제 #12
0
def test_require_site_enabled(apache, example_site):
    from burlap.require.apache import site_enabled
    site_enabled(example_site)
    assert is_link('/etc/apache2/sites-enabled/{0}.conf'.format(example_site))
예제 #13
0
def test_require_module_enabled(apache):
    from burlap.require.apache import module_enabled
    module_enabled('rewrite')
    assert is_link('/etc/apache2/mods-enabled/rewrite.load')
예제 #14
0
파일: nginx.py 프로젝트: noeldvictor/burlap
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 burlap 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:`burlap.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')
예제 #15
0
파일: nginx.py 프로젝트: noeldvictor/burlap
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 burlap 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:`burlap.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')
예제 #16
0
def is_module_enabled(module):
    """
    Check if an Apache module is enabled.
    """
    return is_link('/etc/apache2/mods-enabled/%s.load' % module)
예제 #17
0
def test_require_site_enabled(apache, example_site):
    from burlap.require.apache import site_enabled
    site_enabled(example_site)
    assert is_link('/etc/apache2/sites-enabled/{0}.conf'.format(example_site))
예제 #18
0
def test_require_module_enabled(apache):
    from burlap.require.apache import module_enabled
    module_enabled('rewrite')
    assert is_link('/etc/apache2/mods-enabled/rewrite.load')