[Uludag-commits] r16958 - branches/pardus-python/pardus
uludag-commits at pardus.org.tr
uludag-commits at pardus.org.tr
4 Şub 2008 Pzt 15:48:59 EET
Author: bahadir.kandemir
Date: Mon Feb 4 15:48:59 2008
New Revision: 16958
Modified:
branches/pardus-python/pardus/serviceutils.py
Log:
Get saved service states from /etc/conf.d/mudur
Modified: branches/pardus-python/pardus/serviceutils.py
=================================================================
--- branches/pardus-python/pardus/serviceutils.py (original)
+++ branches/pardus-python/pardus/serviceutils.py Mon Feb 4 15:48:59 2008
@@ -26,16 +26,14 @@
# utility functions
-def is_on():
- return "off"
-
-def loadConfig():
+def loadConfig(filename=None):
conf = {}
- try:
- from csl import serviceConf
- except ImportError:
- serviceConf = script()[0]
- filename = "/etc/conf.d/%s" % serviceConf
+ if not filename:
+ try:
+ from csl import serviceConf
+ except ImportError:
+ serviceConf = script()[0]
+ filename = "/etc/conf.d/%s" % serviceConf
if not os.path.exists(filename):
return conf
for line in file(filename):
@@ -48,6 +46,19 @@
conf[key] = value
return conf
+def is_on():
+ state = "off"
+ try:
+ from csl import serviceDefault
+ state = serviceDefault
+ except:
+ pass
+ config = loadConfig("/etc/conf.d/mudur")
+ services = config.get("services", "").split()
+ if script() in services:
+ state = "on"
+ return state
+
def loadEnvironment():
basePath = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:"
if os.path.exists("/etc/profile.env"):
@@ -90,7 +101,10 @@
Arguments are service names.
"""
for service in services:
- call(service, "System.Service", "start")
+ try:
+ call(service, "System.Service", "start")
+ except:
+ pass
# Service control utilities
@@ -372,7 +386,7 @@
state = "stopped"
except:
pass
- return "\n".join([serviceType, state, serviceDesc])
+ return serviceType, serviceDesc, state
def ready():
if is_on() == "on":
@@ -382,4 +396,18 @@
def setState(state=None):
if state != "on" and state != "off":
fail("Unknown state '%s'" % state)
+
+ config = loadConfig("/etc/conf.d/mudur")
+ services = set(config.get("services", "").split())
+
+ if state == "on":
+ services.add(script())
+ elif script() in services:
+ services.remove(script())
+
+ import re
+ content = file("/etc/conf.d/mudur").read()
+ content = re.sub("services\s*=.*", "services = %s" % " ".join(services), content)
+ file("/etc/conf.d/mudur", "w").write(content)
+
notify("System.Service", "Changed", (script(), state))
Uludag-commits mesaj listesiyle ilgili
daha fazla bilgi