diff --git a/bin/datastore-service b/bin/datastore-service index 03f7a89..9c249cb 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,22 @@ ds.complete_indexing() logger.info("Starting Datastore %s" % (repo_dir)) mainloop = gobject.MainLoop() +def handle_disconnect(): + global connected + ds.stop() + connected = False + print "shutdown cleanly" + def handle_shutdown(signum, frame): ds.stop() print "shutdown cleanly" 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,7 +84,8 @@ def main(): import time context = mainloop.get_context() try: - while True: + while connected: + print connected context.iteration(False) time.sleep(0.0025)