-
Notifications
You must be signed in to change notification settings - Fork 24
/
rudder-server.spec
434 lines (358 loc) · 13.7 KB
/
rudder-server.spec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
#####################################################################################
# Copyright 2011- Normation SAS
#####################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#####################################################################################
#=================================================
# Specification file for rudder-server
#
# Installs a Rudder server
#
# Copyright (C) 2011- Normation
#=================================================
#=================================================
# Variables
#=================================================
%define real_name rudder-server
%define old_epoch 1398866025
%define maven_settings settings-external.xml
%define apache_conf_dir %{apache}/conf.d
# Reference for suse_version : https://en.opensuse.org/openSUSE:Build_Service_cross_distribution_howto
%if 0%{?suse_version}
%define apache apache2
%define apache_tools apache2-utils
%define htpasswd_cmd htpasswd2
%define ldap_clients openldap2-client
%define jetty_init_script jetty-sles.sh
%define apache_vhost_dir %{apache}/vhosts.d
%endif
%if 0%{?rhel}
%define apache httpd
%define apache_tools httpd-tools
%define htpasswd_cmd htpasswd
%define ldap_clients openldap-clients
%define jetty_init_script jetty-rpm.sh
%define apache_vhost_dir %{apache}/conf.d
%endif
# avoid error during byte compilation of pyc since they are removed anyway
%define _python_bytecompile_errors_terminate_build 0
#=================================================
# Header
#=================================================
Summary: Configuration management and audit tool - server package
Name: %{real_name}
Version: %{real_version}
Release: 1%{?dist}
Epoch: 0
License: GPLv3
URL: https://www.rudder.io/
Group: Applications/System
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
AutoReq: 0
AutoProv: 0
Obsoletes: rudder-server-root < 7.2
Obsoletes: rudder-webapp < 7.2
Obsoletes: rudder-reports < 7.2
Requires: %(../format-dependencies rpm %{old_epoch}:%{real_version} rudder-agent)
Requires: %(../format-dependencies rpm %{real_version} rudder-relay)
Requires: %{apache}, %{apache_tools}, git-core, iproute, rsync, openssl, %{ldap_clients}, curl, acl, rudder-api-client
%if 0%{?rhel} && 0%{?rhel} == 7
# rudder-external-db will not prevent installation of postgresql-server on rhel7
Requires: postgresql-server
%else
# rudder-external-db must prevent installation of postgresql-server
Requires: (postgresql-server >= 10.3 or rudder-external-db)
%endif
BuildRequires: gcc, rsync
# OS-specific dependencies
## RHEL
%if 0%{?rhel}
BuildRequires: selinux-policy-devel
Requires: mod_ssl httpd shadow-utils
Requires: jre-headless >= 11
Requires: perl-Digest-SHA libtool-ltdl
BuildRequires: openssl-devel libtool-ltdl-devel
%endif
## SLES
%if 0%{?suse_version}
Requires: apache2 pwdutils libltdl7
BuildRequires: libopenssl-devel
%endif
%if 0%{?sle_version} && 0%{?sle_version} >= 150000
Requires: jre-headless >= 11
%endif
## Python 3
%if 0%{?rhel} && 0%{?rhel} == 7
BuildRequires: python
Requires: python
%endif
%if 0%{?rhel} && 0%{?rhel} == 8
BuildRequires: python3
Requires: python3
%endif
# Doc for suse versioning https://en.opensuse.org/openSUSE:Packaging_for_Leap
%if 0%{?suse_version} && 0%{?suse_version} < 1500
BuildRequires: python
Requires: python, python-pyOpenSSL
%endif
%if 0%{?suse_version} && 0%{?suse_version} >= 1500
BuildRequires: python3
Requires: python3
%endif
%description
Rudder is an open source configuration management and audit solution.
This package install all components required to run a Rudder root server on a machine,
including the web interface and its dependencies.
#=================================================
# Source preparation
#=================================================
%prep
cd %{_sourcedir}
make --debug rudder-sources
#=================================================
# Building
#=================================================
%build
# Ensure an appropriate environment for the compiler
export CFLAGS="$RPM_OPT_FLAGS"
cd %{_sourcedir}
make --debug build
%if 0%{?rhel}
# Build SELinux policy package
# Compiles rudder-webapp.te and rudder-webapp.fc into rudder-webapp.pp
make -f /usr/share/selinux/devel/Makefile
%endif
#=================================================
# Installation
#=================================================
%install
rm -rf %{buildroot}
cd %{_sourcedir}
make --debug install APACHE_VHOSTDIR=%{apache_vhost_dir} DESTDIR=%{buildroot} JETTY_SCRIPT=%{jetty_init_script} APACHE_CONFDIR=%{apache_conf_dir}
%if 0%{?rhel}
# Install SELinux policy
install -m 644 rudder-webapp.pp %{buildroot}/opt/rudder/share/selinux/
# Replace init script
cp jetty/bin/jetty-rpm.sh jetty/bin/jetty.sh
%else
# Replace init script
cp jetty/bin/jetty-sles.sh jetty/bin/jetty.sh
%endif
#=================================================
# pretrans is run before all preinst when installing more than one package
#=================================================
%pretrans
set -e
# We need to be sure that uuid.hive is set to root at beginning
mkdir -p /opt/rudder/etc
echo 'root' > /opt/rudder/etc/uuid.hive
mkdir -p /var/rudder/cfengine-community/
echo "127.0.0.1" > /var/rudder/cfengine-community/policy_server.dat
#=================================================
# Pre Installation
#=================================================
%pre
set -e
CFRUDDER_FIRST_INSTALL=$1
LOG_FILE="/var/log/rudder/install/%{name}.log"
echo "`date` - Starting %{name} pre installation script" >> ${LOG_FILE}
# Only do this on package upgrade
if [ $1 -ne 1 ]
then
# When upgrading OpenLDAP, we may need to dump the database
# so that it can be restored from LDIF
TIMESTAMP=`date +%%Y%%m%%d%%H%%M%%S`
# Ensure backup folder exist
mkdir -p /var/rudder/ldap/backup/
# We need it to be able to open big mdb memory-mapped databases
ulimit -v unlimited
[ -x /opt/rudder/sbin/slapcat ] && /opt/rudder/sbin/slapcat -b "cn=rudder-configuration" -l /var/rudder/ldap/backup/openldap-data-pre-upgrade-${TIMESTAMP}.ldif
# If the stops fails, it's probably because it was not started
systemctl stop rudder-jetty >&2 > /dev/null || true
if [ -x /opt/rudder/bin/rudder-pkg ]
then
/opt/rudder/bin/rudder-pkg plugin save-status > /tmp/rudder-plugins-upgrade
else
rudder package plugin save-status > /tmp/rudder-plugins-upgrade
fi
getfacl --absolute-names --recursive /opt/rudder/etc/hooks.d/ > /tmp/rudder-hooks-upgrade
else
# make sure keys and certificate are the server ones
[ -x /opt/rudder/bin/rudder ] && /opt/rudder/bin/rudder agent check -f -s keys
fi
#=================================================
# Post Installation
#=================================================
%post
set -e
RUDDER_FIRST_INSTALL="false"
%if 0%{?rhel}
# rhel does'nt initialize postgresql
DB_NOT_INITIALIZED="true"
%else
DB_NOT_INITIALIZED="false"
%endif
# Do this ONLY at first install
if [ $1 -eq 1 ]
then
RUDDER_FIRST_INSTALL="true"
echo 'DAVLockDB /tmp/davlock.db' > /etc/%{apache}/conf.d/dav_mod.conf
fi
%if 0%{?suse_version}
a2enmod rewrite dav dav_fs ssl version
# Add required includes in the apache2 configuration
nextline=$(grep -A1 -E "^. /etc/sysconfig/rudder-webapp-apache$" /etc/sysconfig/apache2 | tail -n1)
if [ "${nextline}" = "" ]; then
# No include currently
echo -e '# This sources the modules/defines needed by Rudder\n. /etc/sysconfig/rudder-webapp-apache' >> /etc/sysconfig/apache2
echo -e '# This line is necessary for fillup not to remove any lines above. See #11153\nAPACHE_RUDDER_RELAY_CUSTOMIZED="true"' >> /etc/sysconfig/apache2
fi
%endif
# Update /etc/sysconfig/apache2 in case an old module loading entry has already been created by Rudder
if [ -f /etc/sysconfig/apache2 ] && grep -q 'APACHE_MODULES="${APACHE_MODULES} rewrite dav dav_fs proxy proxy_http' /etc/sysconfig/apache2
then
echo "INFO: Upgrading the /etc/sysconfig/apache2 file, Rudder needed modules for Apache are now listed in /etc/sysconfig/rudder-webapp-apache"
sed -i 's%APACHE_MODULES="${APACHE_MODULES} rewrite dav dav_fs proxy proxy_http.*%# This sources the Rudder needed by Rudder\n. /etc/sysconfig/rudder-webapp-apache%' /etc/sysconfig/apache2
fi
if ! /opt/rudder/share/package-scripts/rudder-server-postinst "${RUDDER_FIRST_INSTALL}" "%{apache}" "${DB_NOT_INITIALIZED}"; then
echo "**************************************************************************************"
echo "ERROR: rudder-server postinstall script failed !"
echo ""
echo "Trying to recover the problem, you should check that your instance is properly working"
echo ""
echo "You should also try to manually execute: /opt/rudder/bin/rudder-upgrade"
echo ""
echo " Such errors should not happen, please open an issue for this problem on "
echo " https://issues.rudder.io/projects/rudder/issues/new"
echo "**************************************************************************************"
LOG_FILE="/var/log/rudder/install/rudder-webapp-fail-$(date +%Y%m%d%H%M%S).log"
/opt/rudder/bin/rudder-fix-repository-permissions >> ${LOG_FILE}
fi
%if 0%{?rhel}
# SELinux support
# Check "sestatus" presence, and if here tweak our installation to be
# SELinux compliant
if type sestatus >/dev/null 2>&1 && sestatus | grep -q "enabled"; then
# Add/Update the rudder-webapp SELinux policy
semodule -i /opt/rudder/share/selinux/rudder-webapp.pp
# Ensure inventory directories context is set by resetting
# their context to the contexts defined in SELinux configuration,
# including the file contexts defined in the rudder-webapp module
restorecon -RF /var/rudder/configuration-repository/techniques
fi
%endif
#=================================================
# Pre Un-installation
#=================================================
%preun
set -e
if [[ $1 -eq 0 ]]
then
systemctl stop rudder-jetty
systemctl stop rudder-slapd
fi
#=================================================
# Post Uninstallation
#=================================================
%postun
set -e
# Do it only during uninstallation
if [ $1 -eq 0 ]; then
# Clean up all logrotate leftovers
rm -rf %{_sysconfdir}/logrotate.d/rudder*
%if 0%{?suse_version}
# Remove required includes in the SLES apache2 configuration
if [ -f /etc/sysconfig/apache2 ]; then
sed -i "/# This sources the modules\/defines needed by Rudder/d" /etc/sysconfig/apache2
sed -i "/. \/etc\/sysconfig\/rudder-webapp-apache/d" /etc/sysconfig/apache2
# Also remove an older comment that was erroneously added until 2.11.21 / 3.0.16 / 3.1.10 / 3.2.3
sed -i "/# This sources the configuration file needed by Rudder/d" /etc/sysconfig/apache2
fi
%endif
%if 0%{?rhel}
if type sestatus >/dev/null 2>&1 && sestatus | grep -q "enabled"; then
if semodule -l | grep -q rudder-webapp; then
# Remove the rudder-webapp SELinux policy
semodule -r rudder-webapp
restorecon -RF /var/rudder/configuration-repository/techniques
fi
fi
%endif
if getent passwd rudder-slapd >/dev/null; then
userdel rudder-slapd >/dev/null 2>&1
fi
fi
#=================================================
# Post transaction
#=================================================
%posttrans
set -e
# during upgrade, service may have been stopped by uninstall of rudder-inventory-ldap or rudder-jetty
# 7.2 should not happen anymore
systemctl start rudder-slapd >/dev/null
systemctl start rudder-jetty >/dev/null
#=================================================
# Cleaning
#=================================================
%clean
rm -rf %{buildroot}
#=================================================
# Files
#=================================================
%files
%defattr(-, root, root, 0755)
/opt/rudder/share/package-scripts/rudder-server-postinst
/usr/lib/systemd/system/rudder-server.service
/opt/rudder/share/versions/rudder-server-version
/opt/rudder/etc/postgresql/reportsSchema.sql
/opt/rudder/share/package-scripts/
%config(noreplace) /opt/rudder/etc/openldap/slapd.conf
%config(noreplace) /etc/rsyslog.d/rudder-slapd.conf
%config(noreplace) /opt/rudder/etc/rudder-web.properties
%config(noreplace) /opt/rudder/etc/rudder-users.xml
%config(noreplace) /opt/rudder/etc/logback.xml
%config(noreplace) /opt/rudder/etc/rudder-passwords.conf
%config(noreplace) /etc/default/rudder-jetty
%attr(0600, root, root) /opt/rudder/etc/rudder-passwords.conf
/usr/lib/systemd/system/
/opt/rudder/jetty
/opt/rudder/etc
/opt/rudder/bin
/opt/rudder/sbin
/opt/rudder/share
/opt/rudder/share
/opt/rudder/include
/opt/rudder/lib
/opt/rudder/var
/opt/rudder/libexec
/var/rudder/ldap/openldap-data
/var/rudder/run
/var/rudder/inventories/received
/var/log/rudder/ldap
/var/log/rudder/apache2/
/var/log/rudder/webapp/
/etc/%{apache_vhost_dir}/
%config /opt/rudder/etc/rudder-apache-webapp-common.conf
%config /opt/rudder/etc/rudder-apache-webapp-ssl.conf
%config /opt/rudder/etc/rudder-apache-webapp-nossl.conf
%config(noreplace) /etc/sysconfig/rudder-webapp-apache
/usr/share/doc/rudder
/usr/share/ncf/
#=================================================
# Changelog
#=================================================
%changelog
* Wed Nov 22 2017 - Rudder Team <dev@rudder.io> %{version}
- See https://docs.rudder.io/changelogs/current/index.html for changelogs