More compatibility with windows (#1367)

* unix-domain sockets are not yet supported
* signal.SIGQUIT doesn't exists
This commit is contained in:
Alexander Kukushkin
2020-01-24 12:52:55 +01:00
committed by GitHub
parent 0eb1e0568b
commit 902411239f
4 changed files with 10 additions and 8 deletions

View File

@@ -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',

View File

@@ -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'],

View File

@@ -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:

View File

@@ -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)