#10566 closed defect (fixed)
Error writing to PID file while starting tracd in daemon mode
Reported by: | Owned by: | Remy Blank | |
---|---|---|---|
Priority: | high | Milestone: | 0.12.4 |
Component: | web frontend/tracd | Version: | 0.12.3 |
Severity: | major | Keywords: | daemon ioerror tracd |
Cc: | dkg@… | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
Version: 0.12.3 Python: 2.5.2
If I want to start tracd in daemon mode with a pid file I always get:
Error writing to pid file: IOError: [Errno 2] No such file or directory: '/var/run/mypid.pid'
I think the error come from the changes in [10799] in daemon.py.
# The pid file must be writable try: fileobj = open(pidfile, 'r+') fileobj.close() except IOError, e: from trac.util.text import exception_to_unicode sys.exit('Error writing to pid file: %s' % exception_to_unicode(e))
I think this code opens only an existing PID file and creates no new one. But if I want to start the daemon there exists no PID file!
Attachments (0)
Change History (12)
comment:1 by , 13 years ago
comment:2 by , 13 years ago
Component: | general → web frontend/tracd |
---|---|
Milestone: | → 0.12.4 |
Right. Thanks for the report!
comment:5 by , 13 years ago
The file mode 'w+' works, but I don't see it documented in python 2.7. I used the documented form:
fileobj = open(pidfile, 'a')
Perhaps the reason why this 'r+' mode got introduced is that it also guards against the rather pathetic case that the file is writable but not readable, albeit the error message "Error writing to pid file" doesn't quite cover it. One way to check that is os.access(pidfile, os.R_OK | os.W_OK)
, however that doesn't reveal the reason for the failure like the exception does.
comment:6 by , 13 years ago
Actually, my comment was baloney from start to end.
- The 'w+' mode is described in the standard library section "2. Built-in Functions", just not in tutorial section "7.2. Reading and Writing Files". 'w+' truncates the file, which is appropriate here since the contents of the file were just processed higher up in daemon.py (in a disturbing way, but never mind that). But you might as well use just 'w'.
- One can never used
os.access
to check the possibility to create a file.
- Checking against readability at that point is too late. If the pidfile exists and is not readable, the code higher up in daemon.py will bail out without proper error handling.
comment:7 by , 13 years ago
i've also confirmed the bug and patch. this is a regression from 0.12.2 where tracd would start up fine in daemon mode with a pid file that didn't already exist.
this bug actually makes a real pain to start tracd using an initscript that relies a pid file, as tracd deletes the pid file after closing. in order to work around the bug, it's not only necessary to recreate the pid file, but also to enter a pid into it or else I get "Invalid PID in file /path/to/pidfile". the only other workaround is to not use a PID file at all.
comment:8 by , 13 years ago
#10586 was closed as duplicate of this one, and have a solution proposal / file attached.
comment:10 by , 13 years ago
Cc: | added |
---|
comment:11 by , 13 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Indeed, daemonizing when --pidfile
is specified fails if the file doesn't exist. I fixed it in [11084] by using the mode "a+" instead of "r+", so that the file is created if it doesn't exist, but remains unchanged if it does.
comment:12 by , 13 years ago
Owner: | set to |
---|
I've patched my Trac 0.12.3 with this line of code: