I’ve written a simple init script for openvswitch which uses ovs-ctl script. I’ve saved it as /etc/init.d/ovswitch and I’ve configured it to start automatically with chkconfig ovswitch on.
#!/bin/sh
#
# chkconfig: 2345 20 80
# description: ovswitch system startup-script using ovs-ctl
# author: Miguel Angel Alvarez Cabrerizo (n40lab.wordpress.com)
#
### BEGIN INIT INFO
# Provides: openvswitch
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop openvswitch daemons
# Description: Load kernel modules, start and stop openvswitch daemons
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
exec="/usr/local/share/openvswitch/scripts/ovs-ctl"
prog="ovswitch"
# config="<path to major config file>"
# This init script starts ovswitch with bridge compatibility --brcompat
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
lockfile=/var/lock/subsys/$prog
start() {
$exec start --system-id=random --brcompat
retval=$?
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
$exec stop
retval=$?
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
status() {
$exec status
}
case "$1" in
start)
start && exit 0
$1
;;
stop)
stop || exit 0
$1
;;
restart)
$1
;;
status)
status
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 2
esac
exit $?