logrotate: Allow logs to be missing
[sliver-openvswitch.git] / xenserver / etc_init.d_vswitch
index bb0011e..74162dc 100755 (executable)
 test -e /etc/sysconfig/vswitch && . /etc/sysconfig/vswitch
 
 # General config variables in /etc/sysconfig/vswitch
-: ${VSWITCH_BASE:=/root/vswitch}
-: ${ENABLE_BRCOMPAT:=y}
-: ${ENABLE_FAKE_PROC_NET:=y}
+: ${ENABLE_BRCOMPAT:=n}
+: ${ENABLE_FAKE_PROC_NET:=n}
 : ${FORCE_COREFILES:=y}
 
 # Config variables specific to ovs-vswitchd
 : ${VSWITCHD_CONF:=/etc/ovs-vswitchd.conf}
 : ${VSWITCHD_PIDFILE:=/var/run/ovs-vswitchd.pid}
 : ${VSWITCHD_RUN_DIR:=/var/xen/vswitch}
-: ${VSWITCHD_PRIORITY:=-5}
-: ${VSWITCHD_NETBACK_PRIORITY:=0}
+: ${VSWITCHD_PRIORITY:=-10}
 : ${VSWITCHD_LOGFILE:=/var/log/ovs-vswitchd.log}
-: ${VSWITCHD_FILE_LOGLEVEL:=}
-: ${VSWITCHD_SYSLOG_LOGLEVEL:=WARN}
+: ${VSWITCHD_FILE_LOGLEVEL:=INFO}
+: ${VSWITCHD_SYSLOG_LOGLEVEL:=ERR}
 : ${VSWITCHD_MEMLEAK_LOGFILE:=}
 : ${VSWITCHD_STRACE_LOG:=}
 : ${VSWITCHD_STRACE_OPT:=}
@@ -47,10 +45,10 @@ test -e /etc/sysconfig/vswitch && . /etc/sysconfig/vswitch
 # Config variables specific to ovs-brcompatd
 : ${BRCOMPATD_PIDFILE:=/var/run/ovs-brcompatd.pid}
 : ${BRCOMPATD_RUN_DIR:=/var/xen/vswitch}
-: ${BRCOMPATD_PRIORITY:=-5}
+: ${BRCOMPATD_PRIORITY:=-10}
 : ${BRCOMPATD_LOGFILE:=/var/log/ovs-brcompatd.log}
-: ${BRCOMPATD_FILE_LOGLEVEL:=}
-: ${BRCOMPATD_SYSLOG_LOGLEVEL:=INFO}
+: ${BRCOMPATD_FILE_LOGLEVEL:=INFO}
+: ${BRCOMPATD_SYSLOG_LOGLEVEL:=ERR}
 : ${BRCOMPATD_MEMLEAK_LOGFILE:=}
 : ${BRCOMPATD_STRACE_LOG:=}
 : ${BRCOMPATD_STRACE_OPT:=}
@@ -58,11 +56,11 @@ test -e /etc/sysconfig/vswitch && . /etc/sysconfig/vswitch
 : ${BRCOMPATD_VALGRIND_OPT:=}
 
 # Full paths to executables & modules
-vswitchd="$VSWITCH_BASE/sbin/ovs-vswitchd"
-brcompatd="$VSWITCH_BASE/sbin/ovs-brcompatd"
-dpctl="$VSWITCH_BASE/bin/ovs-dpctl"
-appctl="$VSWITCH_BASE/bin/ovs-appctl"
-ofctl="$VSWITCH_BASE/bin/ovs-ofctl"
+vswitchd="/usr/sbin/ovs-vswitchd"
+brcompatd="/usr/sbin/ovs-brcompatd"
+dpctl="/usr/bin/ovs-dpctl"
+appctl="/usr/bin/ovs-appctl"
+ofctl="/usr/bin/ovs-ofctl"
 
 
 if [ "$ENABLE_FAKE_PROC_NET" = "y" ]; then
@@ -89,10 +87,10 @@ function remove_all_dp {
 function insert_modules_if_required {
     if ! lsmod | grep -q "openvswitch_mod"; then
         action "Inserting llc module" modprobe llc
-        action "Inserting openvswitch module" insmod $VSWITCH_BASE/kernel_modules/openvswitch_mod.ko
+        action "Inserting openvswitch module" modprobe openvswitch_mod
     fi
-    if [ -n "$BRCOMPATD_PIDFILE" ] && ! lsmod | grep -q "brcompat_mod"; then
-        action "Inserting brcompat module" insmod $VSWITCH_BASE/kernel_modules/brcompat_mod.ko
+    if [ "$ENABLE_BRCOMPAT" = "y" ] && [ -n "$BRCOMPATD_PIDFILE" ] && ! lsmod | grep -q "brcompat_mod"; then
+        action "Inserting brcompat module" modprobe brcompat_mod
     fi
 }
 
@@ -113,26 +111,11 @@ function reload_vswitchd {
     fi
 }
 
-function quietly {
-    "$@" > /dev/null
-}
-
-# renice_netback PRIORITY PID [PID...]
-#
-# Renices the netback processes given as each PID to nice level PRIORITY.
-function renice_netback {
-    local pri=$1
-    shift
-
-    if test $# = 0; then
-        warning "Netback not running, nothing to renice"
-        return
+function reload_brcompatd {
+    if [ -f "$BRCOMPATD_PIDFILE" ]; then
+        "$appctl" \
+            --target=ovs-brcompatd.$(cat "$BRCOMPATD_PIDFILE").ctl --reopen
     fi
-
-    for pid
-    do
-        action "Renicing netback (pid $pid) to priority $pri" quietly renice $pri -p $pid
-    done
 }
 
 function start_vswitchd {
@@ -172,11 +155,6 @@ function start_vswitchd {
     if [ "$ENABLE_FAKE_PROC_NET" = "y" ]; then
         fake_proc_net_opt="--fake-proc-net"
     fi
-    if [ "$VSWITCHD_NETBACK_PRIORITY" != default ]; then
-        renice_netback $VSWITCHD_NETBACK_PRIORITY $(pidof netback)
-    else
-        warning "Netback renicing disabled (see /etc/sysconfig/vswitch)"
-    fi
     if [ "$daemonize" != "y" ]; then
         # Start in background and force a "success" message
         action "Starting ovs-vswitchd ($strace_opt$valgrind_opt)" true
@@ -194,7 +172,7 @@ function start_brcompatd {
         mkdir -p "$BRCOMPATD_RUN_DIR"
     fi
     cd "$BRCOMPATD_RUN_DIR"
-    if [ -n "$BRCOMPATD_FILE_LOGLEVEL" ]; then
+    if [ -n "$BRCOMPATD_FILE_LOGLEVEL" ]; then
         logfile_level_opt="-vANY:FILE:${BRCOMPATD_FILE_LOGLEVEL}"
         logfile_file_opt="--log-file=$BRCOMPATD_LOGFILE"
     fi
@@ -286,16 +264,28 @@ function start {
     if [ ! -e "$VSWITCHD_CONF" ]; then
         warning "$VSWITCHD_CONF does not exist"
         action "Creating empty $VSWITCHD_CONF" touch "$VSWITCHD_CONF"
+    elif [ ! -e /var/run/vswitch.booted ]; then
+        touch /var/run/vswitch.booted
+        /usr/bin/ovs-cfg-mod '-vANY:console:emer' -F "$VSWITCHD_CONF" \
+            '--del-match=bridge.*' \
+            '--del-match=port.*' \
+            '--del-match=bonding.*' \
+            '--del-match=iface.*' \
+            '--del-match=vlan.*'
     fi
 
     start_vswitchd
-    start_brcompatd
+    if [ "${ENABLE_BRCOMPAT}" = "y" ] ; then
+        start_brcompatd
+    fi
     reload_vswitchd  # ensures ovs-vswitchd has fully read config file.
+    touch /var/lock/subsys/vswitch
 }
 
 function stop {
     stop_brcompatd
     stop_vswitchd
+    rm -f /var/lock/subsys/vswitch
 }
 
 function restart {
@@ -317,6 +307,7 @@ case "$1" in
         ;;
     reload)
         reload_vswitchd
+        reload_brcompatd
         ;;
     strace-vswitchd)
         shift
@@ -328,11 +319,16 @@ case "$1" in
         ;;
     status)
         status -p ovs-vswitchd.pid ovs-vswitchd
-        status -p ovs-brcompatd.pid ovs-brcompatd
+        rc=$?
+        if [ $rc -eq 0 ] && [ "$ENABLE_BRCOMPAT" = "y" ] ; then
+            status -p ovs-brcompatd.pid ovs-brcompatd
+            rc=$?
+        fi
+        exit $rc
         ;;
     version)
-        "$VSWITCH_BASE"/sbin/ovs-vswitchd -V
-        "$VSWITCH_BASE"/sbin/ovs-brcompatd -V
+        /usr/sbin/ovs-vswitchd -V
+        /usr/sbin/ovs-brcompatd -V
         ;;
     help)
         printf "vswitch [start|stop|restart|reload|unload|status|version]\n"