[ZCM] [ZC] 10/ 5 Resolve "better daemon"

Collector: Zope Bugs and Patches ... zope-coders@zope.org
Wed, 13 Mar 2002 09:27:23 -0500


Issue #10 Update (Resolve) "better daemon"
 Status Resolved, Zope/bug+solution medium
To followup, visit:
  http://collector.zope.org/Zope/10

==============================================================
= Resolve - Entry #5 by htrd on Mar 13, 2002 9:27 am

 Status: Accepted => Resolved

similar patch merged into the trunk for 2.6
________________________________________
= Assign - Entry #4 by matt on Nov 30, 2001 2:54 pm

 Status: Pending => Accepted

 Supporters added: matt


________________________________________
= Comment - Entry #3 by htrd on Nov 9, 2001 11:48 am

Re: platform support

zdaemon/py is unix specific. I believe the code as posted will work anywhere that supports fork (which is called just before my additions in the original version)

Re: checking for tty

sure, this patch isnt all-singing all-dancing. It does achieve the stated aim. Im not sure it would be a good idea to mix up a new feature (that you suggest) with a bug fix (that this is).

Anyway, I dont have time to add any more frills at the moment. Take it or leave it.


__________________________________________________
= Comment - Entry #2 by matt on Nov 9, 2001 11:39 am

In order to accept this patch, it must work on all platforms Zope supports (including Windows).

Also, consider extending it by checking to see if the current stdin/stdout/stderr is an tty -- if it is not a tty, then someone has already done IO redirection.
__________________________________________________
= Request - Entry #1 by htrd on Oct 30, 2001 11:28 am

this one was in the old collector;

currently zope doesnt close its stdin/stout/stderr when run as a daemon.... and it should.

Index: zdaemon.py
===================================================================
RCS file: /home/cvs/development/external/Zope2/lib/python/zdaemon.py,v
retrieving revision 1.1.1.3
diff -c -4 -r1.1.1.3 zdaemon.py
*** zdaemon.py  10 Sep 2001 14:55:05 -0000      1.1.1.3
--- zdaemon.py  30 Oct 2001 16:26:09 -0000
***************
*** 184,191 ****
--- 184,194 ----
           # Detach from terminal
           pid = os.fork()
           if pid:
               sys.exit(0)
+         posix.close(0); sys.stdin  = open('/dev/null')
+         posix.close(1); sys.stdout = open('/dev/null','w')
+         posix.close(2); sys.stderr = open('/dev/null','w')
           posix.setsid()

       while 1:
==============================================================