bundlewrap/bundles/postgresql/items.py

112 lines
3.1 KiB
Python
Raw Normal View History

postgresql_version = node.metadata['postgresql']['version']
pkg_apt = {
'postgresql-common': {},
'postgresql-client-common': {},
'postgresql-{}'.format(postgresql_version): {},
'postgresql-client-{}'.format(postgresql_version): {},
'postgresql-server-dev-{}'.format(postgresql_version): {},
}
if node.has_bundle('zfs'):
for pkgname, pkgconfig in pkg_apt.items():
pkg_apt[pkgname]['needs'] = {
'zfs_dataset:tank/postgresql',
}
directories = {
'/etc/postgresql': {
'owner': None,
'group': None,
'mode': None,
# Keeping old configs messes with cluster-auto-detection.
'purge': True,
},
# This is needed so the above purge does not remove the version
# currently installed.
'/etc/postgresql/{}/main'.format(postgresql_version): {
'owner': 'postgres',
'group': 'postgres',
'mode': '0755',
},
}
files = {
"/etc/postgresql/{}/main/pg_hba.conf".format(postgresql_version): {
'content_type': 'mako',
'owner': 'postgres',
'group': 'postgres',
'triggers': {
'svc_systemd:postgresql:restart',
},
},
"/etc/postgresql/{}/main/postgresql.conf".format(postgresql_version): {
'content_type': 'mako',
'context': node.metadata['postgresql'],
'owner': 'postgres',
'group': 'postgres',
'needs': {
# postgresql won't start if the configured locale isn't available
'action:locale-gen',
} if node.has_bundle('basic') else set(),
'triggers': {
'svc_systemd:postgresql:restart',
},
},
}
# FIXME currently we do not have a mechanism to use snapshot-backups of
# zfs datasets.
if node.has_bundle('backup-client'): # and not node.has_bundle('zfs'):
files['/etc/backup-pre-hooks.d/90-postgresql-dump-all'] = {
'source': 'backup-pre-hook',
'content_type': 'mako',
'context': {
'databases': node.metadata.get('postgresql/databases', {}).keys(),
},
'mode': '0700',
}
directories['/var/tmp/postgresdumps'] = {}
postgres_roles = {
'root': {
'password': repo.vault.password_for('{} postgresql root'.format(node.name)),
'superuser': True,
'needs': {
'svc_systemd:postgresql',
},
},
}
restart_deps = {
f'file:/etc/postgresql/{postgresql_version}/main/pg_hba.conf',
f'file:/etc/postgresql/{postgresql_version}/main/postgresql.conf',
*{f'pkg_apt:{i}' for i in pkg_apt.keys()},
}
svc_systemd = {
'postgresql': {
'needs': restart_deps,
},
}
postgres_dbs = {}
2020-04-04 15:53:59 +00:00
for user, config in node.metadata.get('postgresql/roles', {}).items():
2020-04-04 15:53:59 +00:00
postgres_roles[user] = {
'password': config['password'],
'needs': {
'svc_systemd:postgresql',
},
2020-04-04 15:53:59 +00:00
}
for database, config in node.metadata.get('postgresql/databases', {}).items():
postgres_dbs[database] = {
2020-04-04 15:53:59 +00:00
'owner': config['owner'],
'needs': {
'postgres_role:',
'svc_systemd:postgresql',
},
2020-04-04 15:53:59 +00:00
}