Example #1
0
def provision(update=False):
    """Uploads an install script to /project_name/scripts and runs it.
    The script will not download solr if '/tmp/{project_name}/solr.zip' exists,
    nor it will attempt an install (eg. unpack and copy) if the following file
    exists: '{supervisor_dir}/solr/fabric_solr_install_success' (root of where
    solr is installed).

    Use update=True is as an override.
    """
    # upload the script to {project_dir}/scripts/setup_solr.sh
    user = cget("user")
    solr_dir = cset('solr_dir', pjoin(cget("service_dir"), 'solr'))

    script_name = "setup_solr.sh"
    source = pjoin(cget("local_root"), 'deployment', 'scripts', script_name)

    dest_scripts = cget("script_dir")
    create_target_directories([dest_scripts, solr_dir], "700", user)

    context = dict(env['ctx'])
    destination = pjoin(dest_scripts, script_name)
    upload_template_with_perms(source, destination, context, mode="644")

    # run the script
    show(yellow("Installing solr with update=%s." % update))
    with settings(sudo_prefix=SUDO_PREFIX, warn_only=True):
        script = destination
        # the script will copy files into: MTURK/solr
        ret = sudo("MTURK={home} && UPDATE={update} && . {script}".format(
            home=cget('service_dir'),
            script=script,
            update='true' if update else 'false'))
        if ret.return_code != 0:
            show(yellow("Error while installing sorl."))
Example #2
0
def configure():
    """Creates all neccessary folders and uploads settings."""
    user = cget("user")
    sdir = pjoin(cget('service_dir'), 'nginx')
    logdir = pjoin(cget('log_dir'), 'nginx')
    create_target_directories([sdir, logdir], "700", user)
    context = dict(env["ctx"])
    local_dir = local_files_dir("nginx")
    dest_dir = "/etc/nginx"
    confs = cget("nginx_files") or [local_dir]
    show(yellow("Uploading nginx configuration files: %s." % confs))
    for name in confs:
        source = pjoin(local_dir, name)
        destination = pjoin(dest_dir, name)
        if isdir(source):
            upload_templated_folder_with_perms(source, local_dir, dest_dir,
                context, mode="644", directories_mode="700")
        else:
            upload_template_with_perms(
                source, destination, context, mode="644")
    enabled = cget("nginx_sites_enabled")
    with settings(hide("running", "stderr", "stdout"), sudo_prefix=SUDO_PREFIX,
        warn_only=True):
        show("Enabling sites: %s." % enabled)
        for s in enabled:
            available = '/etc/nginx/sites-available'
            enabled = '/etc/nginx/sites-enabled'
            ret = sudo("ln -s {available}/{site} {enabled}/{site}".format(
                available=available, enabled=enabled, site=s))
            if ret.failed:
                show(red("Error enabling site: {}: {}.".format(s, ret)))
Example #3
0
def setup_ssh():
    """Uploads ssh from the local folder specified in config."""
    user = cget("user")
    ssh_target_dir = cget("ssh_target")

    # Ensure SSH directory is created with proper perms.
    create_target_directories([ssh_target_dir], "700", user)

    # Upload SSH config and keys.
    # TODO: Add copying files from remote folder (upload_ssh_keys_from_local).
    if cget('upload_ssh_keys_from_local') or True:
        files = cget('ssh_files')
        if not files:
            show(yellow("No SSH files to upload."))
            return
        show(yellow("Uploading SSH configuration and keys"))
        for name in files:
            show(u"File: {0}".format(name))
            local_path = pjoin(local_files_dir("ssh"), name)
            remote_path = pjoin(ssh_target_dir, name)
            put_file_with_perms(local_path, remote_path, "600", user, user)
    else:
        # Remoty copying of files
        raise Exception('Not implemented!'
            ' Please set upload_ssh_keys_from_local to True!')
Example #4
0
def provision(update=False):
    """Uploads an install script to /project_name/scripts and runs it.
    The script will not download solr if '/tmp/{project_name}/solr.zip' exists,
    nor it will attempt an install (eg. unpack and copy) if the following file
    exists: '{supervisor_dir}/solr/fabric_solr_install_success' (root of where
    solr is installed).

    Use update=True is as an override.
    """
    # upload the script to {project_dir}/scripts/setup_solr.sh
    user = cget("user")
    solr_dir = cset('solr_dir', pjoin(cget("service_dir"), 'solr'))

    script_name = "setup_solr.sh"
    source = pjoin(cget("local_root"), 'deployment', 'scripts', script_name)

    dest_scripts = cget("script_dir")
    create_target_directories([dest_scripts, solr_dir], "700", user)

    context = dict(env['ctx'])
    destination = pjoin(dest_scripts, script_name)
    upload_template_with_perms(source, destination, context, mode="644")

    # run the script
    show(yellow("Installing solr with update=%s." % update))
    with settings(sudo_prefix=SUDO_PREFIX, warn_only=True):
        script = destination
        # the script will copy files into: MTURK/solr
        ret = sudo("MTURK={home} && UPDATE={update} && . {script}".format(
            home=cget('service_dir'), script=script,
            update='true' if update else 'false'))
        if ret.return_code != 0:
            show(yellow("Error while installing sorl."))
Example #5
0
def configure():
    """Creates all neccessary folders and uploads settings.
    Keep in mind that the base for filenames is /etc, because the files reside
    in /etc/crond.d/ etc. Thus those files/folders must be specified explictly.

    Additionally this will format and upload
        manage_py_exec and
        manage_py_exec_silent

    scripts.

    """
    user = cget("user")
    logdir = pjoin(cget('log_dir'), 'cron')
    create_target_directories([logdir], "700", user)

    context = dict(env["ctx"])
    local_dir = local_files_dir("cron")
    dest_dir = "/etc"
    confs = cget("cron_files")

    show(yellow("Uploading cron configuration files: %s." % confs))
    if not confs or len(confs) == 0:
        show(red("No files to upload for cron."))
        return

    for name in confs:
        source = pjoin(local_dir, name)
        destination = pjoin(dest_dir, name)
        if isdir(source):
            upload_templated_folder_with_perms(source, local_dir, dest_dir,
                context, mode="644", user='******', group='root',
                directories_mode="700")
        else:
            upload_template_with_perms(
                source, destination, context, mode="644", user='******',
                group='root')

    # format and upload command execution script used by cron
    scripts = ['manage_py_exec', 'manage_py_exec_silent']
    for script_name in scripts:
        source = pjoin(cget("local_root"), 'deployment', 'scripts',
                script_name)
        destination = pjoin(cget("script_dir"), script_name)
        upload_template_with_perms(source, destination, context, mode="755")

    show(yellow("Reloading cron"))
    with settings(hide("stderr"), warn_only=True):
        res = service("cron", "reload")
        if res.return_code == 2:
            show(red("Error reloading cron!"))
Example #6
0
def configure():
    """Creates all neccessary folders and uploads settings.
    Keep in mind that the base for filenames is /etc, because the files reside
    in /etc/crond.d/ etc. Thus those files/folders must be specified explictly.

    Additionally this will format and upload
        manage_py_exec and
        manage_py_exec_silent

    scripts.

    """
    user = cget("user")
    logdir = pjoin(cget('log_dir'), 'cron')
    create_target_directories([logdir], "700", user)

    context = dict(env["ctx"])
    local_dir = local_files_dir("cron")
    dest_dir = "/etc"
    confs = cget("cron_files")

    show(yellow("Uploading cron configuration files: %s." % confs))
    if not confs or len(confs) == 0:
        show(red("No files to upload for cron."))
        return

    for name in confs:
        source = pjoin(local_dir, name)
        destination = pjoin(dest_dir, name)
        if isdir(source):
            upload_templated_folder_with_perms(source, local_dir, dest_dir,
                context, mode="644", user='******', group='root',
                directories_mode="700")
        else:
            upload_template_with_perms(
                source, destination, context, mode="644", user='******', group='root')

    # format and upload command execution script used by cron
    scripts = ['manage_py_exec', 'manage_py_exec_silent']
    for script_name in scripts:
        source = pjoin(cget("local_root"), 'deployment', 'scripts', script_name)
        destination = pjoin(cget("script_dir"), script_name)
        upload_template_with_perms(source, destination, context, mode="755")

    show(yellow("Reloading cron"))
    with settings(hide("stderr"), sudo_prefix=SUDO_PREFIX, warn_only=True):
        res = sudo("service cron reload")
        if res.return_code == 2:
            show(red("Error reloading cron!"))
Example #7
0
def prepare_target_env():
    """Prepare all things needed before source code deployment."""
    user = cget("user")
    project_dir = cget("project_dir")

    # Ensure proper directory structure.
    create_target_directories([project_dir], '755', user)

    dirs = ["code", "logs", "logs/old", "misc", "virtualenv",
        "media", "static", "scripts", "services"]
    dirs = [pjoin(project_dir, d) for d in dirs]
    create_target_directories(dirs, "755", user)

    # Create Virtualenv if not present.
    create_virtualenv()
Example #8
0
def prepare_target_env():
    """Prepare all things needed before source code deployment."""
    user = cget("user")
    project_dir = cget("project_dir")

    # Ensure proper directory structure.
    create_target_directories([project_dir], '755', user)

    dirs = [
        "code", "logs", "logs/old", "misc", "virtualenv", "media", "static",
        "scripts", "services"
    ]
    dirs = [pjoin(project_dir, d) for d in dirs]
    create_target_directories(dirs, "755", user)

    # Create Virtualenv if not present.
    create_virtualenv()
Example #9
0
def setup_ssh():
    """Uploads ssh from the local folder specified in config."""
    user = cget("user")
    ssh_target_dir = cget("ssh_target")

    # Ensure SSH directory is created with proper perms.
    create_target_directories([ssh_target_dir], "700", user)

    # Upload SSH config and keys.
    # TODO: Add copying files from remote folder (upload_ssh_keys_from_local).
    if cget('upload_ssh_keys_from_local') or True:
        files = cget('ssh_files')
        show(yellow("Uploading SSH configuration and keys"))
        for name in files:
            show(u"File: {0}".format(name))
            local_path = pjoin(local_files_dir("ssh"), name)
            remote_path = pjoin(ssh_target_dir, name)
            put_file_with_perms(local_path, remote_path, "600", user, user)
    else:
        # Remoty copying of files
        raise Exception('Not implemented!'
                        ' Please set upload_ssh_keys_from_local to True!')
Example #10
0
def configure():
    """Creates all neccessary folders and uploads settings."""
    user = cget("user")
    sdir = pjoin(cget('service_dir'), 'nginx')
    logdir = pjoin(cget('log_dir'), 'nginx')
    create_target_directories([sdir, logdir], "700", user)
    context = dict(env["ctx"])
    local_dir = local_files_dir("nginx")
    dest_dir = "/etc/nginx"
    confs = cget("nginx_files") or [local_dir]
    show(yellow("Uploading nginx configuration files: %s." % confs))
    for name in confs:
        source = pjoin(local_dir, name)
        destination = pjoin(dest_dir, name)
        if isdir(source):
            upload_templated_folder_with_perms(source,
                                               local_dir,
                                               dest_dir,
                                               context,
                                               mode="644",
                                               directories_mode="700")
        else:
            upload_template_with_perms(source,
                                       destination,
                                       context,
                                       mode="644")
    enabled = cget("nginx_sites_enabled")
    with settings(hide("running", "stderr", "stdout"),
                  sudo_prefix=SUDO_PREFIX,
                  warn_only=True):
        show("Enabling sites: %s." % enabled)
        for s in enabled:
            available = '/etc/nginx/sites-available'
            enabled = '/etc/nginx/sites-enabled'
            ret = sudo("ln -s {available}/{site} {enabled}/{site}".format(
                available=available, enabled=enabled, site=s))
            if ret.failed:
                show(red("Error enabling site: {}: {}.".format(s, ret)))