Merge lp:~ken-vandine/desktopcouch/desktopcouch-408796 into lp:desktopcouch

Proposed by Ken VanDine
Status: Merged
Approved by: Elliot Murphy
Approved revision: 24
Merged at revision: not available
Proposed branch: lp:~ken-vandine/desktopcouch/desktopcouch-408796
Merge into: lp:desktopcouch
Diff against target: None lines
To merge this branch: bzr merge lp:~ken-vandine/desktopcouch/desktopcouch-408796
Reviewer Review Type Date Requested Status
Elliot Murphy (community) Approve
Review via email: mp+9635@code.launchpad.net

Commit message

  Handle the case where the pid file is empty or doesn't exist (LP: #408796)

To post a comment you must log in.
Revision history for this message
Ken VanDine (ken-vandine) wrote :

  Handle the case where the pid file is empty or doesn't exist (LP: #408796)

Revision history for this message
Elliot Murphy (statik) wrote :

reviewed and tested locally.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/__init__.py'
2--- desktopcouch/__init__.py 2009-07-28 17:56:10 +0000
3+++ desktopcouch/__init__.py 2009-08-04 11:15:52 +0000
4@@ -24,19 +24,21 @@
5 def find_pid():
6 # Work out whether CouchDB is running by looking at its pid file
7 from desktopcouch import local_files
8- fp = open(local_files.FILE_PID)
9- pid = int(fp.read())
10- fp.close()
11+ pid = ''
12 try:
13- os.kill(pid, 0)
14- except os.error, detail:
15- if detail.errno == errno.ESRCH:
16- # pidfile is stale
17- # start CouchDB by running the startup script
18- print "Desktop CouchDB is not running; starting it."
19- from desktopcouch import start_local_couchdb
20- start_local_couchdb.start_couchdb()
21- time.sleep(2) # give the process a chance to start
22+ fp = open(local_files.FILE_PID)
23+ pid = int(fp.read())
24+ fp.close()
25+ except IOError:
26+ pass
27+
28+ if not is_couchdb(pid):
29+ # pidfile is stale
30+ # start CouchDB by running the startup script
31+ print "Desktop CouchDB is not running; starting it."
32+ from desktopcouch import start_local_couchdb
33+ start_local_couchdb.start_couchdb()
34+ time.sleep(2) # give the process a chance to start
35
36 # get the pid
37 try:
38@@ -49,24 +51,29 @@
39 raise
40 return pid
41
42-def find_port(pid):
43- # Look in the CouchDB log to find the port number, someday.
44- # Currently, we have to grovel around in /proc instead.
45- # Oh, the huge manatee... (this replaced an lsof shell recipe
46- # which was shorter but less reliable)
47-
48+def is_couchdb(pid):
49 proc_dir = "/proc/%s" % (pid,)
50
51 # check to make sure that the process still exists
52 if not os.path.isdir(proc_dir):
53- raise RuntimeError("Stale PID file or desktop-couch crashed")
54+ return False
55
56 # check to make sure it is actually a desktop-couch instance
57 with open(os.path.join(proc_dir, 'cmdline')) as cmd_file:
58 cmd = cmd_file.read()
59 if re.search('desktop-couch', cmd) is None:
60- raise RuntimeError("Stale PID file")
61-
62+ return False
63+
64+ return True
65+
66+def find_port(pid):
67+ # Look in the CouchDB log to find the port number, someday.
68+ # Currently, we have to grovel around in /proc instead.
69+ # Oh, the huge manatee... (this replaced an lsof shell recipe
70+ # which was shorter but less reliable)
71+
72+ proc_dir = "/proc/%s" % (pid,)
73+
74 # enumerate the process' file descriptors
75 fd_dir = os.path.join(proc_dir, 'fd')
76 fd_paths = [os.readlink(os.path.join(fd_dir, fd))

Subscribers

People subscribed via source and target branches