Implementation of PEP 3143 DaemonContext
freezer.lib.pep3143daemon.daemon.
DaemonContext
(chroot_directory=None, working_directory='/', umask=0, uid=None, gid=None, prevent_core=True, detach_process=None, files_preserve=None, pidfile=None, stdin=None, stdout=None, stderr=None, signal_map=None)¶Bases: object
Implementation of PEP 3143 DaemonContext class
This class should be instantiated only once in every program that has to become a Unix Daemon. Typically you should call its open method after you have done everything that may require root privileges. For example opening port <= 1024.
Each option can be passed as a keyword argument to the constructor, but can also be changed by assigning a new value to the corresponding attribute on the instance.
Altering attributes after open() is called, will have no effect. In future versions, trying to do so, will may raise a DaemonError.
Parameters: |
|
---|
close
()¶Dummy function
is_open
¶True when this instances open method was called
Returns: | bool |
---|
open
()¶Daemonize this process
Do everything that is needed to become a Unix daemon.
Returns: | None |
---|---|
Raise: | DaemonError |
terminate
(signal_number, stack_frame)¶Terminate this process
Simply terminate this process by raising SystemExit. This method is called if signal.SIGTERM was received.
Check carefully if this really is what you want!
Most likely it is not!
You should implement a function/method that is able to cleanly shutdown you daemon. Like gracefully terminating child processes, threads. or closing files.
You can create a custom handler by overriding this method, ot setting a custom handler via the signal_map. It is also possible to set the signal handlers directly via signal.signal().
Returns: | None |
---|---|
Raise: | SystemExit |
working_directory
¶The working_directory property
Returns: | str |
---|
freezer.lib.pep3143daemon.daemon.
DaemonError
¶Bases: Exception
Exception raised by DaemonContext
freezer.lib.pep3143daemon.daemon.
close_filenos
(preserve)¶Close unprotected file descriptors
Close all open file descriptors that are not in preserve.
If ulimit -nofile is “unlimited”, all is defined filenos <= 4096, else all is <= the output of resource.getrlimit().
Parameters: | preserve (set) – set with protected files |
---|---|
Returns: | None |
freezer.lib.pep3143daemon.daemon.
default_signal_map
()¶Create the default signal map for this system.
Returns: | dict |
---|
freezer.lib.pep3143daemon.daemon.
detach_required
()¶Check if detaching is required
This is done by collecting the results of parent_is_inet and parent_is_init. If one of them is True, detaching, aka the daemonizing, aka the double fork magic, is not required, and can be skipped.
Returns: | bool |
---|
freezer.lib.pep3143daemon.daemon.
parent_is_inet
()¶Check if parent is inet
Check if our parent seems ot be a superserver, aka inetd/xinetd.
This is done by checking if sys.__stdin__ is a network socket.
Returns: | bool |
---|
freezer.lib.pep3143daemon.daemon.
parent_is_init
()¶Check if parent is Init
Check if the parent process is init, or something else that owns PID 1.
Returns: | bool |
---|
freezer.lib.pep3143daemon.daemon.
redirect_stream
(system, target)¶Redirect Unix streams
If None, redirect Stream to /dev/null, else redirect to target.
Parameters: |
|
---|---|
Returns: | None |
Raise: | DaemonError |
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.