more verbose error reporting for non-writeable pid file
This commit is contained in:
parent
1537f0f2ec
commit
8aa7eaf225
1 changed files with 18 additions and 2 deletions
|
@ -234,13 +234,25 @@ def close_open_files():
|
|||
os.dup2(0, 1) # standard output (1)
|
||||
|
||||
|
||||
def write_pid_file(pid_file):
|
||||
def write_pid_file(pid_file, pid=None):
|
||||
"""write the process ID of the cryptonas daemon to a file
|
||||
|
||||
call this function with the second parameter (e.g. pid=0) to check, if the
|
||||
given location is writeable
|
||||
@param pid_file: the path of the pid file to be written
|
||||
@type pid_file: string
|
||||
@param pid: use a specific PID instead of the PID of the current process
|
||||
@type pid: int
|
||||
"""
|
||||
if pid is None:
|
||||
## use the PID of the current process
|
||||
pid = os.getpid()
|
||||
if os.path.exists(pid_file):
|
||||
sys.stderr.write(
|
||||
"Warning: pid file (%s) already exists - overwriting ...\n" % pid_file)
|
||||
try:
|
||||
pidf = open(pid_file,"w")
|
||||
pidf.write(str(os.getpid()))
|
||||
pidf.write(str(pid))
|
||||
pidf.close()
|
||||
except (IOError, OSError), err_msg:
|
||||
sys.stderr.write(
|
||||
|
@ -371,6 +383,10 @@ if __name__ == "__main__":
|
|||
sys.stderr.write("Check the log file for details.\n")
|
||||
cherrypy.server.stop()
|
||||
sys.exit(1)
|
||||
## test if we can write to the PID file
|
||||
## this _must_ be done before forking, since a potential error would be
|
||||
## silent (due to the closed files - e.g. STDERR)
|
||||
write_pid_file(options.pidfile, 0)
|
||||
## redirect stderr to the webserver's logfile
|
||||
if options.background:
|
||||
## replace stdin and stdout by /dev/null
|
||||
|
|
Loading…
Add table
Reference in a new issue