[Uludag-commits] r16959 - branches/mudur/bin

uludag-commits at pardus.org.tr uludag-commits at pardus.org.tr
4 Şub 2008 Pzt 15:50:53 EET


Author: bahadir.kandemir
Date: Mon Feb  4 15:50:52 2008
New Revision: 16959

Added:
   branches/mudur/bin/service2.py   (contents, props changed)
Modified:
   branches/mudur/bin/mudur.py
Log:
Mudur now uses COMAR2 if mudur=dbus passed as kernel parameter.


Modified: branches/mudur/bin/mudur.py
=================================================================
--- branches/mudur/bin/mudur.py	(original)
+++ branches/mudur/bin/mudur.py	Mon Feb  4 15:50:52 2008
@@ -188,8 +188,10 @@
             "debug": False,
             "livecd": False,
             "safe": False,
+            "dbus": False,
             "forcefsck": False,
-            "head_start": "kdebase",
+            "head_start": "",
+            "services": "",
         }
         # load config file if exists
         if os.path.exists("/etc/conf.d/mudur"):
@@ -237,6 +239,8 @@
                     self.opts["debug"] = True
                 elif opt == "safe":
                     self.opts["safe"] = True
+                elif opt == "dbus":
+                    self.opts["dbus"] = True
                 elif opt.startswith("language:"):
                     self.opts["language"] = opt[9:]
                 elif opt.startswith("keymap:"):
@@ -423,47 +427,124 @@
 #
 
 def startComar():
-    ui.info(_("Starting COMAR"))
-    # If a job crashes before finishing a transaction, Berkeley DB halts.
-    # We are deleting DB log files before starting Comar, so a reboot fixes
-    # the problem if it ever happens.
-    delete("/var/db/comar/__*")
-    delete("/var/db/comar/log*")
-    run("/sbin/start-stop-daemon", "-b", "--start", "--quiet",
-        "--pidfile", "/var/run/comar.pid", "--make-pidfile",
-        "--exec", "/usr/bin/comar")
+    if config.get("dbus"):
+        if not os.path.exists("/var/lib/dbus/machine-id"):
+            run("/usr/bin/dbus-uuidgen", "--ensure")
+        run("/sbin/start-stop-daemon", "-b", "--start", "--quiet",
+            "--pidfile", "/var/run/dbus/pid", "--exec", "/usr/bin/dbus-daemon",
+            "--", "--system")
+        waitBus("/var/run/dbus/system_bus_socket")
+    else:
+        ui.info(_("Starting COMAR"))
+        # If a job crashes before finishing a transaction, Berkeley DB halts.
+        # We are deleting DB log files before starting Comar, so a reboot fixes
+        # the problem if it ever happens.
+        delete("/var/db/comar/__*")
+        delete("/var/db/comar/log*")
+        run("/sbin/start-stop-daemon", "-b", "--start", "--quiet",
+            "--pidfile", "/var/run/comar.pid", "--make-pidfile",
+            "--exec", "/usr/bin/comar")
+
+def startService(service, bus, detach=False):
+    if not detach:
+        ui.info("Starting %s..." % service)
+        obj = bus.get_object("tr.org.pardus.comar", "/package/%s" % service, introspect=False)
+        obj.start(dbus_interface="tr.org.pardus.comar.System.Service")
+    else:
+        obj = bus.get_object("tr.org.pardus.comar", "/package/%s" % service, introspect=False)
+        obj.start(dbus_interface="tr.org.pardus.comar.System.Service", ignore_reply=True)
+
+def stopService(service, bus):
+    obj = bus.get_object("tr.org.pardus.comar", "/package/%s" % service, introspect=False)
+    ui.info("Stopping %s..." % service)
+    obj.stop(dbus_interface="tr.org.pardus.comar.System.Service")
+
+def getServices(startupOnly, bus):
+    if startupOnly:
+        return config.get('services').split()
+    else:
+        obj = bus.get_object("tr.org.pardus.comar", "/", introspect=False)
+        return obj.listModelApplications("System.Service", dbus_interface="tr.org.pardus.comar")
 
 def startServices(extras=None):
     if extras is None:
-        ui.info(_("Starting services"))
-    import comar
-    waitBus("/var/run/comar.socket")
-    try:
-        link = comar.Link()
-    except:
-        ui.error(_("Cannot connect to COMAR, services won't be started"))
-        return
-    # Almost everything depends on logger, so start manually
-    link.call_package("System.Service.start", "sysklogd")
-    if not waitBus("/dev/log", stream=False):
-        ui.warn(_("Cannot start system logger"))
-    if extras:
-        for service in extras:
-            link.System.Service[service].start()
-        return
-    # Give login screen a headstart
-    link.call_package("System.Service.ready", config.get("head_start"))
-    if not config.get("safe"):
-        waitBus("/tmp/.X11-unix/X0", timeout=3)
-        link.call("System.Service.ready")
+        if config.get("dbus"):
+            ui.info(_("Starting services with DBus"))
+        else:
+            ui.info(_("Starting services"))
+    if config.get("dbus"):
+        import dbus
+        try:
+            bus = dbus.SystemBus()
+        except dbus.DBusException:
+            ui.error(_("Cannot connect to DBus, services won't be started"))
+            return
+        
+        # Almost everything depends on logger, so start manually
+        try:
+            startService("sysklogd", bus)
+        except dbus.DBusException, exception:
+            pass
+        if extras:
+            for service in extras:
+                try:
+                    startService(service, bus, detach=True)
+                except dbus.DBusException:
+                    pass
+            return
+        # Give login screen a headstart
+        #if config.get("head_start"):
+        #    startService(config.get("head_start"), bus, detach=True)
+        if not config.get("safe"):
+            for service in getServices(True, bus):
+                startService(str(service), bus, detach=True)
+    else:
+        import comar
+        waitBus("/var/run/comar.socket")
+        try:
+            link = comar.Link()
+        except:
+            ui.error(_("Cannot connect to COMAR, services won't be started"))
+            return
+        # Almost everything depends on logger, so start manually
+        link.call_package("System.Service.start", "sysklogd")
+        if not waitBus("/dev/log", stream=False):
+            ui.warn(_("Cannot start system logger"))
+        if extras:
+            for service in extras:
+                link.System.Service[service].start()
+            return
+        # Give login screen a headstart
+        link.call_package("System.Service.ready", config.get("head_start"))
+        if not config.get("safe"):
+            waitBus("/tmp/.X11-unix/X0", timeout=3)
+            link.call("System.Service.ready")
 
 def stopServices():
-    ui.info(_("Stopping services"))
-    run_quiet("/usr/bin/hav", "call", "System.Service.stop")
+    if config.get("dbus"):
+        ui.info(_("Stopping services with DBus"))
+        import dbus
+        try:
+            bus = dbus.SystemBus()
+        except dbus.DBusException:
+            return
+        
+        for service in getServices(False, bus):
+            try:
+                stopService(service, bus)
+            except dbus.DBusException:
+                pass
+    else:
+        ui.info(_("Stopping services"))
+        run_quiet("/usr/bin/hav", "call", "System.Service.stop")
 
 def stopComar():
-    ui.info(_("Stopping COMAR"))
-    run("start-stop-daemon", "--stop", "--quiet", "--pidfile", "/var/run/comar.pid")
+    if config.get("dbus"):
+        ui.info(_("Stopping DBus"))
+        run("start-stop-daemon", "--stop", "--quiet", "--pidfile", "/var/run/dbus/pid")
+    else:
+        ui.info(_("Stopping COMAR"))
+        run("start-stop-daemon", "--stop", "--quiet", "--pidfile", "/var/run/comar.pid")
 
 
 #


Uludag-commits mesaj listesiyle ilgili daha fazla bilgi