When this component finishes, the process is completely decoupled from
- the parent environment.
+ the parent environment. Please note that when this component is used,
+ the return code from the parent process will always be 0, even if a
+ startup error occured, unless that error was during the daemonizing process.
+ If you use this plugin to Daemonize, don't use the return code as an accurate
+ indication of whether the process fully started. In fact, that return code
+ only indicates if the process succesfully finished the first fork.
def __init__(self, bus, stdin='/dev/null', stdout='/dev/null',
# This is the first parent. Exit, now that we've forked.
# Python raises OSError rather than returning negative numbers.
sys.exit("%s: fork #1 failed: (%d) %s\n"
sys.exit(0) # Exit second parent
+ s.exit(0) # Exit second parent
sys.exit("%s: fork #2 failed: (%d) %s\n"
% (sys.argv, exc.errno, exc.strerror))
# that we wait for the daemon to finish running before we fail.
self.fail("Daemonized process failed to exit cleanly")
- def test_2_Start_Error_With_Daemonize(self):
- if not self.server_class:
- print "skipped (no server) ",
- if os.name not in ['posix']:
- print "skipped (not on posix) ",
- # Start the demo script in a new process
- demoscript = os.path.join(os.getcwd(), os.path.dirname(__file__),
- host = cherrypy.server.socket_host
- port = cherrypy.server.socket_port
- # If a process errors during start, it should stop the engine
- # and exit with a non-zero exit code, even if we daemonize soon
- args = [sys.executable, demoscript, host, str(port), '-starterror', '-daemonize']
- if self.scheme == "https":
- exit_code = os.spawnl(os.P_WAIT, sys.executable, *args)
- self.fail("Process failed to return nonzero exit code.")
- time.sleep(2) # Wait for the daemonized process to exit.