blob: c173da0a921c60ade5bb7c8e83f3e3b187aa9553 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
#!/bin/sh
# Start/stop/restart openvswitch.
# To start Open vSwitch automatically at boot, be sure this script is
# executable:
#
# % chmod 755 /etc/rc.d/rc.openvswitch
# Before you can run Open vSwitch daemon, you must have a database. To
# install one, perform the following as root:
#
# % /etc/rc.d/rc.openvswitch clean-database
#
DBCONF=/etc/openvswitch/ovs-vswitchd.conf.db
RUNDIR=/var/run/openvswitch
SOCKET=$RUNDIR/db.sock
VSPID=$RUNDIR/ovs-vswitchd.pid
DBPID=$RUNDIR/ovsdb-server.pid
# Insert kernel driver for Open vSwitch:
/sbin/modprobe openvswitch
# Insert kernel driver for VLANs:
/sbin/modprobe 8021q
# Start openvswitch:
openvswitch_start() {
echo "Starting openvswitch: /etc/rc.d/rc.openvswitch"
mkdir -p $RUNDIR
/usr/sbin/ovsdb-server /etc/openvswitch/ovs-vswitchd.conf.db --remote=punix:$SOCKET \
--detach --pidfile=$DBPID --verbose=ANY:ANY:err
/usr/bin/ovs-vsctl --no-wait --verbose=ANY:ANY:err init
/usr/sbin/ovs-vswitchd unix:$SOCKET --detach --pidfile=$VSPID --verbose=ANY:ANY:err
}
# Stop openvswitch:
openvswitch_stop() {
echo "Stopping openvswitch: /etc/rc.d/rc.openvswitch"
if [ -e $VSPID ]; then
pid=$(cat $VSPID)
/usr/bin/ovs-appctl -t $RUNDIR/ovs-vswitchd.$pid.ctl exit
fi
if [ -e $DBPID ]; then
pid=$(cat $DBPID)
/usr/bin/ovs-appctl -t $RUNDIR/ovsdb-server.$pid.ctl exit
fi
}
# Clean openvswitch:
openvswitch_clean() {
if [ ! -e $DBPID ] && [ ! -e $VSPID ]; then
rm -f $DBCONF
/usr/bin/ovsdb-tool create $DBCONF /usr/share/openvswitch/vswitch.ovsschema
else
echo "Stop openvswitch first!"
fi
}
case "$1" in
'start')
openvswitch_start
;;
'stop')
openvswitch_stop
;;
'restart')
openvswitch_stop
sleep 1
openvswitch_start
;;
'clean-database')
openvswitch_clean
;;
'start-clean')
openvswitch_clean
sleep 1
openvswitch_start
;;
'restart-clean')
openvswitch_stop
sleep 1
openvswitch_clean
sleep 1
openvswitch_start
;;
*)
echo "Usage $0 start|stop|restart|clean-database|start-clean|restart-clean"
esac
|