cement.ext.ext_daemon
¶
Cement daemon extension module.
-
class
cement.ext.ext_daemon.
Environment
(**kw)[source]¶ Bases:
object
This class provides a mechanism for altering the running processes environment.
Optional Arguments:
Keyword Arguments: - stdin – A file to read STDIN from. Default:
/dev/null
- stdout – A file to write STDOUT to. Default:
/dev/null
- stderr – A file to write STDERR to. Default:
/dev/null
- dir – The directory to run the process in.
- pid_file – The filesystem path to where the PID (Process ID) should be written to. Default: None
- user – The user name to run the process as.
Default:
os.getlogin()
- group – The group name to run the process as.
Default: The primary group of
os.getlogin()
. - umask – The umask to pass to os.umask(). Default:
0
-
daemonize
()[source]¶ Fork the current process into a daemon.
References:
- UNIX Programming FAQ:
- 1.7 How do I get my program to act like a daemon? http://www.unixguide.net/unix/programming/1.7.shtml http://www.faqs.org/faqs/unix-faq/programmer/faq/
- Advanced Programming in the Unix Environment
- Richard Stevens, 1992, Addison-Wesley, ISBN 0-201-56317-7.
- stdin – A file to read STDIN from. Default:
-
cement.ext.ext_daemon.
cleanup
(app)[source]¶ After application run time, this hook just attempts to clean up the pid_file if one was set, and exists.
-
cement.ext.ext_daemon.
daemonize
()[source]¶ This function switches the running user/group to that configured in
config['daemon']['user']
andconfig['daemon']['group']
. The default user isos.getlogin()
and the default group is that user’s primary group. A pid_file and directory to run in is also passed to the environment.It is important to note that with the daemon extension enabled, the environment will switch user/group/set pid/etc regardless of whether the
--daemon
option was passed at command line or not. However, the process will only ‘daemonize’ if the option is passed to do so. This allows the program to run exactly the same in forground or background.