Packaging update to support building ODL distributions.
[integration/packaging.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.4.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 packaging/rpm
18 # git archive HEAD opendaylight-controller.sysconfig opendaylight-controller.systemd \
19 #   opendaylight-controller.sysv run.dist.sh | xz > opendaylight-controller-integration-0.1.0.tar.xz
20 Source0: %{name}-%{version}.tar.xz
21 Source1: %{name}-integration-%{version}.tar.xz
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
74 %description
75 OpenDaylight SDN Controller
76
77
78 %prep
79
80 %setup -q
81 %setup -q -D -T -a 1
82
83 # In more restrictive distributions we should also here remove from the source
84 # package any third party binaries, or replace them with those provided by the
85 # distribution, before performing the actual build.
86
87
88 %build
89
90 # This regular maven build will need to be replaced by the distribution
91 # specific maven build command, but this is ok for now:
92 # todo: eventually move to using mvn-build or mvn-rpmbuild so dependencies are
93 # not downloaded.
94 # Don't do the tests since those are already covered by the normal merge and
95 # verify process and this build does not need to verify them.
96 # maven.compile.fork is used to reduce the build time.
97 #export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=256m" && \
98 #  mvn clean install -Dmaven.test.skip=true -DskipIT -Dmaven.compile.fork=true
99 export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=256m" && mvn clean install -Dmaven.test.skip=true
100
101
102 %install
103
104 # Extract the contents of the distribution to a temporary directory so that we
105 # can take things from there and move them to the correct locations:
106 mkdir -p tmp
107 unzip -o -d tmp opendaylight/distribution/opendaylight/target/distribution.opendaylight-osgipackage.zip
108
109 # Create the directories:
110 mkdir -p %{buildroot}%{configuration_dir}
111 mkdir -p %{buildroot}%{resources_dir}/configuration
112 mkdir -p %{buildroot}%{data_dir}/configuration
113
114 mv tmp/opendaylight/configuration/config.ini %{buildroot}%{configuration_dir}
115 ln -s %{configuration_dir}/config.ini %{buildroot}%{data_dir}/configuration
116 mv tmp/opendaylight/configuration/* %{buildroot}%{resources_dir}/configuration
117 rmdir tmp/opendaylight/configuration
118 ln -s %{resources_dir}/configuration/context.xml %{buildroot}%{data_dir}/configuration
119 ln -s %{resources_dir}/configuration/logback.xml %{buildroot}%{data_dir}/configuration
120 ln -s %{resources_dir}/configuration/tomcat-server.xml %{buildroot}%{data_dir}/configuration
121
122 mv tmp/opendaylight/* %{buildroot}%{resources_dir}
123
124 ln -s %{resources_dir}/lib %{buildroot}%{data_dir}
125 ln -s %{resources_dir}/plugins %{buildroot}%{data_dir}
126
127 %if 0%{?fedora}
128 install -m 644 -D %{name}.systemd %{buildroot}%{_unitdir}/%{name}.service
129 %else
130 install -m 644 -D %{name}.sysv %{buildroot}%{_initddir}/%{name}
131 %endif
132 install -m 644 -D %{name}.sysconfig %{buildroot}%{_sysconfdir}/sysconfig/%{name}
133 install -m 755 -D run.dist.sh %{buildroot}%{resources_dir}/run.dist.sh
134
135 # Usually one wants to replace the .jar files of the dependencies by symlinks
136 # to the ones provided to the system. This assumes the dependencies have been
137 # installed as separate packages and listed in the Requires header.
138 cd %{buildroot}%{resources_dir}/lib
139 for src in $( ls -I "org.opendaylight.*" );
140 do
141     rm -f ${src}
142     #tgt=$(echo ${src} | sed -e "s/-[0-9].*/.jar/")
143     #ln -s %{deps_dir}/${tgt} ${src}
144     ln -s %{deps_dir}/${src} ${src}
145 done
146
147 cd %{buildroot}%{resources_dir}/plugins
148 for src in $( ls -I "org.opendaylight.*" );
149 do
150     rm -f ${src}
151     #tgt=$(echo ${src} | sed -e "s/-[0-9].*/.jar/")
152     #ln -s %{deps_dir}/${tgt} ${src}
153     ln -s %{deps_dir}/${src} ${src}
154 done
155
156
157 # Fix the permissions as they come with all the permissions (mode 777)
158 # from the .zip file:
159 find %{buildroot}%{resources_dir} -type d -exec chmod 755 {} \;
160 find %{buildroot}%{resources_dir} -type f -exec chmod 644 {} \;
161 find %{buildroot}%{data_dir} -type d -exec chmod 755 {} \;
162 find %{buildroot}%{data_dir} -type f -exec chmod 755 {} \;
163 chmod 755 %{buildroot}%{resources_dir}/run.sh
164 chmod 755 %{buildroot}%{resources_dir}/run.dist.sh
165 %if 0%{?rhel}
166 chmod 755 %{buildroot}%{_initddir}/%{name}
167 %endif
168
169 # Remove the temporary directory:
170 rm -rf tmp
171
172
173 %pre
174
175 # todo: register the opendaylight group:user.
176 # Create the group and user that will run the service before installing the
177 # package, as some of the files and directories will be owned by this user:
178 getent group opendaylight > /dev/null
179 if [ "$?" != 0 ]; then
180     groupadd \
181         -f \
182         -r \
183         opendaylight
184 fi
185
186 getent passwd opendaylight > /dev/null
187 if [ "$?" != 0 ]; then
188     useradd \
189         -r \
190         -g opendaylight \
191         -c "OpenDaylight SDN" \
192         -s /sbin/nologin \
193         -d %{data_dir} \
194         opendaylight
195 fi
196
197 # Currently not enabling service on boot.
198 #%post
199 #%systemd_post %{name}.service
200
201 %preun
202 %if 0%{?fedora}
203 %systemd_preun %{name}.service
204 %else
205 if [ $1 -eq 0 ] ; then
206     /sbin/service %{name} stop >/dev/null 2>&1
207     /sbin/chkconfig --del %{name}
208 fi
209 %endif
210
211 %postun
212 %if 0%{?fedora}
213 %systemd_postun
214 %else
215 if [ "$1" -ge "1" ] ; then
216     /sbin/service %{name} condrestart >/dev/null 2>&1 || :
217 fi
218 %endif
219
220 %clean
221 # This check is used for mock build so the build files are not deleted.
222 %if "%{noclean}" == "1"
223     exit 0
224 %endif
225
226
227 %files
228
229 %{resources_dir}
230 %if 0%{?fedora}
231 %{_unitdir}/%{name}.service
232 %else
233 %{_initddir}/%{name}
234 %endif
235
236 # Configuration files should marked as such, so that they aren't overwritten
237 # when updating the package:
238 %dir %{configuration_dir}
239 %config(noreplace) %{configuration_dir}/config.ini
240 %config(noreplace) %{_sysconfdir}/sysconfig/%{name}
241
242 # The data directory needs to be owned by the user that will run the service,
243 # as it will need to write inside:
244 %attr(-, opendaylight, opendaylight) %{data_dir}
245
246 # Documentation:
247 %doc LICENSE
248 %doc NOTICE
249 %doc README.OPENDAYLIGHT
250
251 %endif
252
253 %changelog
254 * Thu Jan 02 2014 Sam Hague <shague@redhat.com> - 0.1.0-0.4.0
255 - Updates to include building distributions.
256
257 * Mon Dec 23 2013 Hsin-Yi Shen <hshen@redhat.com> - 0.1.0-0.3.0
258 - Updates to support building rpm for both RHEL and fedora.
259
260 * Fri Nov 22 2013 Sam Hague <shague@redhat.com> - 0.1.0-0.2.0
261 - Updates to support building rpm with jenkins.
262
263 * Tue Nov 12 2013 Sam Hague <shague@redhat.com> - 0.1.0-0.1.20131007git20dcbd1
264 - Modify the source tarball instructions and name.
265
266 * Wed Nov 06 2013 Sam Hague <shague@redhat.com> - 0.1.0-0.1.20131007git2f02ee4
267 - Add systemd support to install the service.
268 - Simplify the file permission modification logic.
269 - Modify the mvn command to not build tests.
270
271 * Fri Nov 01 2013 Sam Hague <shague@redhat.com> - 0.1.0-0.1.20131007git31c8f18
272 - Modify to include opendaylight-controller-dependencies.
273 - Do not delete the files in var
274
275 * Mon Oct 07 2013 Sam Hague <shague@redhat.com> - 0.1.0-0.1.20131007gitd684dd4
276 - Initial Fedora package.