PHOENIX-4456 queryserver script doesn't perform as expected.
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/9d0a6bb7 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/9d0a6bb7 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/9d0a6bb7 Branch: refs/heads/4.x-HBase-1.1 Commit: 9d0a6bb7eed0b804f85b3a866b82332278c7161d Parents: 441539d Author: Sergey Soldatov <s...@apache.org> Authored: Tue Dec 12 23:20:48 2017 -0800 Committer: Sergey Soldatov <s...@apache.org> Committed: Wed Dec 13 10:18:15 2017 -0800 ---------------------------------------------------------------------- bin/daemon.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/9d0a6bb7/bin/daemon.py ---------------------------------------------------------------------- diff --git a/bin/daemon.py b/bin/daemon.py index aeebae3..bb64148 100644 --- a/bin/daemon.py +++ b/bin/daemon.py @@ -57,6 +57,7 @@ import signal import socket import atexit import fcntl +import time try: # Python 2 has both âstrâ (bytes) and âunicodeâ (text). basestring = basestring @@ -386,7 +387,7 @@ class DaemonContext: change_process_owner(self.uid, self.gid) if self.detach_process: - detach_process_context() + detach_process_context(self.pidfile) signal_handler_map = self._make_signal_handler_map() set_signal_handlers(signal_handler_map) @@ -657,7 +658,7 @@ def prevent_core_dump(): resource.setrlimit(core_resource, core_limit) -def detach_process_context(): +def detach_process_context(pidfile): """ Detach the process context from parent and session. :return: ``None``. @@ -683,6 +684,8 @@ def detach_process_context(): try: pid = os.fork() if pid > 0: + while not os.path.exists(pidfile.path): + time.sleep(0.1) os._exit(0) except OSError as exc: error = DaemonProcessDetachError( @@ -959,7 +962,14 @@ found at [1]. def __init__(self, path, enter_err_msg=None): self.path = path self.enter_err_msg = enter_err_msg - self.pidfile = None + self.pidfile = open(self.path, 'a+') + try: + fcntl.flock(self.pidfile.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) + fcntl.flock(self.pidfile.fileno(), fcntl.LOCK_UN) + self.pidfile.close() + os.remove(self.path) + except IOError: + sys.exit(self.enter_err_msg) def __enter__(self): self.pidfile = open(self.path, 'a+')