[Cherokee-commits] [3506] cherokee/trunk/admin/CherokeeManagement.py: Even though it isn' t recommended, Cherokee allows to launch the server

SVN at cherokee-project.com SVN at cherokee-project.com
Tue Aug 4 10:33:49 CEST 2009


Revision: 3506
          http://svn.cherokee-project.com/changeset/3506
Author:   alo
Date:     2009-08-04 10:33:49 +0200 (Tue, 04 Aug 2009)

Log Message:
-----------
Even though it isn't recommended, Cherokee allows to launch the server
without creating a PID file. Cherokee-admin checks that file in order
to know whether or not the server is running. This patch adds a
slightly smarted function to detect the server presence. In case the
server PID file weren't present it'd try to check the OS processes
list in order to find a cherokee process being executed with the same
configuration file. In case it were found, it'd assume the server was
running.

Modified Paths:
--------------
    cherokee/trunk/admin/CherokeeManagement.py

Modified: cherokee/trunk/admin/CherokeeManagement.py
===================================================================
--- cherokee/trunk/admin/CherokeeManagement.py	2009-08-03 20:48:03 UTC (rev 3505)
+++ cherokee/trunk/admin/CherokeeManagement.py	2009-08-04 08:33:49 UTC (rev 3506)
@@ -153,15 +153,12 @@
 
     # Protected
     #
-    def _get_pid_path (self):
+    def _get_pid (self):
         pid_file = self._cfg.get_val("server!pid_file")
-        if not pid_file:
-            pid_file = os.path.join (CHEROKEE_VAR_RUN, "cherokee.pid")
-        return pid_file
+        if pid_file:
+            return self.__read_pid_file (pid_file)
 
-    def _get_pid (self):
-        pid_file = self._get_pid_path()
-        return self.__read_pid_file (pid_file)
+        return self.__try_to_figure_pid()
 
     def _restart (self, graceful=False):
         if not self._pid:
@@ -176,7 +173,18 @@
 
     # Private
     #
+    def __try_to_figure_pid (self):
+        try:
+            ps = os.popen ("ps aux").read()
+        except:
+            return -1
 
+        for l in ps.split("\n"):
+            if "cherokee " in l and "-C %s"%(self._cfg.file) in l:
+                pid = filter (lambda x: x.isdigit(), l.split())[0]
+                return int(pid)
+        return -1
+
     def __read_pid_file (self, file):
         if not os.access (file, os.R_OK):
             return

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.octality.com/pipermail/cherokee-commits/attachments/20090804/77b1bea7/attachment.htm 


More information about the Cherokee-commits mailing list