def setup_backup(cls): # currently using root, not nice but we su into postgres lexists(os.path) curr_dir = os.path.realpath(os.path.dirname(__file__)) backup_script = os.path.join(curr_dir, "database_backup.sh") if not os.path.isfile(backup_script): raise ValueError( "Unable to find the file {}".format(backup_script) ) os.chmod(backup_script, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR) if not os.access(backup_script, os.X_OK): raise ValueError( "Unable to execute {}".format(backup_script) ) comment = cls.get_comment() crontab = CronTab(user=True) crontab.remove_all(comment=comment) job = crontab.new(command=backup_script, comment=comment) # run every day job.every().dom() crontab.write()
def symlink_upstart(): absPathUpstartConf = os.path.join(env.project_path, "etc/upstart.conf") if not lexists(absPathUpstartConf): raise ValueError("we expect an upstart conf to exist") symlink_name = '/etc/init/{}.conf'.format(env.project_name) if lexists(symlink_name): local("sudo rm {}".format(symlink_name)) local('sudo ln -s {0} {1}'.format(absPathUpstartConf, symlink_name))
def symlink_nginx(): absPathNginxConf = os.path.join(env.project_path, "etc/nginx.conf") if not lexists(absPathNginxConf): raise ValueError("we expect an nginx conf to exist") symlink_name = '/etc/nginx/sites-enabled/{}'.format(env.project_name) if lexists(symlink_name): local("sudo rm {}".format(symlink_name)) local('sudo ln -s {0} {1}'.format(absPathNginxConf, symlink_name))
def install_postgres(): hba_conf = "/etc/postgresql/{0}/main/pg_hba.conf".format( ".".join(str(i) for i in env.pg_version) ) if lexists(hba_conf): local("rm {}".format(hba_conf)) local("sudo cp database/pg_hba.conf {0}".format(hba_conf)) restart_database()
def install_postgres(): hba_conf = "/etc/postgresql/{0}/main/pg_hba.conf".format(".".join( str(i) for i in env.pg_version)) if lexists(hba_conf): local("sudo rm {}".format(hba_conf)) local("sudo cp database/pg_hba.conf {0}".format(hba_conf)) local("sudo chown postgres:postgres {0}".format(hba_conf)) Postgres.restart_database()
def create_local_settings(cls): env_values = { "db_name": env.db_name, "app_user": env.app_owner, "app_password": env.app_password } template = jinja_env.get_template('production_settings.py.jinja2') output = template.render(env_values) local_settings_file = '{0}/{1}/local_settings.py'.format(env.project_path, env.app_name) if not lexists(local_settings_file): with open(local_settings_file, 'w+') as f: f.write(output)
def write_conf(cls, conf_name, env_values): confirmed = False local_conf = '{0}/etc/{1}.conf'.format(env.project_path, conf_name) conf_exists = lexists(local_conf) if conf_exists: confirmed = confirm( 'Local {} exists, would you like to replace it?'.format( conf_name), ) if not confirmed: return template = jinja_env.get_template('{}.conf.jinja2'.format(conf_name)) output = template.render(env_values) with open(local_conf, 'w') as f: f.write(output)
def create_local_settings(cls): env_values = { "db_name": env.db_name, "app_user": env.app_owner, "app_password": env.app_password } template = jinja_env.get_template('production_settings.py.jinja2') output = template.render(env_values) module_name = env.app_name if env.settings_module_name: module_name = env.settings_module_name local_settings_file = '{0}/{1}/local_settings.py'.format( env.project_path, module_name) if not lexists(local_settings_file): with open(local_settings_file, 'w+') as f: f.write(output)
def create_virtual_env(cls): cls.install_virtualenv() if not lexists(env.virtual_env_path): local("/usr/bin/virtualenv {0}".format(env.virtual_env_path))
def create_directory(dir_name): if not lexists(dir_name): local("mkdir -p {}".format(dir_name))
def install_nginx(): Apt.install('nginx') assert lexists('/etc/nginx/sites-enabled') if lexists('/etc/nginx/sites-enabled/default'): local("rm /etc/nginx/sites-enabled/default")
def make_home_directory(): if not lexists(env.home_dir): local("sudo mkdir -p {}".format(env.home_dir)) local("sudo chown ohc:ohc {0}".format(env.home_dir))
def make_home_directory(): if not lexists(env.home_dir): local("sudo mkdir -p {}".format(env.home_dir)) local("sudo chown ohc:ohc {0}".format(env.home_dir))
def create_directory(dir_name): if not lexists(dir_name): local("mkdir -p {}".format(dir_name))
def install_nginx(): Apt.install('nginx') assert lexists('/etc/nginx/sites-enabled') if lexists('/etc/nginx/sites-enabled/default'): local("sudo rm /etc/nginx/sites-enabled/default")