|
|
|
@ -89,11 +89,15 @@ def fork_to_background():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def close_open_files():
|
|
|
|
|
"""this is only necessary if we want to go into background"""
|
|
|
|
|
"""this is only necessary if we want to go into background
|
|
|
|
|
we will only close stdin, stdout and stderr
|
|
|
|
|
"""
|
|
|
|
|
import resource # Resource usage information.
|
|
|
|
|
maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
|
|
|
|
|
if (maxfd == resource.RLIM_INFINITY):
|
|
|
|
|
maxfd = 1024
|
|
|
|
|
## use the following lines to close all open files (including the log file)
|
|
|
|
|
# maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
|
|
|
|
|
# if (maxfd == resource.RLIM_INFINITY):
|
|
|
|
|
# maxfd = 1024
|
|
|
|
|
maxfd = 2
|
|
|
|
|
for fd in range(0, maxfd):
|
|
|
|
|
try:
|
|
|
|
|
os.close(fd)
|
|
|
|
@ -160,14 +164,12 @@ if __name__ == "__main__":
|
|
|
|
|
options = parseOptions()
|
|
|
|
|
## run the webserver as a daemon process
|
|
|
|
|
if options.background: fork_to_background()
|
|
|
|
|
## close open files to allow background execution
|
|
|
|
|
if options.background: close_open_files()
|
|
|
|
|
## write pid file
|
|
|
|
|
write_pid_file(options.pidfile)
|
|
|
|
|
## TODO: if we close the open files _after_ initialization, then we also close
|
|
|
|
|
## the log out - we have to figure something out here ...
|
|
|
|
|
## initialize the webserver class (before forking to get some error messages)
|
|
|
|
|
cbw = CryptoBoxWebserver(options)
|
|
|
|
|
## close open files to allow background execution
|
|
|
|
|
if options.background: close_open_files()
|
|
|
|
|
## start the webserver
|
|
|
|
|
try:
|
|
|
|
|
cbw.start()
|
|
|
|
|