Call /etc/init.d/codemux only when codemux is installed
[nodemanager.git] / plugins / codemux.py
index b367b58..f14fdc0 100644 (file)
@@ -12,9 +12,9 @@ from config import Config
 CODEMUXCONF="/etc/codemux/codemux.conf"
 
 def start(options, conf):
 CODEMUXCONF="/etc/codemux/codemux.conf"
 
 def start(options, conf):
-    logger.log("codemux plugin starting up...")
+    logger.log("codemux: plugin starting up...")
 
 
-def GetSlivers(plc, data, config):
+def GetSlivers(data, config, plc = None):
     """
     For each sliver with the codemux attribute, parse out "host,port" 
     and make entry in conf.  Restart service after.
     """
     For each sliver with the codemux attribute, parse out "host,port" 
     and make entry in conf.  Restart service after.
@@ -35,13 +35,20 @@ def GetSlivers(plc, data, config):
     if slicesinconf.has_key("root"): _writeconf = False
     else: _writeconf = True
 
     if slicesinconf.has_key("root"): _writeconf = False
     else: _writeconf = True
 
+    if 'slivers' not in data:
+        logger.log("codemux.GetSlivers: could not find the slivers keyin data (PLC connection down?) - IGNORED")
+        return
+
     # Parse attributes and update dict of scripts
     for sliver in data['slivers']:
         for attribute in sliver['attributes']:
             if attribute['tagname'] == 'codemux':
                 # add to conf.  Attribute is [host, port]
     # Parse attributes and update dict of scripts
     for sliver in data['slivers']:
         for attribute in sliver['attributes']:
             if attribute['tagname'] == 'codemux':
                 # add to conf.  Attribute is [host, port]
-                params = {'host': attribute['value'].split(",")[0], 
-                          'port': attribute['value'].split(",")[1]}
+                parts = attribute['value'].split(",")
+                if len(parts)<2:
+                    logger.log("codemux: attribute value (%s) for codemux not separated by comma. Skipping."%attribute['value'])
+                    continue
+                params = {'host': parts[0], 'port': parts[1]}
                 try:
                     # Check to see if sliver is running.  If not, continue
                     if vserver.VServer(sliver['name']).is_running():
                 try:
                     # Check to see if sliver is running.  If not, continue
                     if vserver.VServer(sliver['name']).is_running():
@@ -138,6 +145,7 @@ def isRunning():
 
 
 def restartService():
 
 
 def restartService():
+    if not os.path.exists("/etc/init.d/codemux"): return
     logger.log("codemux:  Restarting codemux service")
     if isRunning():
         logger.log_call("/etc/init.d/codemux","condrestart")
     logger.log("codemux:  Restarting codemux service")
     if isRunning():
         logger.log_call("/etc/init.d/codemux","condrestart")
@@ -146,12 +154,16 @@ def restartService():
 
 
 def startService():
 
 
 def startService():
+    if not os.path.exists("/etc/init.d/codemux"): return
     if not isRunning():
         logger.log("codemux:  Starting codemux service")
         logger.log_call("/etc/init.d/codemux", "start")
     if not isRunning():
         logger.log("codemux:  Starting codemux service")
         logger.log_call("/etc/init.d/codemux", "start")
+    logger.log_call("/sbin/chkconfig", "codemux", "on")
 
 
 def stopService():
 
 
 def stopService():
+    if not os.path.exists("/etc/init.d/codemux"): return
     if isRunning():
         logger.log("codemux:  Stopping codemux service")
         logger.log_call("/etc/init.d/codemux", "stop")
     if isRunning():
         logger.log("codemux:  Stopping codemux service")
         logger.log_call("/etc/init.d/codemux", "stop")
+    logger.log_call("/sbin/chkconfig", "codemux", "off")