netdev-dpdk: fix mbuf leaks
[cascardo/ovs.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 restart () {
111     if [ "$1" = "--save-flows=yes" ]; then
112         stop_daemon ovs-xapi-sync
113         start restart
114     else
115         stop
116         start
117     fi
118 }
119
120 case $1 in
121     start)
122         start
123         ;;
124     stop)
125         stop
126         ;;
127     restart)
128         shift
129         restart "$@"
130         ;;
131     reload|force-reload)
132         # The main OVS daemons keep up-to-date, but ovs-xapi-sync needs help.
133         if daemon_is_running ovs-xapi-sync; then
134             action "Configuring Open vSwitch external IDs" \
135                 ovs-appctl -t ovs-xapi-sync flush-cache
136         fi
137         ;;
138     status)
139         ovs_ctl status && daemon_status ovs-xapi-sync
140         ;;
141     version)
142         ovs_ctl version
143         ;;
144     force-reload-kmod)
145         force_reload_kmod
146         ;;
147     help)
148         printf "openvswitch [start|stop|restart|reload|force-reload|status|version]\n"
149         ;;
150     *)
151         printf "Unknown command: $1\n"
152         exit 1
153         ;;
154 esac