Merge lp:~cmiller/desktopcouch/service-exits-properly into lp:desktopcouch

Proposed by Chad Miller
Status: Merged
Approved by: dobey
Approved revision: 276
Merged at revision: 275
Proposed branch: lp:~cmiller/desktopcouch/service-exits-properly
Merge into: lp:desktopcouch
Diff against target: 98 lines (+28/-7)
2 files modified
desktopcouch/application/service.py (+23/-6)
desktopcouch/application/tests/test_service.py (+5/-1)
To merge this branch: bzr merge lp:~cmiller/desktopcouch/service-exits-properly
Reviewer Review Type Date Requested Status
dobey (community) Approve
Eric Casteleijn (community) Approve
Review via email: mp+58964@code.launchpad.net

Commit message

Shut down every child when service exits. On SIGTERM or SIGHUP, exit gracefully. (LP: 597197)

To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) :
review: Approve
Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :
Download full text (119.4 KiB)

The attempt to merge lp:~cmiller/desktopcouch/service-exits-properly into lp:desktopcouch failed. Below is the output from the failed tests.

Apache CouchDB has started, time to relax.
Browse your desktop CouchDB at file:///tmp/tmpaiH_vP/data/couchdb.html
desktopcouch.application.migration.tests.test_migration
  TestMigration
    test_migration_deleted_flag_to_trash ... Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/case.py", line 312, in run
    self.setUp()
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/application/migration/tests/test_migration.py", line 105, in setUp
    super(TestMigration, self).setUp()
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/application/migration/tests/test_migration.py", line 57, in setUp
    self.database = DesktopDatabase(self.dbname, create=True, ctx=self.ctx)
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/application/server.py", line 75, in __init__
    oauth_tokens=oauth_tokens, ctx=ctx, views_factory=views_factory)
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/records/database.py", line 123, in __init__
    self._reconnect()
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/application/server.py", line 85, in _reconnect
    super(DesktopDatabase, self)._reconnect(uri=uri)
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/records/database.py", line 139, in _reconnect
    self._server.create(self._database_name)
  File "/usr/lib/pymodules/python2.7/couchdb/client.py", line 193, in create
    self.resource.put_json(validate_dbname(name))
  File "/usr/lib/pymodules/python2.7/couchdb/http.py", line 405, in put_json
    status, headers, data = self.put(*a, **k)
  File "/usr/lib/pymodules/python2.7/couchdb/http.py", line 384, in put
    return self._request('PUT', path, body=body, headers=headers, **params)
  File "/usr/lib/pymodules/python2.7/couchdb/http.py", line 419, in _request
    credentials=self.credentials)
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/records/http.py", line 259, in request
    raise ServerError((status, error))
couchdb.http.ServerError: (400, ('invalid_consumer_token_pair', 'Invalid consumer and token pair.'))
[ERROR]
    test_migration_in_face_of_broken_records ... Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/case.py", line 312, in run
    self.setUp()
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/application/migration/tests/test_migration.py", line 105, in setUp
    super(TestMigration, self).setUp()
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/application/migration/tests/test_migration.py", line 57, in setUp
    self.database = DesktopDatabase(self.dbname, create=True, ctx=self.ctx)
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/application/server.py", line 75, in __init__
    oauth_tokens=oauth_tokens, ctx=ctx, views_factory=views_factory)
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/records/database.py", line 123, in __init__
    self._reconnect()
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/application/server.py", l...

Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :
Download full text (119.4 KiB)

The attempt to merge lp:~cmiller/desktopcouch/service-exits-properly into lp:desktopcouch failed. Below is the output from the failed tests.

Apache CouchDB has started, time to relax.
Browse your desktop CouchDB at file:///tmp/tmp36oZ76/data/couchdb.html
desktopcouch.application.migration.tests.test_migration
  TestMigration
    test_migration_deleted_flag_to_trash ... Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/case.py", line 312, in run
    self.setUp()
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/application/migration/tests/test_migration.py", line 105, in setUp
    super(TestMigration, self).setUp()
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/application/migration/tests/test_migration.py", line 57, in setUp
    self.database = DesktopDatabase(self.dbname, create=True, ctx=self.ctx)
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/application/server.py", line 75, in __init__
    oauth_tokens=oauth_tokens, ctx=ctx, views_factory=views_factory)
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/records/database.py", line 123, in __init__
    self._reconnect()
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/application/server.py", line 85, in _reconnect
    super(DesktopDatabase, self)._reconnect(uri=uri)
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/records/database.py", line 139, in _reconnect
    self._server.create(self._database_name)
  File "/usr/lib/pymodules/python2.7/couchdb/client.py", line 193, in create
    self.resource.put_json(validate_dbname(name))
  File "/usr/lib/pymodules/python2.7/couchdb/http.py", line 405, in put_json
    status, headers, data = self.put(*a, **k)
  File "/usr/lib/pymodules/python2.7/couchdb/http.py", line 384, in put
    return self._request('PUT', path, body=body, headers=headers, **params)
  File "/usr/lib/pymodules/python2.7/couchdb/http.py", line 419, in _request
    credentials=self.credentials)
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/records/http.py", line 259, in request
    raise ServerError((status, error))
couchdb.http.ServerError: (400, ('invalid_consumer_token_pair', 'Invalid consumer and token pair.'))
[ERROR]
    test_migration_in_face_of_broken_records ... Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/case.py", line 312, in run
    self.setUp()
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/application/migration/tests/test_migration.py", line 105, in setUp
    super(TestMigration, self).setUp()
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/application/migration/tests/test_migration.py", line 57, in setUp
    self.database = DesktopDatabase(self.dbname, create=True, ctx=self.ctx)
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/application/server.py", line 75, in __init__
    oauth_tokens=oauth_tokens, ctx=ctx, views_factory=views_factory)
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/records/database.py", line 123, in __init__
    self._reconnect()
  File "/home/otto/tarmac-builds/desktopcouch/trunk/desktopcouch/application/server.py", l...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/application/service.py'
2--- desktopcouch/application/service.py 2011-04-13 21:31:15 +0000
3+++ desktopcouch/application/service.py 2011-04-25 16:47:54 +0000
4@@ -146,14 +146,15 @@
5
6 def start(self):
7 """Start the services used by desktopcouch."""
8- should_shut_down_couchdb = False
9+ maintained_child_pids = list()
10 couchdb_pid = self._pid_finder(start_if_not_running=False,
11 ctx=self._ctx)
12 if couchdb_pid is None:
13 logging.warn("Starting up personal couchdb.")
14 couchdb_pid = self._pid_finder(start_if_not_running=True,
15 ctx=self._ctx)
16- should_shut_down_couchdb = True
17+ if couchdb_pid:
18+ maintained_child_pids.append(couchdb_pid)
19 else:
20 logging.warn("Personal couchdb is already running at PID#%d.",
21 couchdb_pid)
22@@ -168,6 +169,7 @@
23 return
24 else:
25 assert child_pid > 0
26+ maintained_child_pids.append(child_pid)
27 child_pid = self._fork() # Split!
28 if child_pid == 0:
29 # Let's be the migration tool!
30@@ -184,8 +186,18 @@
31 return
32 else:
33 assert child_pid > 0
34+ maintained_child_pids.append(child_pid)
35 # Let's be the dbus server!
36 # This is the parent process. When we exit, we kill children.
37+
38+ def receive_signal(signum, stackframe):
39+ """On signal, quit main loop gracefully."""
40+ logging.warn("Received signal %d. Quitting.", signum)
41+ self._mainloop.stop()
42+
43+ signal.signal(signal.SIGHUP, receive_signal)
44+ signal.signal(signal.SIGTERM, receive_signal)
45+
46 try:
47 set_up_logging("dbus")
48 # offer the dbus service
49@@ -195,14 +207,19 @@
50 "uncaught exception makes us shut down.")
51 finally:
52 logging.info("exiting.")
53- if should_shut_down_couchdb:
54- logging.warn("shutting down personal couchdb.")
55- self._stop_couchdb(ctx=self._ctx)
56+ self._stop_couchdb(ctx=self._ctx)
57
58+ for child_pid in maintained_child_pids:
59 try:
60 self._kill(child_pid, signal.SIGTERM)
61- self._sleep(1)
62+ logging.warn("Sent SIGTERM to %d", child_pid)
63+ except OSError:
64+ pass
65+ self._sleep(1)
66+ for child_pid in maintained_child_pids:
67+ try:
68 self._kill(child_pid, signal.SIGKILL)
69+ logging.warn("Sent SIGKILL to %d", child_pid)
70 except OSError:
71 pass
72 return # pylint: disable=W0150
73
74=== modified file 'desktopcouch/application/tests/test_service.py'
75--- desktopcouch/application/tests/test_service.py 2011-04-13 21:31:15 +0000
76+++ desktopcouch/application/tests/test_service.py 2011-04-25 16:47:54 +0000
77@@ -72,7 +72,7 @@
78 self._fork()
79 self.mocker.result(234) # We are parent
80 self._fork()
81- self.mocker.result(234) # We are parent
82+ self.mocker.result(345) # We are parent
83
84 # plugins load
85 semaphores = self.mocker.mock()
86@@ -121,9 +121,13 @@
87 # and then dbus service is ready to answer queries.
88
89 self._stop_couchdb(ctx=self._ctx)
90+ self._kill(self._pid_result, signal.SIGTERM)
91 self._kill(234, signal.SIGTERM)
92+ self._kill(345, signal.SIGTERM)
93 self._sleep(1)
94+ self._kill(self._pid_result, signal.SIGKILL)
95 self._kill(234, signal.SIGKILL)
96+ self._kill(345, signal.SIGKILL)
97
98 self.mocker.replay()
99

Subscribers

People subscribed via source and target branches