improved error handling of the server start script
This commit is contained in:
parent
c22a7c5210
commit
96cfbbdf14
|
@ -89,11 +89,15 @@ def fork_to_background():
|
||||||
|
|
||||||
|
|
||||||
def close_open_files():
|
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.
|
import resource # Resource usage information.
|
||||||
maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
|
## use the following lines to close all open files (including the log file)
|
||||||
if (maxfd == resource.RLIM_INFINITY):
|
# maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
|
||||||
maxfd = 1024
|
# if (maxfd == resource.RLIM_INFINITY):
|
||||||
|
# maxfd = 1024
|
||||||
|
maxfd = 2
|
||||||
for fd in range(0, maxfd):
|
for fd in range(0, maxfd):
|
||||||
try:
|
try:
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
|
@ -160,14 +164,12 @@ if __name__ == "__main__":
|
||||||
options = parseOptions()
|
options = parseOptions()
|
||||||
## run the webserver as a daemon process
|
## run the webserver as a daemon process
|
||||||
if options.background: fork_to_background()
|
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
|
||||||
write_pid_file(options.pidfile)
|
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)
|
## initialize the webserver class (before forking to get some error messages)
|
||||||
cbw = CryptoBoxWebserver(options)
|
cbw = CryptoBoxWebserver(options)
|
||||||
|
## close open files to allow background execution
|
||||||
|
if options.background: close_open_files()
|
||||||
## start the webserver
|
## start the webserver
|
||||||
try:
|
try:
|
||||||
cbw.start()
|
cbw.start()
|
||||||
|
|
|
@ -75,7 +75,7 @@ Details = ./cryptobox.log
|
||||||
Stylesheet = /cryptobox-misc/cryptobox.css
|
Stylesheet = /cryptobox-misc/cryptobox.css
|
||||||
|
|
||||||
# default language
|
# default language
|
||||||
Language = de
|
Languages = de, en
|
||||||
|
|
||||||
|
|
||||||
[Programs]
|
[Programs]
|
||||||
|
|
Loading…
Reference in a new issue