phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tdsi...@apache.org
Subject [32/50] [abbrv] phoenix git commit: PHOENIX-4456 queryserver script doesn't perform as expected.
Date Fri, 19 Jan 2018 18:03:40 GMT
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/90c72416
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/90c72416
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/90c72416

Branch: refs/heads/system-catalog
Commit: 90c7241611667e3cd3689ce6a72762c6315231ef
Parents: 1a19d1e
Author: Sergey Soldatov <ssa@apache.org>
Authored: Tue Dec 12 23:20:48 2017 -0800
Committer: Sergey Soldatov <ssa@apache.org>
Committed: Wed Dec 13 10:16:54 2017 -0800

----------------------------------------------------------------------
 bin/daemon.py | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/90c72416/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+')


Mime
View raw message