Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #14020: Update rudder server root to match modern packaging recommendation #1746

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rudder-inventory-ldap/SOURCES/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ endif
# Pass an empty string to skip hash check
GET=get() { $(_GET) "$$1.part" "$$2" && { openssl dgst -sha256 "$$1.part" | grep -q "$$3" || { echo "Wrong checksum, aborting"; exit 1; }; } && mv "$$1.part" "$$1"; }; get

DESTDIR = $(CURDIR)/target

localdepends: openldap-source

openldap-source:
Expand Down Expand Up @@ -97,6 +99,7 @@ localclean:
rm -rf rudder-sources
rm -rf openldap-source

distclean: veryclean
veryclean: clean
rm -f ./rudder-sources.tar.bz2

Expand Down
6 changes: 3 additions & 3 deletions rudder-inventory-ldap/SPECS/rudder-inventory-ldap.spec
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ rm -rf %{buildroot}

make install DESTDIR=%{buildroot}

%pre -n rudder-inventory-ldap
#=================================================
# Pre Installation
#=================================================
%pre -n rudder-inventory-ldap

# Only do this on package upgrade
if [ $1 -ne 1 ]
Expand All @@ -126,10 +126,10 @@ if [ $1 -ne 1 ]
/opt/rudder/sbin/slapcat -b "cn=rudder-configuration" -l /var/rudder/ldap/backup/openldap-data-pre-upgrade-${TIMESTAMP}.ldif
fi

%post -n rudder-inventory-ldap
#=================================================
# Post Installation
#=================================================
%post -n rudder-inventory-ldap

# ldconfig only necessary when upgrading from 4.1 to >4.2
if [[ $1 -gt 1 ]]; then
Expand All @@ -150,10 +150,10 @@ echo -n "INFO: Restarting rudder-slapd..."
systemctl restart rudder-slapd >/dev/null
echo " Done"

%preun -n rudder-inventory-ldap
#=================================================
# Pre Un-installation
#=================================================
%preun -n rudder-inventory-ldap

if [[ $1 -eq 0 ]]
then
Expand Down
Empty file removed rudder-reports/BUILD/.placeholder
Empty file.
Empty file removed rudder-reports/RPMS/.placeholder
Empty file.
53 changes: 45 additions & 8 deletions rudder-reports/SOURCES/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,60 @@
#
#####################################################################################

.DEFAULT_GOAL := localdepends
.DEFAULT_GOAL := build

RUDDER_VERSION_TO_PACKAGE = <put Rudder version or version-snapshot here>

localdepends: ./rudder-sources
# GENERIC_GET: do not remove this line
# This is a generic get code that is common to many of our Makefiles.
# The tag is here to find them. Rudder agent has an even more generic one.
# If you change this code, change all the places where you can find this tag too.
# It is duplicated because it is the code that is used to manage dependency
# to other repositories, hence allowing deduplication of other code.
# Autodetect wget, curl or fetch usage and proxy configuration
# Usage: $(GET) <destination_file> <url> <hash>
PROXY_ENV = $(if $(PROXY), http_proxy=$(PROXY) ftp_proxy=$(PROXY))
# No accept encoding to prevent the webserver form altering the distributed file
WGET = wget -q --header="accept-encoding:" -O
CURL = curl -s -L -o
ifneq (,$(wildcard /usr/bin/curl))
_GET = $(PROXY_ENV) $(CURL)
else
_GET = $(PROXY_ENV) $(WGET)
endif
# Pass an empty string to skip hash check
GET=get() { $(_GET) "$$1.part" "$$2" && { openssl dgst -sha256 "$$1.part" | grep -q "$$3" || { echo "Wrong checksum, aborting"; exit 1; }; } && mv "$$1.part" "$$1"; }; get

./rudder-sources.tar.bz2:
$(WGET) -O rudder-sources.tar.bz2 https://www.rudder-project.org/archives/rudder-sources-${RUDDER_VERSION_TO_PACKAGE}.tar.bz2
DESTDIR = $(CURDIR)/target

./rudder-sources: ./rudder-sources.tar.bz2
localdepends:

rudder-sources.tar.bz2:
$(GET) rudder-sources.tar.bz2 https://repository.rudder.io/sources/$(RUDDER_VERSION_TO_PACKAGE)/rudder-sources-$(RUDDER_VERSION_TO_PACKAGE).tar.bz2 ""

rudder-sources: rudder-sources.tar.bz2
tar -xjf rudder-sources.tar.bz2
mv rudder-sources-*/ rudder-sources/

build: rudder-sources
touch $@

# Install into DESTDIR
install: build
mkdir -p $(DESTDIR)/opt/rudder/etc/postgresql/
mkdir -p $(DESTDIR)/opt/rudder/etc/server-roles.d/
mkdir -p $(DESTDIR)/opt/rudder/share/package-scripts/
install -m 644 rudder-sources/rudder/rudder-core/src/main/resources/reportsSchema.sql $(DESTDIR)/opt/rudder/etc/postgresql/
install -m 644 rudder-reports $(DESTDIR)/opt/rudder/etc/server-roles.d/
install -m 644 rudder-db $(DESTDIR)/opt/rudder/etc/server-roles.d/
install -m 755 rudder-reports-postinst $(DESTDIR)/opt/rudder/share/package-scripts/

clean: localclean
localclean:
rm -rf ./rudder-sources
rm -rf rudder-sources

veryclean:
distclean: veryclean
veryclean: clean
rm -f ./rudder-sources.tar.bz2

.PHONY: localclean localdepends veryclean
.PHONY: build install clean localclean localdepends veryclean
100 changes: 100 additions & 0 deletions rudder-reports/SOURCES/rudder-reports-postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/bash

DB_NOT_INITIALIZED="$1"

# Try with systemd
POSTGRESQL_SERVICE_NAME=$(systemctl list-unit-files --type service | awk -F'.' '{print $1}' | grep -E "^postgresql[0-9]*$" | tail -n 1)

# If nothing try with chkconfig (sles 12 only)
if [ -z "${POSTGRESQL_SERVICE_NAME}" ] && ! type chkconfig >/dev/null 2>/dev/null ; then
POSTGRESQL_SERVICE_NAME=$(chkconfig 2>/dev/null | awk '{ print $1 }' | grep "postgresql" | tail -n 1)
fi

# If nothin try default name (should not happen)
if [ -z "${POSTGRESQL_SERVICE_NAME}" ]; then
POSTGRESQL_SERVICE_NAME="postgresql"
fi

# Check if PostgreSQL is started
systemctl status ${POSTGRESQL_SERVICE_NAME} > /dev/null

# Start if necessary
if [ $? -ne 0 ]
then
if [ "${DB_NOT_INITIALIZED}" != "" ]; then
echo -n "INFO: Initializing PostgreSQL ..."
# rhel package doesn't initialize database
service ${POSTGRESQL_SERVICE_NAME} initdb
echo " Done"
fi
systemctl start ${POSTGRESQL_SERVICE_NAME} >/dev/null
fi

# TODO RPM only ??
PG_HBA_FILE=$(su - postgres -c "psql -t -P format=unaligned -c 'show hba_file';")
if [ $? -ne 0 ]; then
echo "Postgresql failed to start! Halting"
exit 1
fi

#HACK: Give rights for login without unix account
if [ -f ${PG_HBA_FILE} ]; then
RUDDER_PG_DEFINED=`grep "rudder" ${PG_HBA_FILE} | wc -l`
if [ ${RUDDER_PG_DEFINED} -le 0 ]; then
sed -i 1i"host all rudder ::1/128 md5" ${PG_HBA_FILE}
sed -i 1i"host all rudder 127.0.0.1/32 md5" ${PG_HBA_FILE}

# Apply changes in PostgreSQL
# TODO just after a start ?
systemctl reload ${POSTGRESQL_SERVICE_NAME}
fi
fi
# ODOT

# RHEL doesn't autostart service
if [ "${DB_NOT_INITIALIZED}" != "" ]; then
echo -n "INFO: Setting PostgreSQL as a boot service..."
systemctl enable ${POSTGRESQL_SERVICE_NAME} >/dev/null
echo " Done"
fi


echo -n "INFO: Waiting for PostgreSQL to be up..."
CPT=0
TIMEOUT=60
while ! su - postgres -c "psql -q --output /dev/null -c \"SELECT COUNT(*) FROM pg_catalog.pg_authid\"" >/dev/null 2>&1
do
echo -n "."
sleep 1
CPT=$((${CPT}+1))
if [ ${CPT} -eq ${TIMEOUT} ]
then
echo -e "\nERROR: Connection to PostgreSQL has not been established before timeout. Exiting"
exit 1
fi
done
echo " Done"

DBNAME="rudder"
USERNAME="rudder"
CHK_PG_DB=$(su - postgres -c "psql -t -c \"select count(1) from pg_catalog.pg_database where datname = '${DBNAME}'\"")
CHK_PG_USER=$(su - postgres -c "psql -t -c \"select count(1) from pg_user where usename = '${USERNAME}'\"")

# Rudder user
if [ ${CHK_PG_USER} -eq 0 ]
then
echo -n "INFO: Creating Rudder PostgreSQL user..."
su - postgres -c "psql -q -c \"CREATE USER ${USERNAME} WITH PASSWORD 'Normation'\"" >/dev/null 2>&1
echo "Done"
fi

# Rudder database
if [ ${CHK_PG_DB} -eq 0 ]
then
echo -n "INFO: Creating Rudder PostgreSQL database..."
su - postgres -c "psql -q -c \"CREATE DATABASE ${DBNAME} WITH OWNER = ${USERNAME}\"" >/dev/null 2>&1
echo "localhost:5432:${DBNAME}:${USERNAME}:Normation" > /root/.pgpass
chmod 600 /root/.pgpass
psql -q -U rudder -h localhost -d rudder -f /opt/rudder/etc/postgresql/reportsSchema.sql >/dev/null 2>&1
echo " Done"
fi
124 changes: 10 additions & 114 deletions rudder-reports/SPECS/rudder-reports.spec
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
%define real_name rudder-reports
%define real_epoch 1398866025

%define rudderdir /opt/rudder
%define ruddervardir /var/rudder
%define rudderlogdir /var/log/rudder
%define suse_rsyslog_pgsql rsyslog-module-pgsql

#=================================================
# Header
#=================================================
Expand All @@ -48,20 +43,15 @@ URL: http://www.rudder-project.org

Group: Applications/System

Source1: rudder-sources
Source2: rudder-reports
Source3: rudder-db

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildArch: noarch


Requires: postgresql-server >= 9.2
Requires: rsyslog >= 4

# Reference for suse_version : https://en.opensuse.org/openSUSE:Build_Service_cross_distribution_howto
%if 0%{?suse_version}
Requires: %{suse_rsyslog_pgsql} >= 4
Requires: rsyslog-module-pgsql >= 4
%endif

%if 0%{?rhel}
Expand All @@ -76,11 +66,6 @@ sent from nodes managed with Rudder. These reports are used by rudder-webapp to
calculate compliance to given configuration rules.


#=================================================
# Source preparation
#=================================================
%prep

#=================================================
# Building
#=================================================
Expand All @@ -91,111 +76,21 @@ calculate compliance to given configuration rules.
#=================================================
%install
rm -rf %{buildroot}
# Directories
mkdir -p %{buildroot}%{rudderdir}/etc/postgresql/
mkdir -p %{buildroot}%{rudderdir}/etc/server-roles.d/

cp %{SOURCE1}/rudder/rudder-core/src/main/resources/reportsSchema.sql %{buildroot}%{rudderdir}/etc/postgresql/

install -m 644 %{SOURCE2} %{buildroot}/opt/rudder/etc/server-roles.d/
install -m 644 %{SOURCE3} %{buildroot}/opt/rudder/etc/server-roles.d/

%pre -n rudder-reports
#=================================================
# Pre Installation
#=================================================
make install DESTDIR=%{buildroot}


%post -n rudder-reports
#=================================================
# Post Installation
#=================================================
%post -n rudder-reports

POSTGRESQL_SERVICE_NAME=$(systemctl list-unit-files --type service | awk -F'.' '{print $1}' | grep -E "^postgresql[0-9]*$" | tail -n 1)
%if 0%{?suse_version} < 1500
POSTGRESQL_SERVICE_NAME=$(chkconfig 2>/dev/null | awk '{ print $1 }' | grep "postgresql" | tail -n 1)
%endif

if [ -z "${POSTGRESQL_SERVICE_NAME}" ]; then
POSTGRESQL_SERVICE_NAME="postgresql"
fi

# Check if PostgreSQL is started
systemctl status ${POSTGRESQL_SERVICE_NAME}

if [ $? -ne 0 ]; then
%if 0%{?rhel}
echo -n "INFO: Initializing PostgreSQL ..."
# rhel package doesn't initialize database
service ${POSTGRESQL_SERVICE_NAME} initdb
echo " Done"
%endif
systemctl start ${POSTGRESQL_SERVICE_NAME}
fi

PG_HBA_FILE=$(su - postgres -c "psql -t -P format=unaligned -c 'show hba_file';")
if [ $? -ne 0 ]; then
echo "Postgresql failed to start! Halting"
exit 1
fi

#HACK: Give rights for login without unix account
if [ -f ${PG_HBA_FILE} ]; then
RUDDER_PG_DEFINED=`grep "rudder" ${PG_HBA_FILE} | wc -l`
if [ ${RUDDER_PG_DEFINED} -le 0 ]; then
sed -i 1i"host all rudder ::1/128 md5" ${PG_HBA_FILE}
sed -i 1i"host all rudder 127.0.0.1/32 md5" ${PG_HBA_FILE}

# Apply changes in PostgreSQL
systemctl reload ${POSTGRESQL_SERVICE_NAME}
fi
fi

echo -n "INFO: Setting PostgreSQL as a boot service..."
%if 0%{?rhel}
systemctl enable ${POSTGRESQL_SERVICE_NAME} >/dev/null
/opt/rudder/share/package-scripts/rudder-reports-postinst true
%else
/opt/rudder/share/package-scripts/rudder-reports-postinst
%endif
echo " Done"

echo -n "INFO: Waiting for PostgreSQL to be up..."
CPT=0
TIMEOUT=60
while ! su - postgres -c "psql -q --output /dev/null -c \"SELECT COUNT(*) FROM pg_catalog.pg_authid\"" >/dev/null 2>&1
do
echo -n "."
sleep 1
CPT=$((${CPT}+1))
if [ ${CPT} -eq ${TIMEOUT} ]
then
echo -e "\nERROR: Connection to PostgreSQL has not been established before timeout. Exiting"
exit 1
fi
done
echo " Done"

DBNAME="rudder"
USERNAME="rudder"
CHK_PG_DB=$(su - postgres -c "psql -t -c \"select count(1) from pg_catalog.pg_database where datname = '${DBNAME}'\"")
CHK_PG_USER=$(su - postgres -c "psql -t -c \"select count(1) from pg_user where usename = '${USERNAME}'\"")

# Rudder user
if [ ${CHK_PG_USER} -eq 0 ]
then
echo -n "INFO: Creating Rudder PostgreSQL user..."
su - postgres -c "psql -q -c \"CREATE USER ${USERNAME} WITH PASSWORD 'Normation'\"" >/dev/null 2>&1
echo " Done"
fi

# Rudder database
if [ ${CHK_PG_DB} -eq 0 ]
then
echo -n "INFO: Creating Rudder PostgreSQL database..."
su - postgres -c "psql -q -c \"CREATE DATABASE ${DBNAME} WITH OWNER = ${USERNAME}\"" >/dev/null 2>&1
echo "localhost:5432:${DBNAME}:${USERNAME}:Normation" > /root/.pgpass
chmod 600 /root/.pgpass
psql -q -U rudder -h localhost -d rudder -f %{rudderdir}/etc/postgresql/reportsSchema.sql >/dev/null 2>&1
echo " Done"
fi


#=================================================
# Cleaning
Expand All @@ -208,8 +103,9 @@ rm -rf %{buildroot}
#=================================================
%files -n rudder-reports
%defattr(-, root, root, 0755)
%{rudderdir}/etc/postgresql/reportsSchema.sql
%{rudderdir}/etc/server-roles.d/
/opt/rudder/etc/postgresql/reportsSchema.sql
/opt/rudder/etc/server-roles.d/
/opt/rudder/share/package-scripts/

#=================================================
# Changelog
Expand Down
Empty file removed rudder-reports/SRPMS/.placeholder
Empty file.
Loading