diff --git a/features/environment.py b/features/environment.py index d678a523..851c41a1 100644 --- a/features/environment.py +++ b/features/environment.py @@ -171,7 +171,8 @@ class PatroniController(AbstractController): config['name'] = name config['postgresql']['data_dir'] = self._data_dir - config['postgresql']['use_unix_socket'] = True + config['postgresql']['use_unix_socket'] = os.name != 'nt' # windows doesn't yet support unix-domain sockets + config['postgresql']['pgpass'] = os.path.join(tempfile.gettempdir(), 'pgpass_' + name) config['postgresql']['parameters'].update({ 'logging_collector': 'on', 'log_destination': 'csvlog', 'log_directory': self._output_dir, 'log_filename': name + '.log', 'log_statement': 'all', 'log_min_messages': 'debug1', diff --git a/patroni/postgresql/config.py b/patroni/postgresql/config.py index a71076f2..c6ed5ce3 100644 --- a/patroni/postgresql/config.py +++ b/patroni/postgresql/config.py @@ -456,7 +456,7 @@ class ConfigHandler(object): # when we are doing custom bootstrap we assume that we don't know superuser password # and in order to be able to change it, we are opening trust access from a certain address if self._postgresql.bootstrap.running_custom_bootstrap: - addresses = {'': 'local'} + addresses = {} if os.name == 'nt' else {'': 'local'} # windows doesn't yet support unix-domain sockets if 'host' in self.local_replication_address and not self.local_replication_address['host'].startswith('/'): addresses.update({sa[0] + '/32': 'host' for _, _, _, _, sa in socket.getaddrinfo( self.local_replication_address['host'], self.local_replication_address['port'], diff --git a/patroni/postgresql/postmaster.py b/patroni/postgresql/postmaster.py index add11488..6ee51d26 100644 --- a/patroni/postgresql/postmaster.py +++ b/patroni/postgresql/postmaster.py @@ -20,9 +20,9 @@ elif sys.version_info >= (3, 4): # pragma: no cover logger = logging.getLogger(__name__) STOP_SIGNALS = { - 'smart': signal.SIGTERM, - 'fast': signal.SIGINT, - 'immediate': signal.SIGQUIT, + 'smart': 'TERM', + 'fast': 'INT', + 'immediate': 'QUIT', } @@ -116,7 +116,7 @@ class PostmasterProcess(psutil.Process): if os.name != 'posix': return self.pg_ctl_kill(mode, pg_ctl) try: - self.send_signal(STOP_SIGNALS[mode]) + self.send_signal(getattr(signal, 'SIG' + STOP_SIGNALS[mode])) except psutil.NoSuchProcess: return True except psutil.AccessDenied as e: @@ -126,9 +126,8 @@ class PostmasterProcess(psutil.Process): return None def pg_ctl_kill(self, mode, pg_ctl): - SIGNALNAME = {"smart": "TERM", "fast": "INT", "immediate": "QUIT"}[mode] try: - status = subprocess.call([pg_ctl, "kill", SIGNALNAME, str(self.pid)]) + status = subprocess.call([pg_ctl, "kill", STOP_SIGNALS[mode], str(self.pid)]) except OSError: return False if status == 0: diff --git a/tests/test_postmaster.py b/tests/test_postmaster.py index a62436e3..7189a626 100644 --- a/tests/test_postmaster.py +++ b/tests/test_postmaster.py @@ -66,6 +66,8 @@ class TestPostmasterProcess(unittest.TestCase): @patch('psutil.Process.__init__', Mock()) @patch('psutil.Process.send_signal') @patch('psutil.Process.pid', Mock(return_value=123)) + @patch('os.name', 'posix') + @patch('signal.SIGQUIT', 3, create=True) def test_signal_stop(self, mock_send_signal): proc = PostmasterProcess(-123) self.assertEqual(proc.signal_stop('immediate'), False)