X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=debian%2Fopenvswitch-switch.init;h=8ea58660657ce099d14a25ca9364f872e3c988b6;hb=1b807595c4e6b4348444852bda8814e92412ad41;hp=7ce9a64508ebbbfe7736669b45415255665c1dc3;hpb=5f55c39b21e69025045437ffbd3bb98fe6ce2e89;p=sliver-openvswitch.git diff --git a/debian/openvswitch-switch.init b/debian/openvswitch-switch.init index 7ce9a6450..8ea586606 100755 --- a/debian/openvswitch-switch.init +++ b/debian/openvswitch-switch.init @@ -12,7 +12,7 @@ ### BEGIN INIT INFO # Provides: openvswitch-switch # Required-Start: $network $named $remote_fs $syslog -# Required-Stop: +# Required-Stop: $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Open vSwitch switch @@ -29,7 +29,7 @@ DODTIME=1 # Time to wait for the server to die, in seconds # let some servers to die gracefully and # 'restart' will not work -# Include ovs-openflowd defaults if available +# Include openvswitch-switch defaults if available unset OVSDB_SERVER_OPTS unset OVS_VSWITCHD_OPTS unset CORE_LIMIT @@ -66,11 +66,11 @@ running_pid() # running name # # Checks for a running process named 'name' by looking for a pidfile -# named /var/run/${name}.pid +# named /var/run/openvswitch/${name}.pid running() { local name=$1 - local pidfile=/var/run/${name}.pid + local pidfile=/var/run/openvswitch/${name}.pid # No pidfile, probably no daemon present [ ! -f "$pidfile" ] && return 1 @@ -84,19 +84,19 @@ running() # force_stop name # # Checks for a running process named 'name', by looking for a pidfile -# named /var/run/${name}.pid, and then kills it and waits for it to -# die. +# named /var/run/openvswitch/${name}.pid, and then kills it and waits +# for it to die. force_stop() { local name=$1 - local pidfile=/var/run/${name}.pid + local pidfile=/var/run/openvswitch/${name}.pid [ ! -f "$pidfile" ] && return if running $name; then kill $pid - [ -n "$DODTIME" ] && sleep "$DODTIME"s + [ -n "$DODTIME" ] && sleep "$DODTIME" if running $name; then kill -KILL $pid - [ -n "$DODTIME" ] && sleep "$DODTIME"s + [ -n "$DODTIME" ] && sleep "$DODTIME" if running $name; then echo "Cannot kill $name (pid=$pid)!" exit 1 @@ -157,7 +157,7 @@ load_module() { echo "For instructions, read" echo "/usr/share/doc/openvswitch-datapath-source/README.Debian" fi - exit 1 + exit 0 fi } @@ -191,30 +191,61 @@ unload_modules() { done fi unload_module openvswitch_mod - unload_module ip_gre_mod +} + +set_system_info() { + ovs_version=`ovs-vswitchd --version | sed 's/.*) //;1q'` + ovs-vsctl --no-wait --timeout=5 set Open_vSwitch . \ + ovs-version="$ovs_version" + + if (lsb_release --id) >/dev/null 2>&1; then + system_type=`lsb_release --id -s` + system_release=`lsb_release --release -s` + system_codename=`lsb_release --codename -s` + system_version="${system_release}-${system_codename}" + + ovs-vsctl --no-wait --timeout=5 set Open_vSwitch . \ + system-type="$system_type" \ + system-version="$system_version" + fi } case "$1" in start) + conf_file=/etc/openvswitch/conf.db + schema_file=/usr/share/openvswitch/vswitch.ovsschema + schema_ver=`ovsdb-tool schema-version "$schema_file"` + load_module openvswitch_mod - unload_module ip_gre - load_module ip_gre_mod if test -n "$CORE_LIMIT"; then check_op "Setting core limit to $CORE_LIMIT" ulimit -c "$CORE_LIMIT" fi # Create an empty configuration database if it doesn't exist. - if test ! -e /etc/openvswitch-switch/conf; then + if test ! -e $conf_file; then # Create configuration database. - ovsdb-tool -vANY:console:emer \ - create /etc/openvswitch-switch/conf \ - /usr/share/openvswitch/vswitch.ovsschema - else + ovsdb-tool -vANY:console:emer create $conf_file $schema_file + elif test "X`ovsdb-tool needs-conversion $conf_file $schema_file`" != Xno; then + # Back up the old version. + version=`ovsdb-tool db-version "$conf_file"` + cksum=`ovsdb-tool db-cksum "$conf_file" | awk '{print $1}'` + cp "$conf_file" "$conf_file.backup$version-$cksum" + + # Compact database. This is important if the old schema did not + # enable garbage collection (i.e. if it did not have any tables + # with "isRoot": true) but the new schema does. In that situation + # the old database may contain a transaction that creates a record + # followed by a transaction that creates the first use of the + # record. Replaying that series of transactions against the new + # database schema (as "convert" does) would cause the record to be + # dropped by the first transaction, then the second transaction + # would cause a referential integrity failure (for a strong + # reference). + ovsdb-tool -vANY:console:emer compact $conf_file + # Upgrade or downgrade schema and compact database. - ovsdb-tool -vANY:console:emer \ - convert /etc/openvswitch-switch/conf \ - /usr/share/openvswitch/vswitch.ovsschema + ovsdb-tool -vANY:console:emer convert $conf_file $schema_file fi if test "$ENABLE_MONITOR" = y; then @@ -223,16 +254,34 @@ case "$1" in monitor_opt= fi + if [ ! -d /var/run/openvswitch ]; then + install -d -m 755 -o root -g root /var/run/openvswitch + fi + + if [ ! -d /var/log/openvswitch ]; then + install -d -m 755 -o root -g root /var/log/openvswitch + fi + + if [ ! -d /var/log/openvswitch/cores ]; then + install -d -m 755 -o root -g root /var/log/openvswitch/cores + fi + # Start ovsdb-server. set -- + set -- "$@" $conf_file set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err - set -- "$@" --log-file - set -- "$@" --detach --pidfile $monitor_opt - set -- "$@" --remote punix:/var/run/ovsdb-server - set -- "$@" /etc/openvswitch-switch/conf + set -- "$@" --log-file=/var/log/openvswitch/ovsdb-server.log + set -- "$@" --detach --no-chdir --pidfile $monitor_opt + set -- "$@" --remote punix:/var/run/openvswitch/db.sock + set -- "$@" --remote db:Open_vSwitch,manager_options + set -- "$@" --private-key=db:SSL,private_key + set -- "$@" --certificate=db:SSL,certificate + set -- "$@" --bootstrap-ca-cert=db:SSL,ca_cert set -- "$@" $OVSDB_SERVER_OPTS echo -n "Starting ovsdb-server: " - start-stop-daemon --start --quiet --pidfile /var/run/ovsdb-server.pid \ + start-stop-daemon --start --quiet --oknodo \ + --pidfile /var/run/openvswitch/ovsdb-server.pid \ + --chdir /var/log/openvswitch/cores \ --exec $ovsdb_server -- "$@" if running ovsdb-server; then echo "ovsdb-server." @@ -240,17 +289,21 @@ case "$1" in echo " ERROR." fi - ovs-vsctl --no-wait init + ovs-vsctl --no-wait --timeout=5 init -- set Open_vSwitch . db-version="$schema_ver" + + set_system_info # Start ovs-vswitchd. set -- set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err - set -- "$@" --log-file - set -- "$@" --detach --pidfile $monitor_opt - set -- "$@" unix:/var/run/ovsdb-server + set -- "$@" --log-file=/var/log/openvswitch/ovs-vswitchd.log + set -- "$@" --detach --no-chdir --pidfile $monitor_opt + set -- "$@" unix:/var/run/openvswitch/db.sock set -- "$@" $OVS_VSWITCHD_OPTS echo -n "Starting ovs-vswitchd: " - start-stop-daemon --start --quiet --pidfile /var/run/ovs-vswitchd.pid \ + start-stop-daemon --start --quiet --oknodo \ + --pidfile /var/run/openvswitch/ovs-vswitchd.pid \ + --chdir /var/log/openvswitch/cores \ --exec $ovs_vswitchd -- "$@" if running ovs-vswitchd; then echo "ovs-vswitchd." @@ -260,14 +313,16 @@ case "$1" in ;; stop) echo -n "Stopping ovs-vswitchd: " - start-stop-daemon --stop --quiet --oknodo \ - --pidfile /var/run/ovs-vswitchd.pid \ + start-stop-daemon --stop --quiet --oknodo --retry 5 \ + --pidfile /var/run/openvswitch/ovs-vswitchd.pid \ + --chdir /var/log/openvswitch/cores \ --exec $ovs_vswitchd echo "ovs-vswitchd." echo -n "Stopping ovsdb-server: " - start-stop-daemon --stop --quiet --oknodo \ - --pidfile /var/run/ovsdb-server.pid \ + start-stop-daemon --stop --quiet --oknodo --retry 5 \ + --pidfile /var/run/openvswitch/ovsdb-server.pid \ + --chdir /var/log/openvswitch/cores \ --exec $ovsdb_server echo "ovsdb-server." ;; @@ -308,13 +363,13 @@ case "$1" in if running $daemon; then echo "running" else - echo " not running." + echo "not running." exit 1 fi done ;; *) - N=/etc/init.d/$NAME + N=/etc/init.d/openvswitch-switch echo "Usage: $N {start|stop|restart|force-reload|status|force-stop|unload}" >&2 exit 1 ;;