Edgewall Software
Modify

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#10566 closed defect (fixed)

Error writing to PID file while starting tracd in daemon mode

Reported by: f.rochlitzer@… 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@…
Release Notes:
API 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 Changed 6 years ago by f.rochlitzer@…

I've patched my Trac 0.12.3 with this line of code:

fileobj = open(pidfile, 'w+')

comment:2 Changed 6 years ago by Christian Boos

Component: generalweb frontend/tracd
Milestone: 0.12.4

Right. Thanks for the report!

comment:3 Changed 6 years ago by anonymous

I've confirmed the bug and the patch in a brand new installation.

comment:4 Changed 6 years ago by thiagokronig@…

I've confirmed the bug and the patch in a brand new installation.

comment:5 Changed 6 years ago by Stein Somers <ssomers@…>

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 Changed 6 years ago by Stein Somers <ssomers@…>

Actually, my comment was baloney from start to end.

  1. 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'.
  1. One can never used os.access to check the possibility to create a file.
  1. 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 Changed 6 years ago by anonymous

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 Changed 6 years ago by AdrianFritz

#10586 was closed as duplicate of this one, and have a solution proposal / file attached.

comment:9 Changed 6 years ago by Remy Blank

#10615 was closed as a duplicate.

comment:10 Changed 6 years ago by Daniel Kahn Gillmor <dkg@…>

Cc: dkg@… added

comment:11 Changed 6 years ago by Remy Blank

Resolution: fixed
Status: newclosed

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 Changed 6 years ago by Remy Blank

Owner: set to Remy Blank

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Remy Blank.
The resolution will be deleted.
to The owner will be changed from Remy Blank to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.