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 openvswitch-switch 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"
97 if running $name; then
99 [ -n "$DODTIME" ] && sleep "$DODTIME"
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 conf_file=/etc/openvswitch/conf.db
199 schema_file=/usr/share/openvswitch/vswitch.ovsschema
200 schema_ver=`ovsdb-tool schema-version "$schema_file"`
202 load_module openvswitch_mod
204 if test -n "$CORE_LIMIT"; then
205 check_op "Setting core limit to $CORE_LIMIT" ulimit -c "$CORE_LIMIT"
208 # Create an empty configuration database if it doesn't exist.
209 if test ! -e $conf_file; then
210 # Create configuration database.
211 ovsdb-tool -vANY:console:emer create $conf_file $schema_file
213 # If schema version changed, then back up the old version.
214 old_ver=`ovsdb-tool db-version "$conf_file"`
215 if test "X$old_ver" != "X$schema_ver"; then
216 cp "$conf_file" "$conf_file.backup$old_ver"
219 # Upgrade or downgrade schema and compact database.
220 ovsdb-tool -vANY:console:emer convert $conf_file $schema_file
223 if test "$ENABLE_MONITOR" = y; then
224 monitor_opt=--monitor
229 if [ ! -d /var/run/openvswitch ]; then
230 install -d -m 755 -o root -g root /var/run/openvswitch
233 if [ ! -d /var/log/openvswitch ]; then
234 install -d -m 755 -o root -g root /var/log/openvswitch
237 if [ ! -d /var/log/openvswitch/cores ]; then
238 install -d -m 755 -o root -g root /var/log/openvswitch/cores
241 # Start ovsdb-server.
243 set -- "$@" $conf_file
244 set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err
245 set -- "$@" --log-file=/var/log/openvswitch/ovsdb-server.log
246 set -- "$@" --detach --no-chdir --pidfile $monitor_opt
247 set -- "$@" --remote punix:/var/run/openvswitch/db.sock
248 set -- "$@" --remote db:Open_vSwitch,managers
249 set -- "$@" --remote db:Open_vSwitch,manager_options
250 set -- "$@" --private-key=db:SSL,private_key
251 set -- "$@" --certificate=db:SSL,certificate
252 set -- "$@" --bootstrap-ca-cert=db:SSL,ca_cert
253 set -- "$@" $OVSDB_SERVER_OPTS
254 echo -n "Starting ovsdb-server: "
255 start-stop-daemon --start --quiet --oknodo \
256 --pidfile /var/run/openvswitch/ovsdb-server.pid \
257 --chdir /var/log/openvswitch/cores \
258 --exec $ovsdb_server -- "$@"
259 if running ovsdb-server; then
265 ovs-vsctl --no-wait --timeout=5 init -- set Open_vSwitch . db-version="$schema_ver"
267 # Start ovs-vswitchd.
269 set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err
270 set -- "$@" --log-file=/var/log/openvswitch/ovs-vswitchd.log
271 set -- "$@" --detach --no-chdir --pidfile $monitor_opt
272 set -- "$@" unix:/var/run/openvswitch/db.sock
273 set -- "$@" $OVS_VSWITCHD_OPTS
274 echo -n "Starting ovs-vswitchd: "
275 start-stop-daemon --start --quiet --oknodo \
276 --pidfile /var/run/openvswitch/ovs-vswitchd.pid \
277 --chdir /var/log/openvswitch/cores \
278 --exec $ovs_vswitchd -- "$@"
279 if running ovs-vswitchd; then
286 echo -n "Stopping ovs-vswitchd: "
287 start-stop-daemon --stop --quiet --oknodo --retry 5 \
288 --pidfile /var/run/openvswitch/ovs-vswitchd.pid \
289 --chdir /var/log/openvswitch/cores \
293 echo -n "Stopping ovsdb-server: "
294 start-stop-daemon --stop --quiet --oknodo --retry 5 \
295 --pidfile /var/run/openvswitch/ovsdb-server.pid \
296 --chdir /var/log/openvswitch/cores \
301 echo -n "Forcefully stopping ovs-vswitchd: "
302 force_stop ovs-vswitchd
303 if ! running ovs-vswitchd; then
309 echo -n "Forcefully stopping ovsdb-server: "
310 force_stop ovsdb-server
311 if ! running ovsdb-server; then
323 # Nothing to do, since ovs-vswitchd automatically reloads
324 # whenever its configuration changes, and ovsdb-server doesn't
325 # have anything to reload.
332 for daemon in ovs-vswitchd ovsdb-server; do
333 echo -n "$daemon is "
334 if running $daemon; then
343 N=/etc/init.d/openvswitch-switch
344 echo "Usage: $N {start|stop|restart|force-reload|status|force-stop|unload}" >&2