mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
More compatibility with windows (#1367)
* unix-domain sockets are not yet supported * signal.SIGQUIT doesn't exists
This commit is contained in:
@@ -171,7 +171,8 @@ class PatroniController(AbstractController):
|
|||||||
|
|
||||||
config['name'] = name
|
config['name'] = name
|
||||||
config['postgresql']['data_dir'] = self._data_dir
|
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({
|
config['postgresql']['parameters'].update({
|
||||||
'logging_collector': 'on', 'log_destination': 'csvlog', 'log_directory': self._output_dir,
|
'logging_collector': 'on', 'log_destination': 'csvlog', 'log_directory': self._output_dir,
|
||||||
'log_filename': name + '.log', 'log_statement': 'all', 'log_min_messages': 'debug1',
|
'log_filename': name + '.log', 'log_statement': 'all', 'log_min_messages': 'debug1',
|
||||||
|
|||||||
@@ -456,7 +456,7 @@ class ConfigHandler(object):
|
|||||||
# when we are doing custom bootstrap we assume that we don't know superuser password
|
# 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
|
# 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:
|
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('/'):
|
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(
|
addresses.update({sa[0] + '/32': 'host' for _, _, _, _, sa in socket.getaddrinfo(
|
||||||
self.local_replication_address['host'], self.local_replication_address['port'],
|
self.local_replication_address['host'], self.local_replication_address['port'],
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ elif sys.version_info >= (3, 4): # pragma: no cover
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
STOP_SIGNALS = {
|
STOP_SIGNALS = {
|
||||||
'smart': signal.SIGTERM,
|
'smart': 'TERM',
|
||||||
'fast': signal.SIGINT,
|
'fast': 'INT',
|
||||||
'immediate': signal.SIGQUIT,
|
'immediate': 'QUIT',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ class PostmasterProcess(psutil.Process):
|
|||||||
if os.name != 'posix':
|
if os.name != 'posix':
|
||||||
return self.pg_ctl_kill(mode, pg_ctl)
|
return self.pg_ctl_kill(mode, pg_ctl)
|
||||||
try:
|
try:
|
||||||
self.send_signal(STOP_SIGNALS[mode])
|
self.send_signal(getattr(signal, 'SIG' + STOP_SIGNALS[mode]))
|
||||||
except psutil.NoSuchProcess:
|
except psutil.NoSuchProcess:
|
||||||
return True
|
return True
|
||||||
except psutil.AccessDenied as e:
|
except psutil.AccessDenied as e:
|
||||||
@@ -126,9 +126,8 @@ class PostmasterProcess(psutil.Process):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def pg_ctl_kill(self, mode, pg_ctl):
|
def pg_ctl_kill(self, mode, pg_ctl):
|
||||||
SIGNALNAME = {"smart": "TERM", "fast": "INT", "immediate": "QUIT"}[mode]
|
|
||||||
try:
|
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:
|
except OSError:
|
||||||
return False
|
return False
|
||||||
if status == 0:
|
if status == 0:
|
||||||
|
|||||||
@@ -66,6 +66,8 @@ class TestPostmasterProcess(unittest.TestCase):
|
|||||||
@patch('psutil.Process.__init__', Mock())
|
@patch('psutil.Process.__init__', Mock())
|
||||||
@patch('psutil.Process.send_signal')
|
@patch('psutil.Process.send_signal')
|
||||||
@patch('psutil.Process.pid', Mock(return_value=123))
|
@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):
|
def test_signal_stop(self, mock_send_signal):
|
||||||
proc = PostmasterProcess(-123)
|
proc = PostmasterProcess(-123)
|
||||||
self.assertEqual(proc.signal_stop('immediate'), False)
|
self.assertEqual(proc.signal_stop('immediate'), False)
|
||||||
|
|||||||
Reference in New Issue
Block a user