Merge lp:~sil/desktopcouch/logging-find-port-linux-461114 into lp:desktopcouch

Proposed by Stuart Langridge
Status: Merged
Approved by: Nicola Larosa
Approved revision: 95
Merged at revision: not available
Proposed branch: lp:~sil/desktopcouch/logging-find-port-linux-461114
Merge into: lp:desktopcouch
Diff against target: 75 lines
1 file modified
desktopcouch/__init__.py (+31/-2)
To merge this branch: bzr merge lp:~sil/desktopcouch/logging-find-port-linux-461114
Reviewer Review Type Date Requested Status
Chad Miller (community) Approve
Eric Casteleijn (community) Approve
Vincenzo Di Somma (community) Approve
Review via email: mp+14193@code.launchpad.net

Commit message

Add extra logging to try and determine why bug#461114 happens (couldn't find a port in find_port_linux).

To post a comment you must log in.
Revision history for this message
Stuart Langridge (sil) wrote :

Add extra logging to try and determine why bug 461114 happens (couldn't find a port in find_port_linux).

Revision history for this message
Vincenzo Di Somma (vds) wrote :

Looks good.

review: Approve
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Looking good, tests pass

review: Approve
Revision history for this message
Chad Miller (cmiller) :
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-09-09 23:24:53 +0000
3+++ desktopcouch/__init__.py 2009-10-29 22:05:20 +0000
4@@ -16,21 +16,43 @@
5 "Desktop Couch helper files"
6
7 from __future__ import with_statement
8-import os, re
9+import os, re, xdg.BaseDirectory
10 from desktopcouch.start_local_couchdb import process_is_couchdb, read_pidfile
11
12+import logging, logging.handlers
13+log_directory = os.path.join(xdg.BaseDirectory.xdg_cache_home,
14+ "desktop-couch/log")
15+try:
16+ os.makedirs(log_directory)
17+except:
18+ pass
19+rotating_log = logging.handlers.TimedRotatingFileHandler(
20+ os.path.join(log_directory, "desktop-couch-startup.log"),
21+ "midnight", 1, 14)
22+rotating_log.setLevel(logging.DEBUG)
23+formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s')
24+rotating_log.setFormatter(formatter)
25+console_log = logging.StreamHandler()
26+console_log.setLevel(logging.WARNING)
27+console_log.setFormatter(logging.Formatter("%(asctime)s - %(message)s"))
28+logging.getLogger('').addHandler(console_log)
29+logging.getLogger('').addHandler(rotating_log)
30+logging.getLogger('').setLevel(logging.DEBUG)
31+log = logging.getLogger('')
32+
33 def find_pid(start_if_not_running=True):
34 # Work out whether CouchDB is running by looking at its pid file
35 pid = read_pidfile()
36 if not process_is_couchdb(pid) and start_if_not_running:
37 # start CouchDB by running the startup script
38- print "Desktop CouchDB is not running; starting it.",
39+ log.info("Desktop CouchDB is not running; starting it.")
40 from desktopcouch import start_local_couchdb
41 pid = start_local_couchdb.start_couchdb()
42 # now load the design documents, because it's started
43 start_local_couchdb.update_design_documents()
44
45 if not process_is_couchdb(pid):
46+ log.error("CouchDB process did not start up")
47 raise RuntimeError("desktop-couch not started")
48
49 return pid
50@@ -47,6 +69,7 @@
51 fd_paths = [os.readlink(os.path.join(fd_dir, fd))
52 for fd in os.listdir(fd_dir)]
53 except OSError:
54+ log.error("Unable to find file descriptors in /proc")
55 raise RuntimeError("Unable to find file descriptors in /proc")
56
57 # identify socket fds
58@@ -82,6 +105,11 @@
59 port = str(int(match.group(1), 16))
60 break
61 if port is None:
62+ log.error("Unable to find listening port")
63+ log.error("Looked at the following processes for inode %s:" % inode_subexp)
64+ fp = open(os.path.join(proc_dir, 'net', 'tcp'))
65+ log.error(fp.read())
66+ fp.close()
67 raise RuntimeError("Unable to find listening port")
68
69 return port
70@@ -95,4 +123,5 @@
71 "Linux": find_port__linux
72 } [os_name]
73 except KeyError:
74+ log.error("os %r is not yet supported" % (os_name,))
75 raise NotImplementedError("os %r is not yet supported" % (os_name,))

Subscribers

People subscribed via source and target branches