From 5c2cad20d7e80cfd55db710ce637f7034e115a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Mart=C3=ADnez?= Date: Wed, 31 Aug 2016 15:30:31 +0200 Subject: [PATCH] Add custom_conf configuration parameter This will be used in place of postgresql.base.conf, to be included on the main postgresql.conf. --- patroni/postgresql.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/patroni/postgresql.py b/patroni/postgresql.py index 37d09460..a189acc4 100644 --- a/patroni/postgresql.py +++ b/patroni/postgresql.py @@ -100,9 +100,13 @@ class Postgresql(object): self._postgresql_conf = os.path.join(self._data_dir, config_base_name + '.conf') self._postgresql_base_conf_name = config_base_name + '.base.conf' self._postgresql_base_conf = os.path.join(self._data_dir, self._postgresql_base_conf_name) + self._postgresql_custom_conf = config.get('custom_conf') self._recovery_conf = os.path.join(self._data_dir, 'recovery.conf') - self._configuration_to_save = (self._postgresql_conf, self._postgresql_base_conf, - os.path.join(self._data_dir, 'pg_hba.conf')) + self._configuration_to_save = [self._postgresql_conf] + if not self._postgresql_custom_conf: + self._configuration_to_save.append(self._postgresql_base_conf) + if not config['parameters'].get('hba_file'): + self._configuration_to_save.append(os.path.join(self._data_dir, 'pg_hba.conf')) self._postmaster_pid = os.path.join(self._data_dir, 'postmaster.pid') self._trigger_file = config.get('recovery_conf', {}).get('trigger_file') or 'promote' self._trigger_file = os.path.abspath(os.path.join(self._data_dir, self._trigger_file)) @@ -622,12 +626,12 @@ class Postgresql(object): def _write_postgresql_conf(self): # rename the original configuration if it is necessary - if not os.path.exists(self._postgresql_base_conf): + if not self._postgresql_custom_conf and not os.path.exists(self._postgresql_base_conf): os.rename(self._postgresql_conf, self._postgresql_base_conf) with open(self._postgresql_conf, 'w') as f: f.write('# Do not edit this file manually!\n# It will be overwritten by Patroni!\n') - f.write("include '{0}'\n\n".format(self._postgresql_base_conf_name)) + f.write("include '{0}'\n\n".format(self._postgresql_custom_conf or self._postgresql_base_conf_name)) for name, value in sorted(self._server_parameters.items()): if name not in self.CMDLINE_OPTIONS: f.write("{0} = '{1}'\n".format(name, value))