shutdown lighttpd correctly
[opensuse:yast-rest-service.git] / webservice / package / webyast-base-ws.spec
1 #
2 # spec file for package webyast-base-ws (Version 0.1.19)
3 #
4 # Copyright (c) 2008 SUSE LINUX Products GmbH, Nuernberg, Germany.
5 # This file and all modifications and additions to the pristine
6 # package are under the same license as the package itself.
7 #
8 # Please submit bugfixes or comments via http://bugs.opensuse.org/
9 #
10
11
12 Name:           webyast-base-ws
13 Provides:       yast2-webservice = %{version}
14 Obsoletes:      yast2-webservice < %{version}
15 Provides:       webyast-language-ws = 0.1.0
16 Obsoletes:      webyast-language-ws <= 0.1.0
17
18 %if 0%{?suse_version} == 0 || %suse_version > 1110
19 # 11.2 or newer
20
21 %if 0%{?suse_version} > 1120
22 # since 11.3, they are in a separate subpackage
23 Requires:       sysvinit-tools
24 %else
25 # Require startproc respecting -p, bnc#559534#c44
26 Requires:       sysvinit > 2.86-215.2
27 %endif
28 Requires:       yast2-core >= 2.18.10
29 %else
30 # 11.1 or SLES11
31 Requires:       yast2-core >= 2.17.30.1
32 Requires:       sysvinit > 2.86-195.3.1
33 %endif
34 Requires:       rubygem-passenger-nginx
35 Requires:       nginx >= 1.0
36 Requires:       ruby-fcgi, sqlite, syslog-ng
37 %if 0%{?suse_version} == 0 || %suse_version <= 1130
38 Requires:       ruby-dbus
39 %else
40 Requires:       rubygem-ruby-dbus
41 %endif
42 Requires:       rubygem-webyast-rake-tasks, rubygem-http_accept_language
43 Requires:       rubygem-static_record_cache
44 Requires:       yast2-dbus-server
45 # 634404
46 Recommends:     logrotate
47 PreReq:         PolicyKit, PackageKit, rubygem-rake, rubygem-sqlite3
48 PreReq:         rubygem-rails-2_3 >= 2.3.8
49 PreReq:         rubygem-rpam, rubygem-polkit, rubygem-gettext_rails
50 PreReq:         yast2-runlevel
51 License:        LGPL-2.0
52 Group:          Productivity/Networking/Web/Utilities
53 URL:            http://en.opensuse.org/Portal:WebYaST
54 Autoreqprov:    on
55 Version:        0.2.23
56 Release:        0
57 Summary:        WebYaST - base components for rest service
58 Source:         www.tar.bz2
59 Source1:        webyastPermissionsService.rb
60 Source2:        webyast.permissions.conf
61 Source3:        webyast.permissions.service.service
62 Source4:        org.opensuse.yast.permissions.policy
63 Source5:        grantwebyastrights
64 Source6:        yast_user_roles
65 Source9:        yastws
66 Source10:       webyast
67 Source11:       webyast-ws.lr.conf
68 Source12:       nginx.conf
69
70 BuildRoot:      %{_tmppath}/%{name}-%{version}-build
71 BuildRequires:  ruby, pkg-config, rubygem-mocha, rubygem-static_record_cache
72 # if we run the tests during build, we need most of Requires here too,
73 # except for deployment specific stuff
74 BuildRequires:  rubygem-webyast-rake-tasks, rubygem-restility
75 BuildRequires:  yast2-core, yast2-dbus-server, sqlite, dbus-1
76 %if 0%{?suse_version} == 0 || %suse_version <= 1130
77 BuildRequires:  ruby-dbus
78 %else
79 BuildRequires:  rubygem-ruby-dbus
80 %endif
81 BuildRequires:  PolicyKit, PackageKit, rubygem-sqlite3
82 BuildRequires:  rubygem-rails-2_3 >= 2.3.8
83 BuildRequires:  rubygem-rpam, rubygem-polkit
84 # the testsuite is run during build
85 BuildRequires:  rubygem-test-unit rubygem-mocha
86 BuildRequires:  nginx >= 1.0, rubygem-passenger-nginx
87
88 # This is for Hudson (build service) to setup the build env correctly
89 %if 0
90 BuildRequires:  rubygem-test-unit
91 BuildRequires:  rubygem-rcov >= 0.9.3.2
92 %endif
93
94 # we do not necessarily need any UI in case of WebYaST
95 Provides:       yast2_ui
96 Provides:       yast2_ui_pkg
97
98 # rpmlint warns about file duplicates, this should take care but
99 # doesn't build (?!)
100 #%if 0%{?suse_version} > 1020
101 #BuildRequires:  fdupes
102 #%endif
103
104 BuildArch:      noarch
105
106 %package testsuite
107 Group:    Productivity/Networking/Web/Utilities
108 Requires: webyast-base-ws = %{version}
109 Summary:  Testsuite for webyast-base-ws package
110
111 #
112 %define pkg_home /var/lib/%{webyast_ws_user}
113 #
114
115
116 %description
117 WebYaST - Core components for REST based interface to system manipulation.
118 Authors:
119 --------
120     Duncan Mac-Vicar Prett <dmacvicar@suse.de>
121     Klaus Kaempf <kkaempf@suse.de>
122     Bjoern Geuken <bgeuken@suse.de>
123     Stefan Schubert <schubi@suse.de>
124
125 %description testsuite
126 Testsuite for core WebYaST webservice package.
127
128 %prep
129 %setup -q -n www
130
131 %build
132
133 %check
134 # run the testsuite
135 RAILS_ENV=test rake db:migrate
136 RAILS_ENV=test $RPM_BUILD_ROOT%{webyast_ws_dir}/test/dbus-launch-simple rake test
137
138 #---------------------------------------------------------------
139 %install
140
141 #
142 # Install all web and frontend parts.
143 #
144 mkdir -p $RPM_BUILD_ROOT%{webyast_ws_dir}/log/
145 cp -a * $RPM_BUILD_ROOT%{webyast_ws_dir}/
146 rm -f $RPM_BUILD_ROOT%{webyast_ws_dir}/log/*
147 rm -f $RPM_BUILD_ROOT%{webyast_ws_dir}/COPYING
148 touch $RPM_BUILD_ROOT%{webyast_ws_dir}/db/schema.rb
149
150 %{__install} -d -m 0755                            \
151     %{buildroot}%{pkg_home}/sockets/               \
152     %{buildroot}%{pkg_home}/cache/                 \
153     %{buildroot}%{_sbindir}                        \
154     %{buildroot}%{_var}/log/%{webyast_ws_user}
155 #
156 # init script
157 #
158 %{__install} -D -m 0755 %SOURCE9 \
159     %{buildroot}%{_sysconfdir}/init.d/%{webyast_ws_service}
160 %{__ln_s} -f %{_sysconfdir}/init.d/%{webyast_ws_service} %{buildroot}%{_sbindir}/rc%{webyast_ws_service}
161 #
162
163 # configure nginx web service
164 mkdir -p $RPM_BUILD_ROOT/etc/yastws/
165 install -m 0644 %SOURCE12 $RPM_BUILD_ROOT/etc/yastws/
166 # create symlinks to nginx config files
167 ln -s /etc/nginx/fastcgi.conf $RPM_BUILD_ROOT/etc/yastws
168 ln -s /etc/nginx/fastcgi_params $RPM_BUILD_ROOT/etc/yastws
169 ln -s /etc/nginx/koi-utf $RPM_BUILD_ROOT/etc/yastws
170 ln -s /etc/nginx/koi-win $RPM_BUILD_ROOT/etc/yastws
171 ln -s /etc/nginx/mime.types $RPM_BUILD_ROOT/etc/yastws
172 ln -s /etc/nginx/scgi_params $RPM_BUILD_ROOT/etc/yastws
173 ln -s /etc/nginx/uwsgi_params $RPM_BUILD_ROOT/etc/yastws
174 ln -s /etc/nginx/win-utf $RPM_BUILD_ROOT/etc/yastws
175
176 # Policies
177 mkdir -p $RPM_BUILD_ROOT/usr/share/PolicyKit/policy
178 install -m 0644 %SOURCE4 $RPM_BUILD_ROOT/usr/share/PolicyKit/policy/
179 install -m 0644 %SOURCE6 $RPM_BUILD_ROOT/etc/
180 install -m 0555 %SOURCE5 $RPM_BUILD_ROOT/usr/sbin/
181
182 # firewall service definition, bnc#545627
183 mkdir -p $RPM_BUILD_ROOT/etc/sysconfig/SuSEfirewall2.d/services
184 install -m 0644 %SOURCE10 $RPM_BUILD_ROOT/etc/sysconfig/SuSEfirewall2.d/services
185
186 # logrotate configuration bnc#634404
187 mkdir $RPM_BUILD_ROOT/etc/logrotate.d
188 install -m 0644 %SOURCE11 $RPM_BUILD_ROOT/etc/logrotate.d
189
190 #  create yastwsdirs (config, var and data)
191 mkdir -p $RPM_BUILD_ROOT/etc/webyast
192 mkdir -p $RPM_BUILD_ROOT/var/lib/yastws
193 mkdir -p $RPM_BUILD_ROOT/usr/share/yastws
194
195 #  create empty tmp directory
196 mkdir -p $RPM_BUILD_ROOT%{webyast_ws_dir}/tmp
197 mkdir -p $RPM_BUILD_ROOT%{webyast_ws_dir}/tmp/cache
198 mkdir -p $RPM_BUILD_ROOT%{webyast_ws_dir}/tmp/pids
199 mkdir -p $RPM_BUILD_ROOT%{webyast_ws_dir}/tmp/sessions
200 mkdir -p $RPM_BUILD_ROOT%{webyast_ws_dir}/tmp/sockets
201
202 # install permissions service
203 mkdir -p $RPM_BUILD_ROOT/usr/sbin/
204 install -m 0500 %SOURCE1 $RPM_BUILD_ROOT/usr/sbin/
205 mkdir -p $RPM_BUILD_ROOT/etc/dbus-1/system.d/
206 install -m 0644 %SOURCE2 $RPM_BUILD_ROOT/etc/dbus-1/system.d/
207 mkdir -p $RPM_BUILD_ROOT/usr/share/dbus-1/system-services/
208 install -m 0444 %SOURCE3 $RPM_BUILD_ROOT/usr/share/dbus-1/system-services/
209
210 #create dummy update-script
211 mkdir -p %buildroot/var/adm/update-scripts
212 touch %buildroot/var/adm/update-scripts/%name-%version-%release-1
213
214 #---------------------------------------------------------------
215 %clean
216 rm -rf $RPM_BUILD_ROOT
217
218 #---------------------------------------------------------------
219 %pre
220
221 #
222 # e.g. adding user
223 #
224 /usr/sbin/groupadd -r %{webyast_ws_user} &>/dev/null ||:
225 /usr/sbin/useradd  -g %{webyast_ws_user} -s /bin/false -r -c "User for YaST-Webservice" -d %{pkg_home} %{webyast_ws_user} &>/dev/null ||:
226
227 # services will not be restarted correctly if
228 # the package name will changed while the update
229 # So the service will be restarted by an update-script
230 # which will be called AFTER the installation
231 if /bin/rpm -q yast2-webservice > /dev/null ; then
232   echo "renaming yast2-webservice to webyast-base-ws"
233   if /sbin/yast runlevel summary service=yastws 2>&1|grep " 3 "|grep yastws >/dev/null ; then
234     echo "yastws is inserted into the runlevel"
235     echo "#!/bin/sh" > %name-%version-%release-1
236     echo "/sbin/yast runlevel add service=yastws" >> %name-%version-%release-1
237     echo "/usr/sbin/rcyastws restart" >> %name-%version-%release-1
238   else
239     if /usr/sbin/rcyastws status > /dev/null ; then
240       echo "yastws is running"
241       echo "#!/bin/sh" > %name-%version-%release-1
242       echo "/usr/sbin/rcyastws restart" >> %name-%version-%release-1
243     fi
244   fi
245 fi
246 #We are switching from lighttpd to nginx. So lighttpd has to be killed
247 #at first
248 if rpm -q --requires %{name}|grep lighttpd > /dev/null ; then
249   if /usr/sbin/rcyastws status > /dev/null ; then
250     echo "yastws is running under lighttpd -> switching to nginx"
251     /usr/sbin/rcyastws stop > /dev/null
252     echo "#!/bin/sh" > %name-%version-%release-1
253     echo "/usr/sbin/rcyastws restart" >> %name-%version-%release-1
254   fi
255 fi
256 if [ -f %name-%version-%release-1 ] ; then
257   install -D -m 755 %name-%version-%release-1 /var/adm/update-scripts
258   rm %name-%version-%release-1
259   echo "Please check the service runlevels and restart WebYaST service with \"rcyastws restart\" if the update has not been called with zypper,yast or packagekit"
260 fi
261 exit 0
262
263 #---------------------------------------------------------------
264 %post
265 %fillup_and_insserv %{webyast_ws_service}
266 #
267 #granting permissions for yastws
268 #
269 if [ `/usr/bin/polkit-auth --user %{webyast_ws_user} | grep -c "org.freedesktop.packagekit.system-update"` -eq 0 ]; then
270   # FIXME: remove ||: (don't hide errors), has to be correctly implemented for package update...
271   /usr/bin/polkit-auth --user %{webyast_ws_user} --grant org.freedesktop.packagekit.system-update > /dev/null ||:
272 fi
273 if [ `/usr/bin/polkit-auth --user %{webyast_ws_user} | grep -c "org.freedesktop.policykit.read"` -eq 0 ]; then
274   # FIXME: remove ||: (don't hide errors), has to be correctly implemented for package update...
275   /usr/bin/polkit-auth --user %{webyast_ws_user} --grant org.freedesktop.policykit.read > /dev/null ||:
276 fi
277 if [ `/usr/bin/polkit-auth --user %{webyast_ws_user} | grep -c "org.opensuse.yast.module-manager.import"` -eq 0 ]; then
278   # FIXME: remove ||: (don't hide errors), has to be correctly implemented for package update...
279   /usr/bin/polkit-auth --user %{webyast_ws_user} --grant org.opensuse.yast.module-manager.import > /dev/null ||:
280 fi
281 #
282 # granting all permissions for root 
283 #
284 /usr/sbin/grantwebyastrights --user root --action grant > /dev/null ||:
285 #
286 # create database 
287 #
288 cd %{webyast_ws_dir}
289 #migrate database
290 RAILS_ENV=production rake db:migrate
291 chown -R %{webyast_ws_user}: db
292 chown -R %{webyast_ws_user}: log
293 echo "Database is ready"
294 #
295 # patching nginx configuration
296 #
297 if [ -d /usr/lib64 ]; then
298   sed -i "s/passenger_root \/usr\/lib/passenger_root \/usr\/lib64/" /etc/yastws/nginx.conf
299 fi
300 #
301 # try-reload D-Bus config (bnc#635826)
302 #
303 dbus-send --print-reply --system --dest=org.freedesktop.DBus / org.freedesktop.DBus.ReloadConfig >/dev/null ||:
304
305 #---------------------------------------------------------------
306 %preun
307 %stop_on_removal %{webyast_ws_service}
308
309 #---------------------------------------------------------------
310 %postun
311 %restart_on_update %{webyast_ws_service}
312 %{insserv_cleanup}
313
314 #---------------------------------------------------------------
315 # restart yastws on nginx update (bnc#559534)
316 %triggerin -- nginx
317 %restart_on_update %{webyast_ws_service}
318
319 #---------------------------------------------------------------
320 %files 
321 %defattr(-,root,root)
322 #this /etc/yastws is for ligght conf for yastws
323 %dir /etc/yastws
324 %dir %{webyast_ws_dir}
325 %dir %{_datadir}/PolicyKit
326 %dir %{_datadir}/PolicyKit/policy
327 %attr(-,%{webyast_ws_user},%{webyast_ws_user}) %dir %{pkg_home}
328 %attr(-,%{webyast_ws_user},%{webyast_ws_user}) %dir %{pkg_home}/sockets
329 %attr(-,%{webyast_ws_user},%{webyast_ws_user}) %dir %{pkg_home}/cache
330 %attr(-,%{webyast_ws_user},%{webyast_ws_user}) %dir %{_var}/log/%{webyast_ws_user}
331
332 #logrotate configuration file
333 %config(noreplace) /etc/logrotate.d/webyast-ws.lr.conf
334
335 #this /etc/webyast is for webyast configuration files
336 %dir /etc/webyast/
337 %dir %{_datadir}/yastws
338 %dir %attr(-,%{webyast_ws_user},root) /var/lib/yastws
339 %dir %{webyast_ws_dir}/db
340 %{webyast_ws_dir}/app
341 %{webyast_ws_dir}/db/migrate
342 %ghost %{webyast_ws_dir}/db/schema.rb
343 %{webyast_ws_dir}/doc
344 %{webyast_ws_dir}/lib
345 %{webyast_ws_dir}/public
346 %{webyast_ws_dir}/Rakefile
347 %{webyast_ws_dir}/script
348 %{webyast_ws_dir}/vendor
349 %dir %{webyast_ws_dir}/config
350 %{webyast_ws_dir}/config/boot.rb
351 %{webyast_ws_dir}/config/database.yml
352 %{webyast_ws_dir}/config/environments
353 %{webyast_ws_dir}/config/initializers
354 %{webyast_ws_dir}/config/routes.rb
355 #also users can run granting script, as permissions is handled by policyKit right for granting permissions
356 %attr(555,root,root) /usr/sbin/grantwebyastrights
357 %attr(755,root,root) %{webyast_ws_dir}/start.sh
358 %attr(500,root,root) /usr/sbin/webyastPermissionsService.rb
359 %attr(444,root,root) /usr/share/dbus-1/system-services/webyast.permissions.service.service
360 %attr(644,root,root) %config /etc/dbus-1/system.d/webyast.permissions.conf
361 %doc %{webyast_ws_dir}/README
362 %attr(-,%{webyast_ws_user},%{webyast_ws_user}) %{webyast_ws_dir}/log
363 %attr(-,%{webyast_ws_user},%{webyast_ws_user}) %{webyast_ws_dir}/tmp
364 #nginx stuff
365 %config(noreplace) /etc/yastws/nginx.conf
366 %config /etc/yastws/fastcgi.conf
367 %config /etc/yastws/fastcgi_params
368 %config /etc/yastws/koi-utf
369 %config /etc/yastws/koi-win
370 %config /etc/yastws/mime.types
371 %config /etc/yastws/scgi_params
372 %config /etc/yastws/uwsgi_params
373 %config /etc/yastws/win-utf
374
375 %config /etc/sysconfig/SuSEfirewall2.d/services/webyast
376 %config /usr/share/PolicyKit/policy/org.opensuse.yast.permissions.policy
377 %config %{webyast_ws_dir}/config/environment.rb
378 %config(noreplace) /etc/yast_user_roles
379 %config %{_sysconfdir}/init.d/%{webyast_ws_service}
380 %{_sbindir}/rc%{webyast_ws_service}
381 %doc COPYING
382 %ghost %attr(755,root,root) /var/adm/update-scripts/%name-%version-%release-1
383
384 %files testsuite
385 %defattr(-,root,root)
386 %{webyast_ws_dir}/test
387
388 #---------------------------------------------------------------
389 %changelog