3 # /etc/init.d/openvswitch-switch
5 # Written by Miquel van Smoorenburg <miquels@cistron.nl>.
6 # Modified for Debian by Ian Murdock <imurdock@gnu.ai.mit.edu>.
7 # Further changes by Javier Fernandez-Sanguino <jfs@debian.org>
8 # Modified for openvswitch-switch.
10 # Version: @(#)skeleton 1.9 26-Feb-2001 miquels@cistron.nl
13 # Provides: openvswitch-switch
14 # Required-Start: $network $named $remote_fs $syslog
15 # Required-Stop: $remote_fs
16 # Default-Start: 2 3 4 5
18 # Short-Description: Open vSwitch switch
21 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
22 ovs_vswitchd=/usr/sbin/ovs-vswitchd
23 ovsdb_server=/usr/bin/ovsdb-server
25 (test -x $ovsdb_server && test -x $ovs_vswitchd) || exit 0
27 DODTIME=1 # Time to wait for the server to die, in seconds
28 # If this value is set too low you might not
29 # let some servers to die gracefully and
30 # 'restart' will not work
32 # Include ovs-openflowd defaults if available
33 unset OVSDB_SERVER_OPTS
34 unset OVS_VSWITCHD_OPTS
37 default=/etc/default/openvswitch-switch
38 if [ -f $default ] ; then
42 : ${ENABLE_MONITOR:=y}
46 # running_pid pid name
48 # Check if 'pid' is a process named 'name'
52 [ -z "$pid" ] && return 1
53 [ ! -d /proc/$pid ] && return 1
54 cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
55 # Is this the expected child?
68 # Checks for a running process named 'name' by looking for a pidfile
69 # named /var/run/openvswitch/${name}.pid
73 local pidfile=/var/run/openvswitch/${name}.pid
75 # No pidfile, probably no daemon present
76 [ ! -f "$pidfile" ] && return 1
78 # Obtain the pid and check it against the binary name
80 running_pid $pid $name || return 1
86 # Checks for a running process named 'name', by looking for a pidfile
87 # named /var/run/openvswitch/${name}.pid, and then kills it and waits
91 local pidfile=/var/run/openvswitch/${name}.pid
93 [ ! -f "$pidfile" ] && return
94 if running $name; then
96 [ -n "$DODTIME" ] && sleep "$DODTIME"s
97 if running $name; then
99 [ -n "$DODTIME" ] && sleep "$DODTIME"s
100 if running $name; then
101 echo "Cannot kill $name (pid=$pid)!"
131 # is_module_loaded module
133 # Returns 0 if 'module' is loaded, 1 otherwise.
137 grep -q "^$module " /proc/modules
142 # Loads 'module' into the running kernel, if it is not already loaded.
145 echo -n "Loading $module: "
146 if is_module_loaded $module; then
147 echo "already loaded, nothing to do."
148 elif modprobe $module; then
152 echo "$module has probably not been built for this kernel."
153 if ! test -d /usr/share/doc/openvswitch-datapath-source; then
154 echo "Install the openvswitch-datapath-source package, then read"
155 echo "/usr/share/doc/openvswitch-datapath-source/README.Debian"
157 echo "For instructions, read"
158 echo "/usr/share/doc/openvswitch-datapath-source/README.Debian"
164 # unload_module module
166 # Unloads 'module' from the running kernel, if it is loaded.
169 echo -n "Unloading $module: "
170 if is_module_loaded $module; then
171 if rmmod $module; then
178 echo "not loaded, nothing to do."
183 if is_module_loaded openvswitch_mod; then
184 for dp in $(ovs-dpctl dump-dps); do
185 echo -n "Deleting datapath $dp: "
186 if ovs-dpctl del-dp $dp; then
193 unload_module openvswitch_mod
198 load_module openvswitch_mod
200 if test -n "$CORE_LIMIT"; then
201 check_op "Setting core limit to $CORE_LIMIT" ulimit -c "$CORE_LIMIT"
204 # Create an empty configuration database if it doesn't exist.
205 if test ! -e /etc/openvswitch/conf.db; then
206 install -d -m 755 -o root -g root /etc/openvswitch
208 # Create configuration database.
209 ovsdb-tool -vANY:console:emer \
210 create /etc/openvswitch/conf.db \
211 /usr/share/openvswitch/vswitch.ovsschema
213 # Upgrade or downgrade schema and compact database.
214 ovsdb-tool -vANY:console:emer \
215 convert /etc/openvswitch/conf.db \
216 /usr/share/openvswitch/vswitch.ovsschema
219 if test "$ENABLE_MONITOR" = y; then
220 monitor_opt=--monitor
225 if [ ! -d /var/run/openvswitch ]; then
226 install -d -m 755 -o root -g root /var/run/openvswitch
229 if [ ! -d /var/log/openvswitch ]; then
230 install -d -m 755 -o root -g root /var/log/openvswitch
233 # Start ovsdb-server.
235 set -- "$@" /etc/openvswitch/conf.db
236 set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err
237 set -- "$@" --log-file=/var/log/openvswitch/ovsdb-server.log
238 set -- "$@" --detach --pidfile $monitor_opt
239 set -- "$@" --remote punix:/var/run/openvswitch/db.sock
240 set -- "$@" --remote db:Open_vSwitch,managers
241 set -- "$@" --private-key=db:SSL,private_key
242 set -- "$@" --certificate=db:SSL,certificate
243 set -- "$@" --bootstrap-ca-cert=db:SSL,ca_cert
244 set -- "$@" $OVSDB_SERVER_OPTS
245 echo -n "Starting ovsdb-server: "
246 start-stop-daemon --start --quiet \
247 --pidfile /var/run/openvswitch/ovsdb-server.pid \
248 --exec $ovsdb_server -- "$@"
249 if running ovsdb-server; then
255 ovs-vsctl --no-wait init
257 # Start ovs-vswitchd.
259 set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err
260 set -- "$@" --log-file=/var/log/openvswitch/ovs-vswitchd.log
261 set -- "$@" --detach --pidfile $monitor_opt
262 set -- "$@" unix:/var/run/openvswitch/db.sock
263 set -- "$@" $OVS_VSWITCHD_OPTS
264 echo -n "Starting ovs-vswitchd: "
265 start-stop-daemon --start --quiet \
266 --pidfile /var/run/openvswitch/ovs-vswitchd.pid \
267 --exec $ovs_vswitchd -- "$@"
268 if running ovs-vswitchd; then
275 echo -n "Stopping ovs-vswitchd: "
276 start-stop-daemon --stop --quiet --oknodo \
277 --pidfile /var/run/openvswitch/ovs-vswitchd.pid \
281 echo -n "Stopping ovsdb-server: "
282 start-stop-daemon --stop --quiet --oknodo \
283 --pidfile /var/run/openvswitch/ovsdb-server.pid \
288 echo -n "Forcefully stopping ovs-vswitchd: "
289 force_stop ovs-vswitchd
290 if ! running ovs-vswitchd; then
296 echo -n "Forcefully stopping ovsdb-server: "
297 force_stop ovsdb-server
298 if ! running ovsdb-server; then
310 # Nothing to do, since ovs-vswitchd automatically reloads
311 # whenever its configuration changes, and ovsdb-server doesn't
312 # have anything to reload.
319 for daemon in ovs-vswitchd ovsdb-server; do
320 echo -n "$daemon is "
321 if running $daemon; then
331 echo "Usage: $N {start|stop|restart|force-reload|status|force-stop|unload}" >&2