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
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
36 default=/etc/default/openvswitch-switch
37 if [ -f $default ] ; then
43 # running_pid pid name
45 # Check if 'pid' is a process named 'name'
49 [ -z "$pid" ] && return 1
50 [ ! -d /proc/$pid ] && return 1
51 cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
52 # Is this the expected child?
65 # Checks for a running process named 'name' by looking for a pidfile
66 # named /var/run/${name}.pid
70 local pidfile=/var/run/${name}.pid
72 # No pidfile, probably no daemon present
73 [ ! -f "$pidfile" ] && return 1
75 # Obtain the pid and check it against the binary name
77 running_pid $pid $name || return 1
83 # Checks for a running process named 'name', by looking for a pidfile
84 # named /var/run/${name}.pid, and then kills it and waits for it to
88 local pidfile=/var/run/${name}.pid
90 [ ! -f "$pidfile" ] && return
91 if running $name; then
93 [ -n "$DODTIME" ] && sleep "$DODTIME"s
94 if running $name; then
96 [ -n "$DODTIME" ] && sleep "$DODTIME"s
97 if running $name; then
98 echo "Cannot kill $name (pid=$pid)!"
128 # is_module_loaded module
130 # Returns 0 if 'module' is loaded, 1 otherwise.
134 grep -q "^$module " /proc/modules
139 # Loads 'module' into the running kernel, if it is not already loaded.
142 echo -n "Loading $module: "
143 if is_module_loaded $module; then
144 echo "already loaded, nothing to do."
145 elif modprobe $module; then
149 echo "$module has probably not been built for this kernel."
150 if ! test -d /usr/share/doc/openvswitch-datapath-source; then
151 echo "Install the openvswitch-datapath-source package, then read"
152 echo "/usr/share/doc/openvswitch-datapath-source/README.Debian"
154 echo "For instructions, read"
155 echo "/usr/share/doc/openvswitch-datapath-source/README.Debian"
161 # unload_module module
163 # Unloads 'module' from the running kernel, if it is loaded.
166 echo -n "Unloading $module: "
167 if is_module_loaded $module; then
168 if rmmod $module; then
175 echo "not loaded, nothing to do."
180 if is_module_loaded openvswitch_mod; then
181 for dp in $(ovs-dpctl dump-dps); do
182 echo -n "Deleting datapath $dp: "
183 if ovs-dpctl del-dp $dp; then
190 unload_module openvswitch_mod
191 unload_module ip_gre_mod
196 load_module openvswitch_mod
198 load_module ip_gre_mod
200 if test -n "$CORE_LIMIT"; then
201 check_op "Setting core limit to $CORE_LIMIT" ulimit -c "$CORE_LIMIT"
204 # Start ovsdb-server.
206 set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err
207 set -- "$@" --log-file
208 set -- "$@" --detach --pidfile
209 set -- "$@" --remote punix:/var/run/ovsdb-server
210 set -- "$@" /etc/openvswitch-switch/conf
211 set -- "$@" $OVSDB_SERVER_OPTS
212 echo -n "Starting ovsdb-server: "
213 start-stop-daemon --start --quiet --pidfile /var/run/ovsdb-server.pid \
214 --exec $ovsdb_server -- "$@"
215 if running ovsdb-server; then
221 # Start ovs-vswitchd.
223 set -- "$@" --verbose=ANY:console:emer --verbose=ANY:syslog:err
224 set -- "$@" --log-file
225 set -- "$@" --detach --pidfile
226 set -- "$@" unix:/var/run/ovsdb-server
227 set -- "$@" $OVS_VSWITCHD_OPTS
228 echo -n "Starting ovs-vswitchd: "
229 start-stop-daemon --start --quiet --pidfile /var/run/ovs-vswitchd.pid \
230 --exec $ovs_vswitchd -- "$@"
231 if running ovs-vswitchd; then
238 echo -n "Stopping ovs-vswitchd: "
239 start-stop-daemon --stop --quiet --oknodo \
240 --pidfile /var/run/ovs-vswitchd.pid \
244 echo -n "Stopping ovsdb-server: "
245 start-stop-daemon --stop --quiet --oknodo \
246 --pidfile /var/run/ovsdb-server.pid \
251 echo -n "Forcefully stopping ovs-vswitchd: "
252 force_stop ovs-vswitchd
253 if ! running ovs-vswitchd; then
259 echo -n "Forcefully stopping ovsdb-server: "
260 force_stop ovsdb-server
261 if ! running ovsdb-server; then
273 # Nothing to do, since ovs-vswitchd automatically reloads
274 # whenever its configuration changes, and ovsdb-server doesn't
275 # have anything to reload.
282 for daemon in ovs-vswitchd ovsdb-server; do
283 echo -n "$daemon is "
284 if running $daemon; then
294 echo "Usage: $N {start|stop|restart|force-reload|status|force-stop|unload}" >&2