Beispiel #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."))
Beispiel #2
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."))
Beispiel #3
0
def update_args(ctx, instance, branch, commit, locals_path, requirements,
                setup_environment):
    """Check args and update ctx."""
    # Do the sanity checks.
    instance = cset("instance", instance)
    if not instance or not instance.isalnum():
        abort("You have to specify a proper alphanumeric instance name!")
    if branch is not None and commit is not None:
        abort("You can only deploy specific commit OR specific branch")
    commit and cset("commit", commit, force=True)
    branch and cset("branch", branch, force=True)
    cset("locals_path", locals_path)
    cset("requirements", get_boolean(requirements))
    cset("setup_environment", get_boolean(setup_environment))
    return ctx
Beispiel #4
0
def update_args(ctx, instance, branch, commit, locals_path, requirements,
        setup_environment):
    """Check args and update ctx."""
    # Do the sanity checks.
    instance = cset("instance", instance)
    if not instance or not instance.isalnum():
        abort("You have to specify a proper alphanumeric instance name!")
    if branch is not None and commit is not None:
        abort("You can only deploy specific commit OR specific branch")
    commit and cset("commit", commit, force=True)
    branch and cset("branch", branch, force=True)
    cset("locals_path", locals_path)
    cset("requirements", get_boolean(requirements))
    cset("setup_environment", get_boolean(setup_environment))
    return ctx
Beispiel #5
0
def set_instance_conf():
    """Compute all instance specific paths and settings.
    Put *all* settings computation login here.
    """
    # Use to escape % characters in config files
    cset("p", '%')
    cset("percent_escape_key", "p")

    # System
    cset("user", env["user"])

    # Common project settings.
    cset("prefix", cget("default_prefix"))
    cset("project_name", "%s-%s" % (cget("prefix"), cget("instance")))
    cset(
        'settings_full_name', '.'.join(
            [cget('django_project_name'), 'settings',
             cget('settings_name')]))

    # Host directories
    cset("project_dir", pjoin(cget("projects_dir"), cget("project_name")))
    cset("virtualenv_dir", pjoin(cget("project_dir"), "virtualenv"))
    cset("deployment_files",
         pjoin(cget("project_dir"), "code", "deployment", "files"))
    cset('service_dir', pjoin(cget("project_dir"), "services"))
    cset("script_dir", pjoin(cget("project_dir"), "scripts"))

    # Local directories
    this_dir = os.path.dirname(os.path.abspath(__file__))
    deployment_dir = os.path.abspath(pjoin(this_dir, os.path.pardir))
    cset('local_root', deployment_dir)

    # Directory with manage.py script.
    if not os.path.isabs(cget('manage_py_dir')):
        mpy_dir = pjoin(cget("project_dir"), "code", cget('manage_py_dir'))
        cset("manage_py_dir", mpy_dir, force=True)
    cset("base_dir", pjoin(cget("project_dir"), "code", cget("project_inner")))
    cset("log_dir", pjoin(cget("project_dir"), "logs"))
    cset("doc_dir", pjoin(cget("project_dir"), "doc"))

    # Database settings
    cset("db_name", "%s_%s" % (cget("prefix"), cget("instance")))
    cset("db_user", cget("db_name"))
    cset("db_password", cget("db_user"))
    cset("db_port", "")
    cset("db_host", "localhost")

    # SSH
    user = cget("user")
    cget("ssh_target") or cset("ssh_target", "/home/%s/.ssh" % user)
Beispiel #6
0
def set_instance_conf():
    """Compute all instance specific paths and settings.
    Put *all* settings computation login here.
    """
    # Use to escape % characters in config files
    cset("p", '%')
    cset("percent_escape_key", "p")

    # System
    cset("user", env["user"])

    # Common project settings.
    cset("prefix", cget("default_prefix"))
    cset("project_name", "%s-%s" % (cget("prefix"), cget("instance")))
    cset('settings_full_name', '.'.join([cget('django_project_name'),
        'settings', cget('settings_name')]))

    # Host directories
    cset("project_dir", pjoin(cget("projects_dir"), cget("project_name")))
    cset("virtualenv_dir", pjoin(cget("project_dir"), "virtualenv"))
    cset("deployment_files", pjoin(cget("project_dir"), "code", "deployment",
        "files"))
    cset('service_dir', pjoin(cget("project_dir"), "services"))
    cset("script_dir", pjoin(cget("project_dir"), "scripts"))

    # Local directories
    this_dir = os.path.dirname(os.path.abspath(__file__))
    deployment_dir = os.path.abspath(pjoin(this_dir, os.path.pardir))
    cset('local_root',  deployment_dir)

    # Directory with manage.py script.
    if not os.path.isabs(cget('manage_py_dir')):
        mpy_dir = pjoin(cget("project_dir"), "code", cget('manage_py_dir'))
        cset("manage_py_dir", mpy_dir, force=True)
    cset("base_dir", pjoin(cget("project_dir"), "code", cget("project_inner")))
    cset("log_dir", pjoin(cget("project_dir"), "logs"))
    cset("doc_dir", pjoin(cget("project_dir"), "doc"))

    # Database settings
    cset("db_name", "%s_%s" % (cget("prefix"), cget("instance")))
    cset("db_user", cget("db_name"))
    cset("db_password", cget("db_user"))
    cset("db_port", "")
    cset("db_host", "localhost")

    # SSH
    user = cget("user")
    cget("ssh_target") or cset("ssh_target", "/home/%s/.ssh" % user)