In openflow-switch init script, do not re-load openflow_mod if already loaded.
[sliver-openvswitch.git] / debian / openflow-switch.init
index 2d0ff60..cc5f954 100755 (executable)
@@ -34,6 +34,17 @@ DODTIME=1                   # Time to wait for the server to die, in seconds
                             # 'restart' will not work
 
 # Include secchan defaults if available
+unset NETDEVS
+unset MODE
+unset SWITCH_IP
+unset CONTROLLER
+unset PRIVKEY
+unset CERT
+unset CACERT
+unset CACERT_MODE
+unset MGMT_VCONNS
+unset COMMANDS
+unset DAEMON_OPTS
 default=/etc/default/openflow-switch
 if [ -f $default ] ; then
        . $default
@@ -115,15 +126,21 @@ check_op() {
 }
 
 configure_ssl() {
-    if test ! -e "$PRIVKEY" || test ! -e "$CERT" || test ! -e "$CACERT"; then
+    if (test "$CACERT_MODE" != secure && test "$CACERT_MODE" != bootstrap) \
+       || test ! -e "$PRIVKEY" || test ! -e "$CERT" \
+       || (test ! -e "$CACERT" && test "$CACERT_MODE" != bootstrap); then
+        if test "$CACERT_MODE" != secure && test "$CACERT_MODE" != bootstrap
+        then
+            echo "CACERT_MODE is not set to 'secure' or 'bootstrap'"
+        fi
         if test ! -e "$PRIVKEY"; then
             echo "$PRIVKEY: private key missing" >&2
         fi
         if test ! -e "$CERT"; then
             echo "$CERT: certificate for private key missing" >&2
         fi
-        if test ! -e "$CACERT"; then
-            echo "$CACERT: CA certificate missing" >&2
+        if test ! -e "$CACERT" && test "$CACERT_MODE" != bootstrap; then
+            echo "$CACERT: CA certificate missing (and CA certificate bootstrapping not enabled)" >&2
         fi
         echo "Run ofp-switch-setup or edit /etc/default/openflow-switch to configure" >&2
         if test "$MODE" = discovery; then
@@ -131,7 +148,13 @@ configure_ssl() {
         fi
         exit 1
     fi
-    SSL_OPTS="--private-key=$PRIVKEY --certificate=$CERT --ca-cert=$CACERT"
+
+    SSL_OPTS="--private-key=$PRIVKEY --certificate=$CERT"
+    if test ! -e "$CACERT" && test "$CACERT_MODE" = bootstrap; then
+        SSL_OPTS="$SSL_OPTS --bootstrap-ca-cert=$CACERT"
+    else
+        SSL_OPTS="$SSL_OPTS --ca-cert=$CACERT"
+    fi
 }
 
 case "$1" in
@@ -176,10 +199,12 @@ case "$1" in
         esac
 
         echo -n "Loading openflow_mod: "
-        if modprobe openflow_mod; then
+        if grep -q '^openflow_mod$' /proc/modules; then
+            echo "already loaded, nothing to do."
+        elif modprobe openflow_mod; then
             echo "success."
         else
-            echo " ERROR."
+            echo "ERROR."
             echo "openflow_mod has probably not been built for this kernel."
             if ! test -d /usr/share/doc/openflow-datapath-source; then
                 echo "Install the openflow-datapath-source package, then read"
@@ -206,10 +231,25 @@ case "$1" in
             must_succeed "Disabling of0" ifconfig of0 down
         fi
 
+        MGMT_OPTS=
+        for vconn in $MGMT_VCONNS; do
+            MGMT_OPTS="$MGMT_OPTS --listen=$vconn"
+        done
+
+        COMMAND_OPT=
+        if test -n "$COMMANDS"; then
+            COMMAND_OPT="--commands=$COMMANDS"
+        fi
+
+        if test "$MODE" = out-of-band; then
+            DAEMON_OPTS="$DAEMON_OPTS --out-of-band"
+        fi
+
        echo -n "Starting $DESC: "
        start-stop-daemon --start --quiet --pidfile $PIDFILE \
            --exec $DAEMON -- nl:0 $CONTROLLER --detach --pidfile=$PIDFILE \
-            $DAEMON_OPTS $SSL_OPTS
+            --verbose=ANY:console:emer $DAEMON_OPTS $MGMT_OPTS $SSL_OPTS \
+            "$COMMAND_OPT"
         if running; then
             echo "$NAME."
         else