Add support for of1.3.
[integration.git] / packaging / rpm / opendaylight-controller.spec
1 # Spec file only supports RHEL and Fedora now
2 %if 0%{?rhel} || 0%{?fedora}
3
4 Name: opendaylight-controller
5 Version: 0.1.0
6 Release: 0.5.0%{?dist}
7 Summary: OpenDaylight SDN Controller
8 Group: Applications/Communications
9 License: EPL
10 URL: http://www.opendaylight.org
11
12 # todo: Temporary method for generating tarball
13 # git clone https://git.opendaylight.org/gerrit/p/controller.git
14 # cd controller
15 # git archive --prefix=opendaylight-controller-0.1.0/ HEAD | xz > opendaylight-controller-0.1.0.tar.xz
16 # git clone https://git.opendaylight.org/gerrit/p/integration.git
17 # cd integration
18 # git archive --prefix=opendaylight-integration-0.1.0/HEAD | xz > opendaylight-integration-0.1.0.tar.xz
19 Source0: %{name}-%{version}.tar.xz
20 Source1: opendaylight-integration-%{version}.tar.xz
21 Patch0: opendaylight-integration-fix-paths.patch
22
23 BuildArch: noarch
24
25 BuildRequires: java-devel
26 BuildRequires: maven
27 %if 0%{?fedora}
28 BuildRequires: systemd
29 %else
30 BuildRequires: sysvinit-tools
31 %endif
32
33 Requires: java >= 1:1.7.0
34
35 # todo: Need to create proper packages for all the dependencies.
36 # Here you should have at least dependencies for the packages containing .jar
37 # files that you want to create symlinks to. For now all the jars in a
38 # dependencies package.
39 #Requires: slf4j
40
41 Requires: %{name}-dependencies
42
43 %if 0%{?fedora}
44 Requires(post): systemd
45 Requires(preun): systemd
46 Requires(postun): systemd
47 %else
48 # use sysV for rhel
49 Requires(post): chkconfig
50 Requires(preun): chkconfig
51
52 # This is for /sbin/service
53 Requires(preun): initscripts
54 Requires(postun): initscripts
55 %endif
56
57
58 # This is the directory where all the application resources (scripts,
59 # libraries, etc) will be installed: /usr/share/opendaylight
60 %global resources_dir %{_datadir}/%{name}
61
62 # This is the directory where variable data used by the application should be
63 # created: /var/lib/opendaylight
64 %global data_dir %{_localstatedir}/lib/%{name}
65
66 # This is the directory where the application stores its configuration:
67 # /etc/opendaylight
68 %global configuration_dir %{_sysconfdir}/%{name}
69
70 # This is the directory that has all the JAVA dependencies.
71 %global deps_dir %{_javadir}/opendaylight-controller-dependencies
72
73 # This is the integration buildsubdir and packaging dirs:
74 #%global intbuildsubdir %{_builddir}/%{buildsubdir}/opendaylight-integration-%{version}
75 %global pkgdir opendaylight-integration-%{version}/packaging/rpm
76
77
78 %description
79 OpenDaylight SDN Controller
80
81
82 %prep
83
84 %setup -q
85 %setup -q -D -T -a 1
86 cd opendaylight-integration-%{version}
87 %patch0 -p1
88
89
90 # In more restrictive distributions we should also here remove from the source
91 # package any third party binaries, or replace them with those provided by the
92 # distribution, before performing the actual build.
93
94
95 %build
96
97 # This regular maven build will need to be replaced by the distribution
98 # specific maven build command, but this is ok for now:
99 # todo: eventually move to using mvn-build or mvn-rpmbuild so dependencies are
100 # not downloaded.
101 # Don't do the tests since those are already covered by the normal merge and
102 # verify process and this build does not need to verify them.
103 # maven.compile.fork is used to reduce the build time.
104 #export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=256m" && \
105 #  mvn clean install -Dmaven.test.skip=true -DskipIT -Dmaven.compile.fork=true
106 export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=256m" && mvn clean install -Dmaven.test.skip=true
107
108
109 %install
110
111 # Extract the contents of the distribution to a temporary directory so that we
112 # can take things from there and move them to the correct locations:
113 mkdir -p tmp
114 unzip -o -d tmp opendaylight/distribution/opendaylight/target/distribution.opendaylight-osgipackage.zip
115
116 # Create the directories:
117 mkdir -p %{buildroot}%{configuration_dir}
118 mkdir -p %{buildroot}%{resources_dir}/configuration
119 mkdir -p %{buildroot}%{data_dir}/configuration
120
121 mv tmp/opendaylight/configuration/config.ini %{buildroot}%{configuration_dir}
122 ln -s %{configuration_dir}/config.ini %{buildroot}%{data_dir}/configuration
123 mv tmp/opendaylight/configuration/* %{buildroot}%{resources_dir}/configuration
124 rmdir tmp/opendaylight/configuration
125 ln -s %{resources_dir}/configuration/context.xml %{buildroot}%{data_dir}/configuration
126 ln -s %{resources_dir}/configuration/logback.xml %{buildroot}%{data_dir}/configuration
127 ln -s %{resources_dir}/configuration/tomcat-server.xml %{buildroot}%{data_dir}/configuration
128
129 mv tmp/opendaylight/* %{buildroot}%{resources_dir}
130
131 ln -s %{resources_dir}/lib %{buildroot}%{data_dir}
132 ln -s %{resources_dir}/plugins %{buildroot}%{data_dir}
133
134 %if 0%{?fedora}
135 install -m 644 -D %{pkgdir}/%{name}.systemd %{buildroot}%{_unitdir}/%{name}.service
136 %else
137 install -m 644 -D %{pkgdir}/%{name}.sysv %{buildroot}%{_initddir}/%{name}
138 %endif
139 install -m 644 -D %{pkgdir}/%{name}.sysconfig %{buildroot}%{_sysconfdir}/sysconfig/%{name}
140
141 # Fix all the run.sh files to the right names.
142 install -m 755 -D %{buildroot}%{resources_dir}/run.sh %{buildroot}%{resources_dir}/run.internal.sh
143 install -m 755 -D opendaylight-integration-%{version}/distributions/base/src/assemble/resources/run.sh \
144     %{buildroot}%{resources_dir}/run.base.sh
145 rm %{buildroot}%{resources_dir}/run.sh
146 install -m 755 -D opendaylight-integration-%{version}/distributions/virtualization/src/assemble/resources/run.sh \
147     %{buildroot}%{resources_dir}/run.sh
148 install -m 755 -D opendaylight-integration-%{version}/packaging/rpm/run.dist.sh %{buildroot}%{resources_dir}/run.dist.sh
149
150 # Usually one wants to replace the .jar files of the dependencies by symlinks
151 # to the ones provided to the system. This assumes the dependencies have been
152 # installed as separate packages and listed in the Requires header.
153 cd %{buildroot}%{resources_dir}/lib
154 for src in $( ls -I "org.opendaylight.*" );
155 do
156     rm -f ${src}
157     #tgt=$(echo ${src} | sed -e "s/-[0-9].*/.jar/")
158     #ln -s %{deps_dir}/${tgt} ${src}
159     ln -s %{deps_dir}/${src} ${src}
160 done
161
162 cd %{buildroot}%{resources_dir}/plugins
163 for src in $( ls -I "org.opendaylight.*" );
164 do
165     rm -f ${src}
166     #tgt=$(echo ${src} | sed -e "s/-[0-9].*/.jar/")
167     #ln -s %{deps_dir}/${tgt} ${src}
168     ln -s %{deps_dir}/${src} ${src}
169 done
170
171
172 # Fix the permissions as they come with all the permissions (mode 777)
173 # from the .zip file:
174 find %{buildroot}%{resources_dir} -type d -exec chmod 755 {} \;
175 find %{buildroot}%{resources_dir} -type f -exec chmod 644 {} \;
176 find %{buildroot}%{data_dir} -type d -exec chmod 755 {} \;
177 find %{buildroot}%{data_dir} -type f -exec chmod 755 {} \;
178 chmod 755 %{buildroot}%{resources_dir}/run.sh
179 chmod 755 %{buildroot}%{resources_dir}/run.base.sh
180 chmod 755 %{buildroot}%{resources_dir}/run.internal.sh
181 chmod 755 %{buildroot}%{resources_dir}/run.dist.sh
182 %if 0%{?rhel}
183 chmod 755 %{buildroot}%{_initddir}/%{name}
184 %endif
185
186 # Remove the temporary directory:
187 rm -rf tmp
188
189
190 %pre
191
192 # todo: register the opendaylight group:user.
193 # Create the group and user that will run the service before installing the
194 # package, as some of the files and directories will be owned by this user:
195 getent group opendaylight > /dev/null
196 if [ "$?" != 0 ]; then
197     groupadd \
198         -f \
199         -r \
200         opendaylight
201 fi
202
203 getent passwd opendaylight > /dev/null
204 if [ "$?" != 0 ]; then
205     useradd \
206         -r \
207         -g opendaylight \
208         -c "OpenDaylight SDN" \
209         -s /sbin/nologin \
210         -d %{data_dir} \
211         opendaylight
212 fi
213
214 # Currently not enabling service on boot.
215 #%post
216 #%systemd_post %{name}.service
217
218 %preun
219 %if 0%{?fedora}
220 %systemd_preun %{name}.service
221 %else
222 if [ $1 -eq 0 ] ; then
223     /sbin/service %{name} stop >/dev/null 2>&1
224     /sbin/chkconfig --del %{name}
225 fi
226 %endif
227
228 %postun
229 %if 0%{?fedora}
230 %systemd_postun
231 %else
232 if [ "$1" -ge "1" ] ; then
233     /sbin/service %{name} condrestart >/dev/null 2>&1 || :
234 fi
235 %endif
236
237 %clean
238 # This check is used for mock build so the build files are not deleted.
239 %if "%{noclean}" == "1"
240     exit 0
241 %endif
242
243
244 %files
245
246 %{resources_dir}
247 %if 0%{?fedora}
248 %{_unitdir}/%{name}.service
249 %else
250 %{_initddir}/%{name}
251 %endif
252
253 # Configuration files should marked as such, so that they aren't overwritten
254 # when updating the package:
255 %dir %{configuration_dir}
256 %config(noreplace) %{configuration_dir}/config.ini
257 %config(noreplace) %{_sysconfdir}/sysconfig/%{name}
258
259 # The data directory needs to be owned by the user that will run the service,
260 # as it will need to write inside:
261 %attr(-, opendaylight, opendaylight) %{data_dir}
262
263 # Documentation:
264 %doc LICENSE
265 %doc NOTICE
266 %doc README.OPENDAYLIGHT
267
268 %endif
269
270 %changelog
271 * Thu Jan 09 2014 Sam Hague <shague@redhat.com> - 0.1.0-0.5.0
272 - Updates for OF1.3 support.
273
274 * Thu Jan 02 2014 Sam Hague <shague@redhat.com> - 0.1.0-0.4.0
275 - Updates to include building distributions.
276
277 * Mon Dec 23 2013 Hsin-Yi Shen <hshen@redhat.com> - 0.1.0-0.3.0
278 - Updates to support building rpm for both RHEL and fedora.
279
280 * Fri Nov 22 2013 Sam Hague <shague@redhat.com> - 0.1.0-0.2.0
281 - Updates to support building rpm with jenkins.
282
283 * Tue Nov 12 2013 Sam Hague <shague@redhat.com> - 0.1.0-0.1.20131007git20dcbd1
284 - Modify the source tarball instructions and name.
285
286 * Wed Nov 06 2013 Sam Hague <shague@redhat.com> - 0.1.0-0.1.20131007git2f02ee4
287 - Add systemd support to install the service.
288 - Simplify the file permission modification logic.
289 - Modify the mvn command to not build tests.
290
291 * Fri Nov 01 2013 Sam Hague <shague@redhat.com> - 0.1.0-0.1.20131007git31c8f18
292 - Modify to include opendaylight-controller-dependencies.
293 - Do not delete the files in var
294
295 * Mon Oct 07 2013 Sam Hague <shague@redhat.com> - 0.1.0-0.1.20131007gitd684dd4
296 - Initial Fedora package.