summaryrefslogtreecommitdiffstats
path: root/recipes-networking/openvswitch/files
diff options
context:
space:
mode:
authorDavid Nyström <david.nystrom@enea.com>2012-12-06 10:59:57 +0100
committerDavid Nyström <david.nystrom@enea.com>2012-12-07 15:32:31 +0100
commit5ac786971c9e32f77efc4ee88e5a2ed140961bd7 (patch)
tree384d83cccea912b0b88ff47849acf70865d4e449 /recipes-networking/openvswitch/files
parent43c6da9f1b779b856df51c5b0003c6bddd542bb2 (diff)
downloadmeta-virtualization-5ac786971c9e32f77efc4ee88e5a2ed140961bd7.tar.gz
Added openvswitch recipe
Signed-off-by: David Nyström <david.nystrom@enea.com> Reviewed-by: Bruce Ashfield <bruce.ashfield@windriver.com>
Diffstat (limited to 'recipes-networking/openvswitch/files')
-rwxr-xr-xrecipes-networking/openvswitch/files/openvswitch-controller274
-rw-r--r--recipes-networking/openvswitch/files/openvswitch-controller-setup29
-rw-r--r--recipes-networking/openvswitch/files/openvswitch-example102
-rw-r--r--recipes-networking/openvswitch/files/openvswitch-switch102
-rw-r--r--recipes-networking/openvswitch/files/openvswitch-switch-setup8
5 files changed, 515 insertions, 0 deletions
diff --git a/recipes-networking/openvswitch/files/openvswitch-controller b/recipes-networking/openvswitch/files/openvswitch-controller
new file mode 100755
index 00000000..026974a7
--- /dev/null
+++ b/recipes-networking/openvswitch/files/openvswitch-controller
@@ -0,0 +1,274 @@
1#!/bin/sh
2#
3# Copyright (c) 2011 Nicira Networks Inc.
4# Copyright (c) 2007, 2009 Javier Fernandez-Sanguino <jfs@debian.org>
5#
6# This is free software; you may redistribute it and/or modify
7# it under the terms of the GNU General Public License as
8# published by the Free Software Foundation; either version 2,
9# or (at your option) any later version.
10#
11# This is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License with
17# the Debian operating system, in /usr/share/common-licenses/GPL; if
18# not, write to the Free Software Foundation, Inc., 59 Temple Place,
19# Suite 330, Boston, MA 02111-1307 USA
20#
21### BEGIN INIT INFO
22# Provides: openvswitch-controller
23# Required-Start: $network $local_fs $remote_fs
24# Required-Stop: $remote_fs
25# Should-Start: $named
26# Should-Stop:
27# Default-Start: 2 3 4 5
28# Default-Stop: 0 1 6
29# Short-Description: Open vSwitch controller
30### END INIT INFO
31
32PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
33
34DAEMON=/usr/bin/ovs-controller # Introduce the server's location here
35NAME=ovs-controller # Introduce the short server's name here
36DESC=ovs-controller # Introduce a short description here
37LOGDIR=/var/log/openvswitch # Log directory to use
38
39PIDFILE=/var/run/openvswitch/$NAME.pid
40
41test -x $DAEMON || exit 0
42
43. /lib/lsb/init-functions
44
45# Default options, these can be overriden by the information
46# at /etc/default/openvswitch-controller
47DAEMON_OPTS="" # Additional options given to the server
48
49DODTIME=10 # Time to wait for the server to die, in seconds
50 # If this value is set too low you might not
51 # let some servers to die gracefully and
52 # 'restart' will not work
53
54LOGFILE=$LOGDIR/$NAME.log # Server logfile
55#DAEMONUSER= # User to run the daemons as. If this value
56 # is set start-stop-daemon will chuid the server
57
58# Include defaults if available
59default=/etc/default/openvswitch-controller
60if [ -f $default ] ; then
61 . $default
62fi
63
64# Check that the user exists (if we set a user)
65# Does the user exist?
66if [ -n "$DAEMONUSER" ] ; then
67 if getent passwd | grep -q "^$DAEMONUSER:"; then
68 # Obtain the uid and gid
69 DAEMONUID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $3}'`
70 DAEMONGID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $4}'`
71 else
72 log_failure_msg "The user $DAEMONUSER, required to run $NAME does not exist."
73 exit 1
74 fi
75fi
76
77
78set -e
79
80running_pid() {
81# Check if a given process pid's cmdline matches a given name
82 pid=$1
83 name=$2
84 [ -z "$pid" ] && return 1
85 [ ! -d /proc/$pid ] && return 1
86 cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
87 # Is this the expected server
88 [ "$cmd" != "$name" ] && return 1
89 return 0
90}
91
92running() {
93# Check if the process is running looking at /proc
94# (works for all users)
95
96 # No pidfile, probably no daemon present
97 [ ! -f "$PIDFILE" ] && return 1
98 pid=`cat $PIDFILE`
99 running_pid $pid $DAEMON || return 1
100 return 0
101}
102
103start_server() {
104 if [ -z "$LISTEN" ]; then
105 echo "$default: No connection methods configured, controller disabled" >&2
106 exit 0
107 fi
108
109 if [ ! -d /var/run/openvswitch ]; then
110 install -d -m 755 -o root -g root /var/run/openvswitch
111 fi
112
113 SSL_OPTS=
114 case $LISTEN in
115 *ssl*)
116 : ${PRIVKEY:=/etc/openvswitch-controller/privkey.pem}
117 : ${CERT:=/etc/openvswitch-controller/cert.pem}
118 : ${CACERT:=/etc/openvswitch-controller/cacert.pem}
119 if test ! -e "$PRIVKEY" || test ! -e "$CERT" ||
120 test ! -e "$CACERT"; then
121 if test ! -e "$PRIVKEY"; then
122 echo "$PRIVKEY: private key missing" >&2
123 fi
124 if test ! -e "$CERT"; then
125 echo "$CERT: certificate for private key missing" >&2
126 fi
127 if test ! -e "$CACERT"; then
128 echo "$CACERT: CA certificate missing" >&2
129 fi
130 exit 1
131 fi
132 SSL_OPTS="--private-key=$PRIVKEY --certificate=$CERT --ca-cert=$CACERT"
133 ;;
134 esac
135
136# Start the process using the wrapper
137 if [ -z "$DAEMONUSER" ] ; then
138 start-stop-daemon --start --pidfile $PIDFILE \
139 --exec $DAEMON -- --detach --pidfile=$PIDFILE \
140 $LISTEN $DAEMON_OPTS $SSL_OPTS
141 errcode=$?
142 else
143# if we are using a daemonuser then change the user id
144 start-stop-daemon --start --quiet --pidfile $PIDFILE \
145 --chuid $DAEMONUSER --exec $DAEMON -- \
146 --detach --pidfile=$PIDFILE $LISTEN $DAEMON_OPTS \
147 $SSL_OPTS
148 errcode=$?
149 fi
150 return $errcode
151}
152
153stop_server() {
154# Stop the process using the wrapper
155 if [ -z "$DAEMONUSER" ] ; then
156 start-stop-daemon --stop --quiet --pidfile $PIDFILE \
157 --exec $DAEMON
158 errcode=$?
159 else
160# if we are using a daemonuser then look for process that match
161 start-stop-daemon --stop --quiet --pidfile $PIDFILE \
162 --user $DAEMONUSER --exec $DAEMON
163 errcode=$?
164 fi
165
166 return $errcode
167}
168
169reload_server() {
170 [ ! -f "$PIDFILE" ] && return 1
171 pid=`cat $PIDFILE` # This is the daemon's pid
172 # Send a SIGHUP
173 kill -1 $pid
174 return $?
175}
176
177force_stop() {
178# Force the process to die killing it manually
179 [ ! -e "$PIDFILE" ] && return
180 if running ; then
181 kill -15 $pid
182 # Is it really dead?
183 sleep "$DODTIME"
184 if running ; then
185 kill -9 $pid
186 sleep "$DODTIME"
187 if running ; then
188 echo "Cannot kill $NAME (pid=$pid)!"
189 exit 1
190 fi
191 fi
192 fi
193 rm -f $PIDFILE
194}
195
196
197case "$1" in
198 start)
199 log_begin_msg "Starting $DESC " "$NAME"
200 # Check if it's running first
201 if running ; then
202 log_warning_msg "apparently already running"
203 log_end_msg 0
204 exit 0
205 fi
206 if start_server && running ; then
207 # It's ok, the server started and is running
208 log_end_msg 0
209 else
210 # Either we could not start it or it is not running
211 # after we did
212 # NOTE: Some servers might die some time after they start,
213 # this code does not try to detect this and might give
214 # a false positive (use 'status' for that)
215 log_end_msg 1
216 fi
217 ;;
218 stop)
219 log_begin_msg "Stopping $DESC" "$NAME"
220 if running ; then
221 # Only stop the server if we see it running
222 stop_server
223 log_end_msg $?
224 else
225 # If it's not running don't do anything
226 log_warning_msg "apparently not running"
227 log_end_msg 0
228 exit 0
229 fi
230 ;;
231 force-stop)
232 # First try to stop gracefully the program
233 $0 stop
234 if running; then
235 # If it's still running try to kill it more forcefully
236 log_begin_msg "Stopping (force) $DESC" "$NAME"
237 force_stop
238 log_end_msg $?
239 fi
240 ;;
241 restart|force-reload)
242 log_begin_msg "Restarting $DESC" "$NAME"
243 stop_server
244 # Wait some sensible amount, some server need this
245 [ -n "$DODTIME" ] && sleep $DODTIME
246 start_server
247 running
248 log_end_msg $?
249 ;;
250 status)
251
252 log_begin_msg "Checking status of $DESC" "$NAME"
253 if running ; then
254 log_begin_msg "running"
255 log_end_msg 0
256 else
257 log_warning_msg "apparently not running"
258 log_end_msg 1
259 exit 1
260 fi
261 ;;
262 # Use this if the daemon cannot reload
263 reload)
264 log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
265 log_warning_msg "cannot re-read the config file (use restart)."
266 ;;
267 *)
268 N=/etc/init.d/openvswitch-controller
269 echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2
270 exit 1
271 ;;
272esac
273
274exit 0
diff --git a/recipes-networking/openvswitch/files/openvswitch-controller-setup b/recipes-networking/openvswitch/files/openvswitch-controller-setup
new file mode 100644
index 00000000..1d9f9261
--- /dev/null
+++ b/recipes-networking/openvswitch/files/openvswitch-controller-setup
@@ -0,0 +1,29 @@
1# This is a POSIX shell fragment -*- sh -*-
2
3# LISTEN: What OpenFlow connection methods should the controller listen on?
4#
5# This is a space-delimited list of connection methods:
6#
7# * "pssl:[PORT]": Listen for SSL connections on the specified PORT
8# (default: 6633). The private key, certificate, and CA certificate
9# must be specified below.
10#
11# * "pctp:[PORT]": Listen for TCP connections on the specified PORT
12# (default: 6633). Not recommended for security reasons.
13#
14LISTEN="pssl:"
15
16# PRIVKEY: Name of file containing controller's private key.
17# Required if SSL enabled.
18PRIVKEY=/etc/openvswitch-controller/privkey.pem
19
20# CERT: Name of file containing certificate for private key.
21# Required if SSL enabled.
22CERT=/etc/openvswitch-controller/cert.pem
23
24# CACERT: Name of file containing switch CA certificate.
25# Required if SSL enabled.
26CACERT=/etc/openvswitch-controller/cacert.pem
27
28# Additional options to pass to controller, e.g. "--hub"
29DAEMON_OPTS=""
diff --git a/recipes-networking/openvswitch/files/openvswitch-example b/recipes-networking/openvswitch/files/openvswitch-example
new file mode 100644
index 00000000..6f08c3fa
--- /dev/null
+++ b/recipes-networking/openvswitch/files/openvswitch-example
@@ -0,0 +1,102 @@
1#! /bin/sh
2#
3# Copyright (C) 2011 Nicira Networks, Inc.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at:
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17### BEGIN INIT INFO
18# Provides: openvswitch-switch
19# Required-Start: $network $named $remote_fs $syslog
20# Required-Stop: $remote_fs
21# Default-Start: 2 3 4 5
22# Default-Stop: 0 1 6
23# Short-Description: Open vSwitch switch
24### END INIT INFO
25
26(test -x /usr/sbin/ovs-vswitchd && test -x /usr/sbin/ovsdb-server) || exit 0
27
28. /usr/share/openvswitch/scripts/ovs-lib
29test -e /etc/default/openvswitch-switch && . /etc/default/openvswitch-switch
30
31if test X"$BRCOMPAT" = Xyes && test ! -x /usr/sbin/ovs-brcompatd; then
32 BRCOMPAT=no
33 log_warning_msg "ovs-brcompatd missing, disabling bridge compatibility"
34fi
35
36ovs_ctl () {
37 set /usr/share/openvswitch/scripts/ovs-ctl "$@"
38 if test X"$BRCOMPAT" = Xyes; then
39 set "$@" --brcompat
40 fi
41 "$@"
42}
43
44load_kmod () {
45 ovs_ctl load-kmod || exit $?
46}
47
48start () {
49 if ovs_ctl load-kmod; then
50 :
51 else
52 echo "Module has probably not been built for this kernel."
53 if ! test -d /usr/share/doc/openvswitch-datapath-source; then
54 echo "Install the openvswitch-datapath-source package, then read"
55 else
56 echo "For instructions, read"
57 fi
58 echo "/usr/share/doc/openvswitch-datapath-source/README.Debian"
59 fi
60 set ovs_ctl ${1-start} --system-id=random
61 if test X"$FORCE_COREFILES" != X; then
62 set "$@" --force-corefiles="$FORCE_COREFILES"
63 fi
64 "$@" || exit $?
65
66 ovs_ctl --protocol=gre enable-protocol
67}
68
69stop () {
70 ovs_ctl stop
71}
72
73case $1 in
74 start)
75 start
76 ;;
77 stop | force-stop)
78 stop
79 ;;
80 reload | force-reload)
81 # The OVS daemons keep up-to-date.
82 ;;
83 restart)
84 stop
85 start
86 ;;
87 status)
88 ovs_ctl status
89 ;;
90 force-reload-kmod)
91 start force-reload-kmod
92 ;;
93 load-kmod)
94 load_kmod
95 ;;
96 *)
97 echo "Usage: $0 {start|stop|restart|force-reload|status|force-stop|force-reload-kmod|load-kmod}" >&2
98 exit 1
99 ;;
100esac
101
102exit 0
diff --git a/recipes-networking/openvswitch/files/openvswitch-switch b/recipes-networking/openvswitch/files/openvswitch-switch
new file mode 100644
index 00000000..6f08c3fa
--- /dev/null
+++ b/recipes-networking/openvswitch/files/openvswitch-switch
@@ -0,0 +1,102 @@
1#! /bin/sh
2#
3# Copyright (C) 2011 Nicira Networks, Inc.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at:
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17### BEGIN INIT INFO
18# Provides: openvswitch-switch
19# Required-Start: $network $named $remote_fs $syslog
20# Required-Stop: $remote_fs
21# Default-Start: 2 3 4 5
22# Default-Stop: 0 1 6
23# Short-Description: Open vSwitch switch
24### END INIT INFO
25
26(test -x /usr/sbin/ovs-vswitchd && test -x /usr/sbin/ovsdb-server) || exit 0
27
28. /usr/share/openvswitch/scripts/ovs-lib
29test -e /etc/default/openvswitch-switch && . /etc/default/openvswitch-switch
30
31if test X"$BRCOMPAT" = Xyes && test ! -x /usr/sbin/ovs-brcompatd; then
32 BRCOMPAT=no
33 log_warning_msg "ovs-brcompatd missing, disabling bridge compatibility"
34fi
35
36ovs_ctl () {
37 set /usr/share/openvswitch/scripts/ovs-ctl "$@"
38 if test X"$BRCOMPAT" = Xyes; then
39 set "$@" --brcompat
40 fi
41 "$@"
42}
43
44load_kmod () {
45 ovs_ctl load-kmod || exit $?
46}
47
48start () {
49 if ovs_ctl load-kmod; then
50 :
51 else
52 echo "Module has probably not been built for this kernel."
53 if ! test -d /usr/share/doc/openvswitch-datapath-source; then
54 echo "Install the openvswitch-datapath-source package, then read"
55 else
56 echo "For instructions, read"
57 fi
58 echo "/usr/share/doc/openvswitch-datapath-source/README.Debian"
59 fi
60 set ovs_ctl ${1-start} --system-id=random
61 if test X"$FORCE_COREFILES" != X; then
62 set "$@" --force-corefiles="$FORCE_COREFILES"
63 fi
64 "$@" || exit $?
65
66 ovs_ctl --protocol=gre enable-protocol
67}
68
69stop () {
70 ovs_ctl stop
71}
72
73case $1 in
74 start)
75 start
76 ;;
77 stop | force-stop)
78 stop
79 ;;
80 reload | force-reload)
81 # The OVS daemons keep up-to-date.
82 ;;
83 restart)
84 stop
85 start
86 ;;
87 status)
88 ovs_ctl status
89 ;;
90 force-reload-kmod)
91 start force-reload-kmod
92 ;;
93 load-kmod)
94 load_kmod
95 ;;
96 *)
97 echo "Usage: $0 {start|stop|restart|force-reload|status|force-stop|force-reload-kmod|load-kmod}" >&2
98 exit 1
99 ;;
100esac
101
102exit 0
diff --git a/recipes-networking/openvswitch/files/openvswitch-switch-setup b/recipes-networking/openvswitch/files/openvswitch-switch-setup
new file mode 100644
index 00000000..73387fbc
--- /dev/null
+++ b/recipes-networking/openvswitch/files/openvswitch-switch-setup
@@ -0,0 +1,8 @@
1# This is a POSIX shell fragment -*- sh -*-
2
3# FORCE_COREFILES: If 'yes' then core files will be enabled.
4# FORCE_COREFILES=yes
5
6# BRCOMPAT: If 'yes' and the openvswitch-brcompat package is installed, then
7# Linux bridge compatibility will be enabled.
8# BRCOMPAT=yes