xenserver: Fix typo in comment in XAPI plugin.
[sliver-openvswitch.git] / xenserver / etc_init.d_openvswitch
1 #!/bin/sh
2 #
3 # openvswitch
4 #
5 # chkconfig: 2345 09 91
6 # description: Manage Open vSwitch kernel modules and user-space daemons
7
8 # Copyright (C) 2009, 2010, 2011 Nicira Networks, Inc.
9 #
10 # Licensed under the Apache License, Version 2.0 (the "License");
11 # you may not use this file except in compliance with the License.
12 # You may obtain a copy of the License at:
13 #
14 #     http://www.apache.org/licenses/LICENSE-2.0
15 #
16 # Unless required by applicable law or agreed to in writing, software
17 # distributed under the License is distributed on an "AS IS" BASIS,
18 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 # See the License for the specific language governing permissions and
20 # limitations under the License.
21 ### BEGIN INIT INFO
22 # Provides:          openvswitch-switch
23 # Required-Start:
24 # Required-Stop:
25 # Default-Start:     2 3 4 5
26 # Default-Stop:      0 1 6
27 # Short-Description: Open vSwitch switch
28 ### END INIT INFO
29
30 . /usr/share/openvswitch/scripts/ovs-lib.sh || exit 1
31 . /etc/xensource-inventory
32 test -e /etc/sysconfig/openvswitch && . /etc/sysconfig/openvswitch
33
34 case `cat /etc/xensource/network.conf` in
35     vswitch|openvswitch)
36         ;;
37     bridge)
38         exit 0
39         ;;
40     *)
41         echo "Open vSwitch disabled (/etc/xensource/network.conf is invalid)" >&2
42         exit 0
43         ;;
44 esac
45
46 start () {
47     set $ovs_ctl ${1-start}
48     set "$@" --system-id="$INSTALLATION_UUID"
49     set "$@" --system-type="$PRODUCT_BRAND"
50     set "$@" --system-version="$PRODUCT_VERSION-$BUILD_NUMBER"
51     set "$@" --external-id=xs-system-uuid="$INSTALLATION_UUID"
52     set "$@" --daemon-cwd=/var/xen/openvswitch
53     if test X"$FORCE_COREFILES" != X; then
54         set "$@" --force-corefiles="$FORCE_COREFILES"
55     fi
56     if test X"$OVSDB_SERVER_PRIORITY" != X; then
57         set "$@" --ovsdb-server-priority="$OVSDB_SERVER_PRIORITY"
58     fi
59     if test X"$VSWITCHD_PRIORITY" != X; then
60         set "$@" --ovs-vswitchd-priority="$VSWITCHD_PRIORITY"
61     fi
62     if test X"$VSWITCHD_MLOCKALL" != X; then
63         set "$@" --mlockall="$VSWITCHD_MLOCKALL"
64     fi
65     if test ! -e /var/run/openvswitch.booted; then
66         touch /var/run/openvswitch.booted
67         set "$@" --delete-bridges
68     fi
69     "$@"
70
71     if daemon_is_running ovs-xapi-sync; then
72         log_success_msg "ovs-xapi-sync is already running"
73     else
74         PYTHONPATH=/usr/share/openvswitch/python \
75             /usr/share/openvswitch/scripts/ovs-xapi-sync \
76             --pidfile --detach --monitor unix:/var/run/openvswitch/db.sock
77     fi
78
79     $ovs_ctl --protocol=gre enable-protocol
80
81     touch /var/lock/subsys/openvswitch
82 }
83
84 force_reload_kmod () {
85     start force-reload-kmod
86
87     # Restart the high-availability daemon if it is running.  Otherwise
88     # it loses its heartbeat and reboots the system after a few minutes.
89     if pidof xhad >/dev/null && test -e /etc/xensource/xhad.conf; then
90         PATH=$PATH:/opt/xensource/xha
91         action "Stopping HA daemon" ha_stop_daemon
92         action "Starting HA daemon" ha_start_daemon
93     fi
94 }
95
96 stop () {
97     $ovs_ctl stop
98     stop_daemon ovs-xapi-sync
99     rm -f /var/lock/subsys/openvswitch
100 }
101
102 ovs_ctl=/usr/share/openvswitch/scripts/ovs-ctl
103 case $1 in
104     start)
105         start
106         ;;
107     stop)
108         stop
109         ;;
110     restart)
111         stop
112         start
113         ;;
114     reload|force-reload)
115         # The main OVS daemons keep up-to-date, but ovs-xapi-sync needs help.
116         pidfile=/var/run/openvswitch/ovs-xapi-sync.pid
117         if test -e "$pidfile"; then
118             pid=`cat "$pidfile"`
119             action "Configuring Open vSwitch external IDs" kill -HUP $pid
120         fi
121         ;;
122     status)
123         $ovs_ctl status && daemon_status ovs-xapi-sync
124         ;;
125     version)
126         $ovs_ctl version
127         ;;
128     force-reload-kmod)
129         force_reload_kmod
130         ;;
131     help)
132         printf "openvswitch [start|stop|restart|reload|force-reload|status|version]\n"
133         ;;
134     *)
135         printf "Unknown command: $1\n"
136         exit 1
137         ;;
138 esac