xenserver: Modify init scripts to use new configuration database
[openvswitch] / xenserver / vswitch-xen.spec
1 # Spec file for vswitch and related programs.
2
3 # Copyright (C) 2009 Nicira Networks, Inc.
4 #
5 # Copying and distribution of this file, with or without modification,
6 # are permitted in any medium without royalty provided the copyright
7 # notice and this notice are preserved.  This file is offered as-is,
8 # without warranty of any kind.
9
10 # When building, the rpmbuild command line should define
11 # vswitch_version, xen_version, and build_number using -D arguments.
12 # for example:
13 #
14 #    rpmbuild -D "vswitch_version 0.8.9~1+build123" -D "xen_version 2.6.18-128.1.1.el5.xs5.1.0.483.1000xen" -D "build_number --with-build-number=123" -bb /usr/src/redhat/SPECS/vswitch-xen.spec
15 #
16 %define version %{vswitch_version}-%{xen_version}
17
18 Name: vswitch
19 Summary: Virtual switch
20 Group: System Environment/Daemons
21 URL: http://www.openvswitch.org/
22 Version: %{vswitch_version}
23
24 # The entire source code is ASL 2.0 except datapath/ which is GPLv2
25 License: ASL 2.0 and GPLv2
26 Release: 1
27 Source: openvswitch-%{vswitch_version}.tar.gz
28 Buildroot: /tmp/vswitch-xen-rpm
29 Requires: kernel-xen = %(echo '%{xen_version}' | sed 's/xen$//')
30 # The following Conflicts prevents the "vswitch" package generated by
31 # this spec file from installing at the same time as the "openvswitch"
32 # package shipped with XenServer 5.5.900.  In fact, the packages
33 # contain some files with identical names anyhow, so they will not
34 # coexist, but adding an explicit Conflicts makes this conflict more
35 # obvious.
36 Conflicts: openvswitch
37
38 %description
39 The vswitch provides standard network bridging functions augmented with
40 support for the OpenFlow protocol for remote per-flow control of
41 traffic.
42
43 %prep
44 %setup -q -n openvswitch-%{vswitch_version}
45
46 %build
47 ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=%{_localstatedir} --with-l26=/lib/modules/%{xen_version}/build --enable-ssl %{build_number}
48 make %{_smp_mflags}
49
50 %install
51 rm -rf $RPM_BUILD_ROOT
52 make install DESTDIR=$RPM_BUILD_ROOT
53 install -d -m 755 $RPM_BUILD_ROOT/etc
54 install -d -m 755 $RPM_BUILD_ROOT/etc/init.d
55 install -m 755 xenserver/etc_init.d_vswitch \
56          $RPM_BUILD_ROOT/etc/init.d/vswitch
57 install -m 755 xenserver/etc_init.d_vswitch-xapi-update \
58          $RPM_BUILD_ROOT/etc/init.d/vswitch-xapi-update
59 install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig
60 install -d -m 755 $RPM_BUILD_ROOT/etc/logrotate.d
61 install -m 755 xenserver/etc_logrotate.d_vswitch \
62          $RPM_BUILD_ROOT/etc/logrotate.d/vswitch
63 install -d -m 755 $RPM_BUILD_ROOT/etc/profile.d
64 install -m 755 xenserver/etc_profile.d_vswitch.sh \
65          $RPM_BUILD_ROOT/etc/profile.d/vswitch.sh
66 install -d -m 755 $RPM_BUILD_ROOT/etc/xapi.d/plugins
67 install -m 755 xenserver/etc_xapi.d_plugins_vswitch-cfg-update \
68          $RPM_BUILD_ROOT/etc/xapi.d/plugins/vswitch-cfg-update
69 install -d -m 755 $RPM_BUILD_ROOT/usr/share/vswitch/scripts
70 install -m 644 vswitchd/vswitch-idl.ovsschema \
71          $RPM_BUILD_ROOT/usr/share/vswitch/vswitch-idl.ovsschema
72 install -m 755 xenserver/opt_xensource_libexec_interface-reconfigure \
73              $RPM_BUILD_ROOT/usr/share/vswitch/scripts/interface-reconfigure
74 install -m 755 xenserver/etc_xensource_scripts_vif \
75              $RPM_BUILD_ROOT/usr/share/vswitch/scripts/vif
76 install -m 755 xenserver/usr_share_vswitch_scripts_dump-vif-details \
77                $RPM_BUILD_ROOT/usr/share/vswitch/scripts/dump-vif-details
78 install -m 755 xenserver/usr_share_vswitch_scripts_refresh-xs-network-uuids \
79                $RPM_BUILD_ROOT/usr/share/vswitch/scripts/refresh-xs-network-uuids
80 install -m 755 xenserver/usr_sbin_xen-bugtool \
81              $RPM_BUILD_ROOT/usr/share/vswitch/scripts/xen-bugtool
82 install -m 755 xenserver/usr_sbin_brctl \
83              $RPM_BUILD_ROOT/usr/share/vswitch/scripts/brctl
84 install -m 755 xenserver/usr_share_vswitch_scripts_sysconfig.template \
85          $RPM_BUILD_ROOT/usr/share/vswitch/scripts/sysconfig.template
86 install -m 644 \
87         xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
88                $RPM_BUILD_ROOT/usr/share/vswitch/scripts/XSFeatureVSwitch.py
89
90 install -d -m 755 $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/net/vswitch
91 find datapath/linux-2.6 -name *.ko -exec install -m 755  \{\} $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/net/vswitch \;
92
93 # Get rid of stuff we don't want to make RPM happy.
94 rm \
95     $RPM_BUILD_ROOT/usr/bin/ovs-controller \
96     $RPM_BUILD_ROOT/usr/bin/ovs-discover \
97     $RPM_BUILD_ROOT/usr/bin/ovs-kill \
98     $RPM_BUILD_ROOT/usr/bin/ovs-openflowd \
99     $RPM_BUILD_ROOT/usr/bin/ovs-pki \
100     $RPM_BUILD_ROOT/usr/bin/ovs-wdt \
101     $RPM_BUILD_ROOT/usr/sbin/ovs-monitor \
102     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-controller.8 \
103     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-discover.8 \
104     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-kill.8 \
105     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-openflowd.8 \
106     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-pki.8
107 rm -f $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/net/vswitch/veth_mod.ko
108 rm -r \
109     $RPM_BUILD_ROOT/usr/share/openvswitch/commands
110
111 install -d -m 755 $RPM_BUILD_ROOT/var/lib/openvswitch
112
113 %clean
114 rm -rf $RPM_BUILD_ROOT
115
116 %post
117 if [ ! -f /etc/xensource-inventory ]; then
118     printf "XenSource inventory not present in /etc/xensource-inventory"
119     exit 1
120 fi
121
122 if [ "$1" = "1" ]; then
123     if md5sum -c --status <<EOF
124 ca141d60061dcfdade73e75abc6529b5  /usr/sbin/brctl
125 b8e9835862ef1a9cec2a3f477d26c989  /etc/xensource/scripts/vif
126 51970ad613a3996d5997e18e44db47da  /opt/xensource/libexec/interface-reconfigure
127 5654c8c36699fcc8744ca9cd5b855414  /usr/sbin/xen-bugtool
128 EOF
129     then
130         printf "\nVerified host scripts from XenServer 5.5.0.\n\n"
131     elif md5sum -c --status <<EOF
132 ca141d60061dcfdade73e75abc6529b5  /usr/sbin/brctl
133 b8e9835862ef1a9cec2a3f477d26c989  /etc/xensource/scripts/vif
134 ce451d3c985fd1db6497a363f0d9dedb  /opt/xensource/libexec/interface-reconfigure
135 2b53f500431fcba5276c896e9e4281b9  /usr/sbin/xen-bugtool
136 EOF
137     then
138         printf "\nVerified host scripts from XenServer 5.5.900.\n\n"
139     else
140 cat <<EOF
141
142 The original XenServer scripts replaced by this package are not those
143 of any supported version of XenServer.  This could lead to unexpected
144 behavior of your server.  Unless you are sure you know what you are
145 doing, it is highly recommended that you remove this package
146 immediately after the install completes, which will restore the
147 XenServer scripts that you were previously using.
148
149 EOF
150     fi
151 fi
152
153 if test ! -e /var/lib/openvswitch/dbcache; then
154     if test "$1" = 1; then
155         printf "Creating xapi database cache...  "
156     else
157         printf "warning: Open vSwitch is being re-installed or upgraded,\n"
158         printf "         but the xapi database cache is missing.\n"
159         printf "Re-creating xapi database cache...  "
160     fi
161
162     if /usr/share/vswitch/scripts/interface-reconfigure rewrite; then
163         printf "done.\n"
164     else
165         printf "FAILED\n"
166         printf "Open vSwitch can only be installed on a XenServer that\n"
167         printf "has connectivity to xapi on the pool master.  Please\n"
168         printf "fix connectivity to the pool master, then try again.\n"
169         exit 1
170     fi
171 fi
172
173 # Ensure that modprobe will find our modules.
174 depmod %{xen_version}
175
176 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
177     cat >>/etc/sysctl.conf <<EOF
178 # This works around an issue in xhad, which binds to a particular
179 # Ethernet device, which in turn causes ICMP port unreachable messages
180 # if packets are received are on the wrong interface, which in turn
181 # can happen if we send out ARP replies on every interface (as Linux
182 # does by default) instead of just on the interface that has the IP
183 # address being ARPed for, which this sysctl setting in turn works
184 # around.
185 #
186 # Bug #1378.
187 net.ipv4.conf.all.arp_filter = 1
188 EOF
189 fi
190
191 # Create ovs-vswitchd config database
192 ovsdb-tool create /etc/ovs-vswitchd.conf.db \
193         /usr/share/vswitch/vswitch-idl.ovsschema
194
195 # Create default or update existing /etc/sysconfig/vswitch.
196 SYSCONFIG=/etc/sysconfig/vswitch
197 TEMPLATE=/usr/share/vswitch/scripts/sysconfig.template
198 if [ ! -e $SYSCONFIG ]; then
199     cp $TEMPLATE $SYSCONFIG
200 else
201     for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
202     do
203         if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
204             echo >> $SYSCONFIG
205             sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
206         fi
207     done
208 fi
209
210 # Replace XenServer files by our versions.
211 mkdir -p /usr/lib/vswitch/xs-original \
212     || printf "Could not create script backup directory.\n"
213 for f in \
214     /opt/xensource/libexec/interface-reconfigure \
215     /etc/xensource/scripts/vif \
216     /usr/sbin/xen-bugtool \
217     /usr/sbin/brctl
218 do
219     s=$(basename "$f")
220     t=$(readlink "$f")
221     if [ "$t" != "/usr/share/vswitch/scripts/$s" ]; then
222         mv "$f" /usr/lib/vswitch/xs-original/ \
223             || printf "Could not save original XenServer $s script\n"
224         ln -s "/usr/share/vswitch/scripts/$s" "$f" \
225             || printf "Could not link to vSwitch $s script\n"
226     fi
227 done
228
229 # Install xsconsole plugin
230 plugin=$(readlink /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py)
231 if [ "$plugin" != "/usr/share/vswitch/scripts/XSFeatureVSwitch.py" ]; then
232     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
233     ln -s /usr/share/vswitch/scripts/XSFeatureVSwitch.py /usr/lib/xsconsole/plugins-base/ || printf "Could not link to vSswitch xsconsole plugin.\n"
234 fi
235
236 # Ensure all required services are set to run
237 for s in vswitch vswitch-xapi-update; do
238     if chkconfig --list $s >/dev/null 2>&1; then
239         chkconfig --del $s || printf "Could not remove $s init script."
240     fi
241     chkconfig --add $s || printf "Could not add $s init script."
242     chkconfig $s on || printf "Could not enable $s init script."
243 done
244
245 if [ "$1" = "1" ]; then    # $1 = 2 for upgrade
246     printf "\nYou MUST reboot the server NOW to complete the change to the\n"
247     printf "the vSwitch.  Attempts to modify networking on the server\n"
248     printf "or any hosted VM will fail until after the reboot and could\n"
249     printf "leave the server in an state requiring manual recovery.\n\n"
250 else
251     printf "\nTo use the new vSwitch, you should reboot the server\n"
252     printf "now.  Failure to do so may result in incorrect operation.\n\n"
253 fi
254
255 %preun
256 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
257     for s in vswitch vswitch-xapi-update; do
258         chkconfig --del $s || printf "Could not remove $s init script."
259     done
260 fi
261
262
263 %postun
264 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
265
266     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py \
267         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
268         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo \
269         || printf "Could not remove vSwitch xsconsole plugin.\n"
270
271     # Restore original XenServer scripts
272     for f in \
273         /opt/xensource/libexec/interface-reconfigure \
274         /etc/xensource/scripts/vif \
275         /usr/sbin/xen-bugtool \
276         /usr/sbin/brctl
277     do
278         s=$(basename "$f")
279         if [ ! -f "/usr/lib/vswitch/xs-original/$s" ]; then
280             printf "Original XenServer $s script not present in /usr/lib/vswitch/xs-original\n"
281             printf "Could not restore original XenServer script.\n"
282         else
283             (rm -f "$f" \
284                 && mv "/usr/lib/vswitch/xs-original/$s" "$f") \
285                 || printf "Could not restore original XenServer $s script.\n"
286         fi
287     done
288
289     # Remove all configuration files
290     rm -f /etc/ovs-vswitchd.conf.db
291     rm -f /etc/sysconfig/vswitch
292     rm -f /etc/ovs-vswitchd.cacert
293     rm -f /var/lib/openvswitch/dbcache
294
295     printf "\nYou MUST reboot the server now to complete the change to\n"
296     printf "standard Xen networking.  Attempts to modify networking on the\n"
297     printf "server or any hosted VM will fail until after the reboot and\n"
298     printf "could leave the server in a state requiring manual recovery.\n\n"
299 fi
300
301
302 %files
303 %defattr(-,root,root)
304 /etc/init.d/vswitch
305 /etc/init.d/vswitch-xapi-update
306 /etc/xapi.d/plugins/vswitch-cfg-update
307 /etc/logrotate.d/vswitch
308 /etc/profile.d/vswitch.sh
309 /lib/modules/%{xen_version}/kernel/net/vswitch/openvswitch_mod.ko
310 /lib/modules/%{xen_version}/kernel/net/vswitch/brcompat_mod.ko
311 %if %(echo '%{xen_version}'|awk -F"." '{if ($3>=18) print 1; else print 0;}')
312 /lib/modules/%{xen_version}/kernel/net/vswitch/ip_gre_mod.ko
313 %endif
314 /usr/share/vswitch/scripts/dump-vif-details
315 /usr/share/vswitch/scripts/refresh-xs-network-uuids
316 /usr/share/vswitch/scripts/interface-reconfigure
317 /usr/share/vswitch/scripts/vif
318 /usr/share/vswitch/scripts/xen-bugtool
319 /usr/share/vswitch/scripts/XSFeatureVSwitch.py
320 /usr/share/vswitch/scripts/brctl
321 /usr/share/vswitch/scripts/sysconfig.template
322 # Following two files are generated automatically by rpm.  We don't
323 # really need them and they won't be used on the XenServer, but there
324 # isn't an obvious place to get rid of them since they are generated
325 # after the install script runs.  Since they are small, we just
326 # include them.
327 /usr/share/vswitch/scripts/XSFeatureVSwitch.pyc
328 /usr/share/vswitch/scripts/XSFeatureVSwitch.pyo
329 /usr/share/vswitch/vswitch-idl.ovsschema
330 /usr/sbin/ovs-brcompatd
331 /usr/sbin/ovs-vswitchd
332 /usr/sbin/ovsdb-server
333 /usr/bin/ovs-appctl
334 /usr/bin/ovs-dpctl
335 /usr/bin/ovs-ofctl
336 /usr/bin/ovs-vsctl
337 /usr/bin/ovsdb-client
338 /usr/bin/ovsdb-tool
339 /usr/share/man/man1/ovsdb-client.1.gz
340 /usr/share/man/man1/ovsdb-server.1.gz
341 /usr/share/man/man1/ovsdb-tool.1.gz
342 /usr/share/man/man8/ovs-appctl.8.gz
343 /usr/share/man/man8/ovs-brcompatd.8.gz
344 /usr/share/man/man8/ovs-dpctl.8.gz
345 /usr/share/man/man8/ovs-ofctl.8.gz
346 /usr/share/man/man8/ovs-vsctl.8.gz
347 /usr/share/man/man8/ovs-vswitchd.8.gz
348 /var/lib/openvswitch