Merge branch 'forward-port'
[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, 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 || 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_ovs_xapi_sync () {
47     if daemon_is_running ovs-xapi-sync; then
48         log_success_msg "ovs-xapi-sync is already running"
49     else
50         PYTHONPATH=/usr/share/openvswitch/python \
51             /usr/share/openvswitch/scripts/ovs-xapi-sync \
52             --log-file --pidfile --detach --monitor unix:/var/run/openvswitch/db.sock
53     fi
54 }
55
56 start () {
57     set $ovs_ctl ${1-start}
58     set "$@" --system-id="$INSTALLATION_UUID"
59     set "$@" --system-type="$PRODUCT_BRAND"
60     set "$@" --system-version="$PRODUCT_VERSION-$BUILD_NUMBER"
61     set "$@" --external-id=xs-system-uuid="$INSTALLATION_UUID"
62     set "$@" --daemon-cwd=/var/xen/openvswitch
63     if test X"$FORCE_COREFILES" != X; then
64         set "$@" --force-corefiles="$FORCE_COREFILES"
65     fi
66     if test X"$OVSDB_SERVER_PRIORITY" != X; then
67         set "$@" --ovsdb-server-priority="$OVSDB_SERVER_PRIORITY"
68     fi
69     if test X"$VSWITCHD_PRIORITY" != X; then
70         set "$@" --ovs-vswitchd-priority="$VSWITCHD_PRIORITY"
71     fi
72     if test X"$VSWITCHD_MLOCKALL" != X; then
73         set "$@" --mlockall="$VSWITCHD_MLOCKALL"
74     fi
75     if test ! -e /var/run/openvswitch.booted; then
76         touch /var/run/openvswitch.booted
77         set "$@" --delete-bridges
78     fi
79     set "$@" $OVS_CTL_OPTS
80     "$@"
81
82     start_ovs_xapi_sync
83
84     $ovs_ctl --protocol=gre enable-protocol
85
86     touch /var/lock/subsys/openvswitch
87 }
88
89 force_reload_kmod () {
90     start force-reload-kmod
91
92     # Restart the high-availability daemon if it is running.  Otherwise
93     # it loses its heartbeat and reboots the system after a few minutes.
94     if pidof xhad >/dev/null && test -e /etc/xensource/xhad.conf; then
95         PATH=$PATH:/opt/xensource/xha
96         action "Stopping HA daemon" ha_stop_daemon
97         action "Starting HA daemon" ha_start_daemon
98     fi
99
100     action "Stopping ovs-xapi-sync" stop_daemon ovs-xapi-sync
101     action "Starting ovs-xapi-sync" start_ovs_xapi_sync
102 }
103
104 stop () {
105     $ovs_ctl stop
106     stop_daemon ovs-xapi-sync
107     rm -f /var/lock/subsys/openvswitch
108 }
109
110 ovs_ctl=/usr/share/openvswitch/scripts/ovs-ctl
111 case $1 in
112     start)
113         start
114         ;;
115     stop)
116         stop
117         ;;
118     restart)
119         stop
120         start
121         ;;
122     reload|force-reload)
123         # The main OVS daemons keep up-to-date, but ovs-xapi-sync needs help.
124         if daemon_is_running ovs-xapi-sync; then
125             action "Configuring Open vSwitch external IDs" \
126                 ovs-appctl -t ovs-xapi-sync flush-cache
127         fi
128         ;;
129     status)
130         $ovs_ctl status && daemon_status ovs-xapi-sync
131         ;;
132     version)
133         $ovs_ctl version
134         ;;
135     force-reload-kmod)
136         force_reload_kmod
137         ;;
138     help)
139         printf "openvswitch [start|stop|restart|reload|force-reload|status|version]\n"
140         ;;
141     *)
142         printf "Unknown command: $1\n"
143         exit 1
144         ;;
145 esac