def upgrade(name): """ Upgrade an existing redcap instance using the <name> package. This input file should be in the TGZ format as packaged by this fabfile """ upgrade = True utility_redcap.make_upload_target() copy_running_code_to_backup_dir() utility_redcap.upload_package_and_extract(name, upgrade) utility.write_remote_my_cnf() offline() utility_redcap.move_software_to_live() new = utility.extract_version_from_string(name) old = utility_redcap.get_current_redcap_version() apply_incremental_db_changes(old, new) online() # run the tests but take REDCap offline again and abort if they fail if not utility_redcap.test(warn_only=True): offline() utility.delete_remote_my_cnf() abort("One or more tests failed. REDCap has been taken offline.") utility.delete_remote_my_cnf()
def upgrade(name): """ Upgrade an existing redcap instance using the <name> package. This input file should be in the TGZ format as packaged by this fabfile """ upgrade = True utility_redcap.make_upload_target() copy_running_code_to_backup_dir() utility_redcap.upload_package_and_extract(name, upgrade) utility.write_remote_my_cnf() offline() utility_redcap.move_software_to_live() new = utility.extract_version_from_string(name) old = utility_redcap.get_current_redcap_version() apply_incremental_db_changes(old,new) online() # run the tests but take REDCap offline again and abort if they fail if not utility_redcap.test(warn_only=True): offline() utility.delete_remote_my_cnf() abort("One or more tests failed. REDCap has been taken offline.") utility.delete_remote_my_cnf()
def backup_database(options=""): """ Backup a mysql database from the remote host with mysqldump options in *options*. The backup file will be time stamped with a name like 'redcap-<instance_name>-20170126T1620.sql.gz' The latest backup file will be linked to name 'redcap-<instance_name>-latest.sql.gz' """ utility.write_remote_my_cnf() now = utility.timestamp() with settings(user=env.deploy_user): run("mysqldump --skip-lock-tables %s -u %s -h %s %s | gzip > redcap-%s-%s.sql.gz" % \ (options, env.database_user, env.database_host, env.database_name, env.instance_name, now)) run("ln -sf redcap-%s-%s.sql.gz redcap-%s-latest.sql.gz" % (env.instance_name, now, env.instance_name)) utility.delete_remote_my_cnf()
def test(warn_only=False): """ Run all tests against a running REDCap instance """ utility.write_remote_my_cnf() version = get_current_redcap_version() utility.delete_remote_my_cnf() local("python tests/test.py %s/ redcap_v%s/" % (env.url_of_deployed_app,version)) with settings(warn_only=True): if local("python tests/test.py %s/ redcap_v%s/" % (env.url_of_deployed_app,version)).failed: if warn_only: warn("One or more tests failed.") return(False) else: abort("One or more tests failed.") else: return(True)
def enable(module_name, module_version="", pid=""): """ Enables a REDCap module. """ utility.write_remote_my_cnf() enable_module = """ namespace ExternalModules\ExternalModules; require '/var/www/redcap/external_modules/classes/ExternalModules.php'; #\\ExternalModules\\ExternalModules::initialize(); \\ExternalModules\\ExternalModules::enableForProject('%s', '%s'); """ %(module_name, module_version) run ('php -r \"%s\"' %enable_module) if pid != "": enable_module_for_pid = """ namespace ExternalModules\ExternalModules; require '/var/www/redcap/external_modules/classes/ExternalModules.php'; \\ExternalModules\\ExternalModules::enableForProject('%s', '%s', %s); """ %(module_name, module_version, pid) run ('php -r \"%s\"' %enable_module_for_pid) utility.delete_remote_my_cnf()
def disable(module_name, pid=""): """ Disables a REDCap module. """ utility.write_remote_my_cnf() if pid != "": disable_module_for_pid = """ namespace ExternalModules\ExternalModules; require '/var/www/redcap/external_modules/classes/ExternalModules.php'; \\ExternalModules\\ExternalModules::setProjectSetting('%s', %s, 'enabled', false); """ %(module_name, pid) run ('php -r \"%s\"' %disable_module_for_pid) else: disable_module = """ namespace ExternalModules\ExternalModules; require '/var/www/redcap/external_modules/classes/ExternalModules.php'; \\ExternalModules\\ExternalModules::disable('%s'); """ %module_name run ('php -r \"%s\"' %disable_module) utility.delete_remote_my_cnf()
def deploy(name,force=""): """ Deploy a new REDCap instance defined by <package_name>, optionally forcing redcap cron deployment """ utility_redcap.make_upload_target() utility_redcap.upload_package_and_extract(name) update_redcap_connection() utility.write_remote_my_cnf() if env.vagrant_instance: create_database() create_redcap_tables() utility_redcap.move_software_to_live() move_edocs_folder() utility_redcap.set_redcap_base_url() force_deployment_of_redcap_cron = utility.is_affirmative(force) configure_redcap_cron(env.deploy_redcap_cron, force_deployment_of_redcap_cron) utility_redcap.test() utility.delete_remote_my_cnf()
def change_online_status(state): """ Set the online/offline status with <state>. """ with settings(user=env.deploy_user): if state == "Online": offline_binary = 0 offline_message = 'The system is online.' elif state == "Offline": offline_binary = 1 offline_message = 'The system is offline.' else: abort("Invald state provided. Specify 'Online' or 'Offline'.") utility.write_remote_my_cnf() utility_redcap.set_redcap_config('system_offline', '%s' % offline_binary) utility_redcap.set_redcap_config('system_offline_message', '%s' % offline_message) utility.delete_remote_my_cnf()
def deploy(name, force=""): """ Deploy a new REDCap instance defined by <package_name>, optionally forcing redcap cron deployment """ utility_redcap.make_upload_target() utility_redcap.upload_package_and_extract(name) update_redcap_connection() utility.write_remote_my_cnf() if env.vagrant_instance: create_database() create_redcap_tables() utility_redcap.move_software_to_live() move_edocs_folder() utility_redcap.set_redcap_base_url() force_deployment_of_redcap_cron = utility.is_affirmative(force) configure_redcap_cron(env.deploy_redcap_cron, force_deployment_of_redcap_cron) utility_redcap.test() utility.delete_remote_my_cnf()