def update_postgresql_crontab(): config = hookenv.config() data = dict(config) data['scripts_dir'] = helpers.scripts_dir() data['is_master'] = replication.is_master() data['is_primary'] = postgresql.is_primary() if config['wal_e_storage_uri']: data['wal_e_enabled'] = True data['wal_e_backup_command'] = wal_e.wal_e_backup_command() data['wal_e_prune_command'] = wal_e.wal_e_prune_command() else: data['wal_e_enabled'] = False destination = os.path.join(helpers.cron_dir(), 'juju-postgresql') templating.render('postgres.cron.tmpl', destination, data, owner='root', group='postgres', perms=0o640)
def write_metrics_cronjob(): config = hookenv.config() path = os.path.join(helpers.cron_dir(), 'juju-postgresql-metrics') # Validated in preflight.block_on_invalid_config() metrics_target = config['metrics_target'].strip() metrics_sample_interval = config['metrics_sample_interval'] reactive.remove_state('postgresql.metrics.needs_update') if not metrics_target: if os.path.exists(path): hookenv.log('Turning off metrics cronjob') os.unlink(path) return charm_dir = hookenv.charm_dir() statsd_host, statsd_port = metrics_target.split(':', 1) metrics_prefix = config['metrics_prefix'].strip() metrics_prefix = metrics_prefix.replace( "$UNIT", hookenv.local_unit().replace('.', '-').replace('/', '-')) # ensure script installed charm_script = os.path.join(charm_dir, 'files', 'metrics', 'postgres_to_statsd.py') script_path = os.path.join(helpers.scripts_dir(), 'postgres_to_statsd.py') with open(charm_script, 'r') as f: helpers.write(script_path, f.read(), mode=0o755) # write the crontab data = dict(interval=config['metrics_sample_interval'], script_path=script_path, metrics_prefix=metrics_prefix, metrics_sample_interval=metrics_sample_interval, statsd_host=statsd_host, statsd_port=statsd_port) templating.render('metrics_cronjob.template', charm_script, data, perms=0o644)
def write_metrics_cronjob(): config = hookenv.config() path = os.path.join(helpers.cron_dir(), "juju-postgresql-metrics") # Validated in preflight.block_on_invalid_config() metrics_target = config["metrics_target"].strip() metrics_sample_interval = config["metrics_sample_interval"] reactive.remove_state("postgresql.metrics.needs_update") if not metrics_target: if os.path.exists(path): hookenv.log("Turning off metrics cronjob") os.unlink(path) return charm_dir = hookenv.charm_dir() statsd_host, statsd_port = metrics_target.split(":", 1) metrics_prefix = config["metrics_prefix"].strip() metrics_prefix = metrics_prefix.replace("$UNIT", hookenv.local_unit().replace(".", "-").replace("/", "-")) # ensure script installed charm_script = os.path.join(charm_dir, "files", "metrics", "postgres_to_statsd.py") script_path = os.path.join(helpers.scripts_dir(), "postgres_to_statsd.py") with open(charm_script, "r") as f: helpers.write(script_path, f.read(), mode=0o755) # write the crontab data = dict( interval=config["metrics_sample_interval"], script_path=script_path, metrics_prefix=metrics_prefix, metrics_sample_interval=metrics_sample_interval, statsd_host=statsd_host, statsd_port=statsd_port, ) templating.render("metrics_cronjob.template", charm_script, data, perms=0o644)
def update_postgresql_crontab(): config = hookenv.config() data = dict(config) data["scripts_dir"] = helpers.scripts_dir() data["is_master"] = replication.is_master() data["is_primary"] = postgresql.is_primary() if config["wal_e_storage_uri"]: data["wal_e_enabled"] = True data["wal_e_backup_command"] = wal_e.wal_e_backup_command() data["wal_e_prune_command"] = wal_e.wal_e_prune_command() else: data["wal_e_enabled"] = False destination = os.path.join(helpers.cron_dir(), "juju-postgresql") templating.render( "postgres.cron.tmpl", destination, data, owner="root", group="postgres", perms=0o640, )
def remove_postgresql_crontab(): """When PostgreSQL is not running, we don't want any cron jobs firing.""" path = os.path.join(helpers.cron_dir(), "juju-postgresql") if os.path.exists(path): os.unlink(path)
def remove_postgresql_crontab(): '''When PostgreSQL is not running, we don't want any cron jobs firing.''' path = os.path.join(helpers.cron_dir(), 'juju-postgresql') if os.path.exists(path): os.unlink(path)