2019-01-15 19:12:12 +01:00
|
|
|
Index: patroni/patroni/postmaster.py
|
|
|
|
===================================================================
|
2019-08-05 18:05:05 +02:00
|
|
|
--- patroni.orig/patroni/postgresql/postmaster.py
|
|
|
|
+++ patroni/postgresql/patroni/postmaster.py
|
2019-06-15 11:12:50 +02:00
|
|
|
@@ -50,14 +50,15 @@ class PostmasterProcess(psutil.Process):
|
2018-09-26 14:20:44 +02:00
|
|
|
return {}
|
|
|
|
|
|
|
|
def _is_postmaster_process(self):
|
|
|
|
+ postmaster_pid = int(self._postmaster_pid.get('pid', 0))
|
|
|
|
try:
|
|
|
|
- start_time = int(self._postmaster_pid.get('start_time', 0))
|
|
|
|
- if start_time and abs(self.create_time() - start_time) > 3:
|
|
|
|
- logger.info('Process %s is not postmaster, too much difference between PID file start time %s and '
|
|
|
|
- 'process start time %s', self.pid, self.create_time(), start_time)
|
|
|
|
- return False
|
|
|
|
- except ValueError:
|
|
|
|
- logger.warning('Garbage start time value in pid file: %r', self._postmaster_pid.get('start_time'))
|
|
|
|
+ self.send_signal(0)
|
|
|
|
+ except psutil.NoSuchProcess:
|
|
|
|
+ logger.warning("Could not send stop signal to PostgreSQL")
|
|
|
|
+ return False
|
|
|
|
+ except psutil.AccessDenied as e:
|
|
|
|
+ logger.warning("Could not send stop signal to PostgreSQL (error: {0})".format(e))
|
|
|
|
+ return False
|
|
|
|
|
|
|
|
# Extra safety check. The process can't be ourselves, our parent or our direct child.
|
|
|
|
if self.pid == os.getpid() or self.pid == os.getppid() or self.ppid() == os.getpid():
|
2019-01-15 19:12:12 +01:00
|
|
|
Index: patroni/tests/test_postmaster.py
|
|
|
|
===================================================================
|
|
|
|
--- patroni.orig/tests/test_postmaster.py
|
|
|
|
+++ patroni/tests/test_postmaster.py
|
2019-06-15 11:12:50 +02:00
|
|
|
@@ -36,25 +36,6 @@ class TestPostmasterProcess(unittest.Tes
|
2018-09-26 16:08:24 +02:00
|
|
|
mock_read.return_value = {"pid": "123"}
|
|
|
|
self.assertIsNone(PostmasterProcess.from_pidfile(''))
|
|
|
|
|
|
|
|
- mock_init.side_effect = None
|
|
|
|
- with patch.object(psutil.Process, 'pid', 123), \
|
|
|
|
- patch.object(psutil.Process, 'ppid', return_value=124), \
|
|
|
|
- patch('os.getpid', return_value=125) as mock_ospid, \
|
|
|
|
- patch('os.getppid', return_value=126):
|
|
|
|
-
|
|
|
|
- self.assertIsNotNone(PostmasterProcess.from_pidfile(''))
|
|
|
|
-
|
|
|
|
- mock_create_time.return_value = 100000
|
|
|
|
- mock_read.return_value = {"pid": "123", "start_time": "200000"}
|
|
|
|
- self.assertIsNone(PostmasterProcess.from_pidfile(''))
|
|
|
|
-
|
|
|
|
- mock_read.return_value = {"pid": "123", "start_time": "foobar"}
|
|
|
|
- self.assertIsNotNone(PostmasterProcess.from_pidfile(''))
|
|
|
|
-
|
|
|
|
- mock_ospid.return_value = 123
|
|
|
|
- mock_read.return_value = {"pid": "123", "start_time": "100000"}
|
|
|
|
- self.assertIsNone(PostmasterProcess.from_pidfile(''))
|
|
|
|
-
|
|
|
|
@patch('psutil.Process.__init__')
|
|
|
|
def test_from_pid(self, mock_init):
|
|
|
|
mock_init.side_effect = psutil.NoSuchProcess(123)
|