check for start|stop|restart
Thierry Parmentelat [Tue, 15 Mar 2011 16:23:36 +0000 (17:23 +0100)]
dummy stop for now

plc_sliceinitscripts/sirius

index 6cbf443..89b17f1 100644 (file)
@@ -240,20 +240,54 @@ def server():
 
 ########################################
 
-if DEBUGLEVEL < 2:
-    PIDFILE = '/tmp/sirius.pid'
-else:
-    PIDFILE = 'sirius.pid'
-
-try:
-    if os.fork():
-        sys.exit(0)
-    f = open(PIDFILE, 'w')
-    fcntl.flock(f.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
-except:
-    logexception()
-    sys.exit(1)
-
-Periodic(updateschedule, SLOTDURATION, -5*ONEMINUTE, -1*ONEMINUTE)
-Periodic(updateloans, 5*ONEMINUTE, 0, 0)
-server()
+def start (slicename):
+    if DEBUGLEVEL < 2:
+        PIDFILE = '/tmp/%s.pid'%slicename
+    else:
+        PIDFILE = '%s.pid'%slicename
+    try:
+        if os.fork():
+            sys.exit(0)
+        f = open(PIDFILE, 'w')
+        fcntl.flock(f.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
+    except:
+        logexception()
+        sys.exit(1)
+
+    Periodic(updateschedule, SLOTDURATION, -5*ONEMINUTE, -1*ONEMINUTE)
+    Periodic(updateloans, 5*ONEMINUTE, 0, 0)
+    server()
+
+# xxx fixme
+# at the very least, do nothing 
+def stop(slicename):
+    print '(dummy) stopping',slicename
+    pass
+
+def restart(slicename):
+    stop(slicename)
+    start(slicename)
+
+def main():
+    args=sys.argv[1:]
+    mode='start'
+    slicename='sirius'
+    argc=len(args)
+    if argc>=3: 
+        print 'too many arguments to initscript',args
+        sys.exit(1)
+    elif argc==2: (mode,slicename)=args
+    elif argc==1: mode=args[0]
+    
+#    print "sirius initscript called with mode=%s and slicename=%s"%(mode,slicename)
+
+    if mode=='start': start(slicename)
+    elif mode=='stop': stop(slicename)
+    elif mode=='restart': restart(slicename)
+    else: 
+        print "unknown mode %s"%mode
+        sys.exit(1)
+    sys.exit(0)
+
+if __name__ == '__main__':
+    main()