Can background and run plc.
authorFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Tue, 17 Mar 2009 19:13:03 +0000 (19:13 +0000)
committerFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Tue, 17 Mar 2009 19:13:03 +0000 (19:13 +0000)
geni/geniwrapper [new file with mode: 0644]
geni/plc.py

diff --git a/geni/geniwrapper b/geni/geniwrapper
new file mode 100644 (file)
index 0000000..abfa428
--- /dev/null
@@ -0,0 +1,75 @@
+#!/bin/bash
+#
+# geniwrapper   Wraps PLCAPI into the GENI compliant API
+#
+# chkconfig: 2345 5 99
+#
+# description:   Wraps PLCAPI into the GENI compliant API
+#
+# $Id$
+#
+
+# Source config
+. /usr/share/geniwrapper/geni/util/geni_config
+
+# source function library
+. /etc/init.d/functions
+
+
+start() {
+        echo -n $"Starting GENIWrapper:  "
+
+        if [ "$GENI_REGISTRY_ENABLE" ]; then
+            echo "Registry"
+            daemon $GENI_BASE_DIR/geni/plc.py -r -d $OPTIONS
+        fi
+
+        if [ "$GENI_AGGREGATE_ENABLED" ]; then
+            echo "Aggregate"
+            daemon $GENI_BASE_DIR/geni/plc.py -a -d $OPTIONS
+        fi
+        RETVAL=$?
+        echo
+        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/geniwrapper
+
+}
+
+stop() {
+    echo -n $"Shutting down GENIWrapper: "
+    killproc plc.py
+    RETVAL=$?
+
+    echo
+    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/geniwrapper
+}
+
+
+
+case "$1" in
+  start)
+    start
+    ;;
+  stop)
+    stop
+    ;;
+  restart|reload)
+    stop
+    start
+    ;;
+  condrestart)
+    if [ -f /var/lock/subsys/geniwrapper ]; then
+        stop
+        start
+    fi
+    ;;
+  status)
+    status geniwrapper
+    RETVAL=$?
+    ;;
+  *)
+    echo $"Usage: $0 {start|stop|restart|condrestart|status}"
+    exit 1
+esac
+
+exit $RETVAL
+
index 66d8ae2..a9322ad 100644 (file)
@@ -41,6 +41,21 @@ from geni.registry import Registry
 from geni.aggregate import Aggregate
 from geni.slicemgr import SliceMgr
 
+
+# after http://www.erlenstar.demon.co.uk/unix/faq_2.html
+def daemon():
+    """Daemonize the current process."""
+    if os.fork() != 0: os._exit(0)
+    os.setsid()
+    if os.fork() != 0: os._exit(0)
+    os.umask(0)
+    devnull = os.open(os.devnull, os.O_RDWR)
+    os.dup2(devnull, 0)
+    # xxx fixme - this is just to make sure that nothing gets stupidly lost - should use devnull
+    crashlog = os.open('/var/log/geni.daemon', os.O_RDWR | os.O_APPEND | os.O_CREAT, 0644)
+    os.dup2(crashlog, 1)
+    os.dup2(crashlog, 2)
+
 def main():
     global AuthHierarchy
     global TrustedRoots
@@ -58,10 +73,14 @@ def main():
          help="run aggregate manager", default=False)
     parser.add_option("-v", "--verbose", dest="verbose", action="store_true", 
          help="verbose mode", default=False)
+    parser.add_option("-d", "--daemon", dest="daemon", action="store_true",
+         help="Run as daemon.", default=False)
     (options, args) = parser.parse_args()
  
     key_file = "server.key"
     cert_file = "server.cert"
+    
+    if (options.daemon):  daemon()
 
     if (os.path.exists(key_file)) and (not os.path.exists(cert_file)):
         # If private key exists and cert doesnt, recreate cert