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."))
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)))
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!"))
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!"))
def configure(): """Uploads postgresql configuration files.""" context = dict(env["ctx"]) local_dir = local_files_dir("postgresql") dest_dir = "/etc/postgresql" confs = cget("postgresql_files") or [local_dir] show(yellow("Uploading postgresql configuration files: {}.".format(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")
def configure(): """Uploads solr configuration files.""" context = dict(env["ctx"]) local_dir = local_files_dir("solr") dest_dir = pjoin(cget('service_dir'), 'solr') confs = cget("solr_files") or [local_dir] show(yellow("Uploading solr 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")
def upload_settings_files(): """Uploads target specific (templated) settings files. If specified also uploads user supplied locals.py. *Warning*: Settings are uploaded from your local template file. Make sure to have proper branch/revision checked out. """ base_dir = cget("base_dir") user = cget("user") locals_path = cget("locals_path") show(yellow("Uploading Django settings files.")) # This is Template context not the deployment context. # A split should happen some time. context = dict(env["ctx"]) context # Upload main settings and ensure permissions. source = pjoin(local_files_dir("django"), "settings_template.py") destination = pjoin(base_dir, "settings", "%s.py" % cget("settings_name")) upload_template_with_perms(source, destination, context, mode="644", user=user, group=user) # We could be deploying from different directory. # Try our best to find correct path. # First - direct, absolute match. if not os.path.isfile(locals_path): # Try relative to deployment directory. this_dir = os.path.dirname(os.path.abspath(__file__)) locals_path = pjoin(this_dir, locals_path) if not os.path.isfile(locals_path): # :(( msg = u"Warning: Specified local settings path is incorrect: {0}." show(red(msg.format(locals_path))) confirm_or_abort(red("\nDo you want to continue?")) locals_path = None # Upload user supplied locals if present. if locals_path: show(yellow("Uploading your custom local settings files.")) destination = pjoin(base_dir, "settings", "local.py") put_file_with_perms(locals_path, destination, mode="644", user=user, group=user)
def configure(): """Uploads postgresql configuration files.""" context = dict(env["ctx"]) local_dir = local_files_dir("postgresql") dest_dir = "/etc/postgresql" confs = cget("postgresql_files") or [local_dir] show(yellow("Uploading postgresql 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")
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)))