diff options
author | Marco Pesenti Gritti <mpg@redhat.com> | 2007-10-05 21:55:59 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <mpg@redhat.com> | 2007-10-05 21:55:59 (GMT) |
commit | f59c07164604226a05091a0b2a4179069eb678ac (patch) | |
tree | 460cf782a5ba612c3ca0ef9d9aa167fd7980b9f5 | |
parent | 15b33f9f7101266b9030a6f42b2e42793da7bf7f (diff) |
Exit cleanly when dbus goes down
-rw-r--r-- | NEWS | 2 | ||||
-rwxr-xr-x | bin/datastore-service | 20 |
2 files changed, 17 insertions, 5 deletions
@@ -1,3 +1,5 @@ +* Exit cleanly when dbus goes down. (marco) + Snapshot 64abebe398 * Do not index binaries. (bcsaller) diff --git a/bin/datastore-service b/bin/datastore-service index 03f7a89..13bf74d 100755 --- a/bin/datastore-service +++ b/bin/datastore-service @@ -44,6 +44,7 @@ if not sys.stdin.isatty(): # build the datastore dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) bus = dbus.SessionBus() +connected = True ds = DataStore() ds.registerBackend(backingstore.FileBackingStore) @@ -55,11 +56,20 @@ ds.complete_indexing() logger.info("Starting Datastore %s" % (repo_dir)) mainloop = gobject.MainLoop() +def handle_disconnect(): + global connected + connected = False + def handle_shutdown(signum, frame): - ds.stop() - print "shutdown cleanly" + global connected + connected = False raise SystemExit("Shutting down on signal %s" % signum) +bus.set_exit_on_disconnect(False) +bus.add_signal_receiver(handle_disconnect, + signal_name='Disconnected', + dbus_interface='org.freedesktop.DBus.Local') + signal.signal(signal.SIGHUP, handle_shutdown) signal.signal(signal.SIGTERM, handle_shutdown) @@ -72,20 +82,20 @@ def main(): import time context = mainloop.get_context() try: - while True: + while connected: context.iteration(False) time.sleep(0.0025) except KeyboardInterrupt: - ds.stop() logger.info("DataStore shutdown by user") except: - ds.stop() logger.debug("Datastore shutdown with error", exc_info=sys.exc_info()) main() +ds.stop() + #import hotshot #p = hotshot.Profile('hs.prof') #p.run('main()') |