25
25
sys.path.append(hooks_dir)
27
27
from charmhelpers.core import hookenv
31
32
def replication_pause(params):
32
offset = hooks.postgresql_wal_received_offset()
33
if not postgresql.is_secondary():
34
34
hookenv.action_fail('Not a hot standby')
37
offset = postgresql.wal_received_offset()
36
38
hookenv.action_set(dict(offset=offset))
38
cur = hooks.db_cursor(autocommit=True)
40
con = postgresql.connect()
39
43
cur.execute('SELECT pg_is_xlog_replay_paused()')
40
44
if cur.fetchone()[0] is True:
41
45
hookenv.action_fail('Already paused')
47
51
def replication_resume(params):
48
offset = hooks.postgresql_wal_received_offset()
52
if not postgresql.is_secondary():
50
53
hookenv.action_fail('Not a hot standby')
56
offset = postgresql.wal_received_offset()
52
57
hookenv.action_set(dict(offset=offset))
54
cur = hooks.db_cursor(autocommit=True)
59
con = postgresql.connect()
55
62
cur.execute('SELECT pg_is_xlog_replay_paused()')
56
63
if cur.fetchone()[0] is False:
57
64
hookenv.action_fail('Already resumed')
60
67
hookenv.action_set(dict(result='Resumed'))
70
# Revisit this when actions are more mature. Per Bug #1483525, it seems
71
# impossible to return filenames in our results.
74
# assert params['type'] == 'dump'
75
# script = os.path.join(helpers.scripts_dir(), 'pg_backup_job')
76
# cmd = ['sudo', '-u', 'postgres', '-H', script, str(params['retention'])]
77
# hookenv.action_set(dict(command=' '.join(cmd)))
80
# subprocess.check_call(cmd)
81
# except subprocess.CalledProcessError as x:
82
# hookenv.action_fail(str(x))
86
# for filename in os.listdir(backups_dir):
87
# path = os.path.join(backups_dir, filename)
88
# if not is.path.isfile(path):
90
# backups['{}.{}'.format(filename
91
# backups[filename] = dict(name=filename,
92
# size=os.path.getsize(path),
94
# scp_path='{}:{}'.format(unit, path))
95
# hookenv.action_set(dict(backups=backups))
64
99
action = os.path.basename(argv[0])
65
100
params = hookenv.action_get()