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

Update RPM spec file to avoid overwriting modified config files #410

Merged
merged 8 commits into from
Sep 19, 2024
7 changes: 7 additions & 0 deletions distribution/packages/src/deb/debian/postinst
AlexRuiz7 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ tmp_dir=/var/log/wazuh-indexer/tmp
# Create needed directories
mkdir -p ${tmp_dir}

# Create config files only if not already present
cp -n /etc/init.d/wazuh-indexer.new /etc/init.d/wazuh-indexer
cp -n ${config_dir}/jvm.options.new ${config_dir}/jvm.options
cp -n ${config_dir}/opensearch.yml.new ${config_dir}/opensearch.yml
cp -n ${config_dir}/opensearch-security/roles.yml.new ${config_dir}/opensearch-security/roles.yml
cp -n ${config_dir}/opensearch-security/internal_users.yml.new ${config_dir}/opensearch-security/internal_users.yml

# Set owner
chown -R wazuh-indexer:wazuh-indexer ${product_dir}
chown -R wazuh-indexer:wazuh-indexer ${config_dir}
Expand Down
12 changes: 12 additions & 0 deletions distribution/packages/src/deb/debmake_install.sh
AlexRuiz7 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,17 @@ for i in "${binary_files[@]}"; do
chmod -c 750 "$i"
done

# Append ".new" to configuration file names
dot_new_config_files=()
dot_new_config_files+=("${buildroot}/etc/init.d/${name}")
dot_new_config_files+=("${buildroot}/${config_dir}/jvm.options")
dot_new_config_files+=("${buildroot}/${config_dir}/opensearch.yml")
dot_new_config_files+=("${buildroot}/${config_dir}/opensearch-security/roles.yml")
dot_new_config_files+=("${buildroot}/${config_dir}/opensearch-security/internal_users.yml")
f-galland marked this conversation as resolved.
Show resolved Hide resolved

for i in "${dot_new_config_files[@]}"
do
mv "$i" "$i.new"
done

exit 0
27 changes: 21 additions & 6 deletions distribution/packages/src/rpm/wazuh-indexer.rpm.spec
AlexRuiz7 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ if [ ! -f %{buildroot}%{data_dir}/performance_analyzer_enabled.conf ]; then
echo 'true' > %{buildroot}%{data_dir}/performance_analyzer_enabled.conf
fi

# Append ".new" to configuration file names
mv "%{buildroot}/etc/init.d/%{name}" "%{buildroot}/etc/init.d/%{name}.new"
mv "%{buildroot}/%{config_dir}/jvm.options" "%{buildroot}/%{config_dir}/jvm.options.new"
mv "%{buildroot}/%{config_dir}/opensearch.yml" "%{buildroot}/%{config_dir}/opensearch.yml.new"
mv "%{buildroot}/%{config_dir}/opensearch-security/roles.yml" "%{buildroot}/%{config_dir}/opensearch-security/roles.yml.new"
mv "%{buildroot}/%{config_dir}/opensearch-security/internal_users.yml" "%{buildroot}/%{config_dir}/opensearch-security/internal_users.yml.new"

# Build a filelist to be included in the %files section
echo '%defattr(640, %{name}, %{name}, 750)' > filelist.txt
find %{buildroot} -type d >> filelist.txt
Expand Down Expand Up @@ -117,8 +124,8 @@ set -- "$@" "%%dir /usr/lib/sysctl.d"
set -- "$@" "%%dir /usr/lib/systemd"
set -- "$@" "%{_sysconfdir}/sysconfig/%{name}"
set -- "$@" "%{config_dir}/log4j2.properties"
set -- "$@" "%{config_dir}/jvm.options"
set -- "$@" "%{config_dir}/opensearch.yml"
set -- "$@" "%{config_dir}/jvm.options.new"
set -- "$@" "%{config_dir}/opensearch.yml.new"
set -- "$@" "%{product_dir}/VERSION"
set -- "$@" "%{product_dir}/plugins/opensearch-security/tools/.*\.sh"
set -- "$@" "%{product_dir}/bin/.*"
Expand All @@ -131,7 +138,7 @@ set -- "$@" "%{product_dir}/README.md"
set -- "$@" "%{product_dir}/LICENSE.txt"
set -- "$@" "%{_prefix}/lib/systemd/system/%{name}.service"
set -- "$@" "%{_prefix}/lib/systemd/system/%{name}-performance-analyzer.service"
set -- "$@" "%{_sysconfdir}/init.d/%{name}"
set -- "$@" "%{_sysconfdir}/init.d/%{name}.new"
set -- "$@" "%{_sysconfdir}/sysconfig/%{name}"
set -- "$@" "%{_prefix}/lib/sysctl.d/%{name}.conf"
set -- "$@" "%{_prefix}/lib/tmpfiles.d/%{name}.conf"
Expand Down Expand Up @@ -191,6 +198,14 @@ if ! grep -q '## OpenSearch Performance Analyzer' %{config_dir}/jvm.options; the
echo "-Djava.security.policy=file://%{config_dir}/opensearch-performance-analyzer/opensearch_security.policy" >> %{config_dir}/jvm.options
echo "--add-opens=jdk.attach/sun.tools.attach=ALL-UNNAMED" >> %{config_dir}/jvm.options
fi

# Create config files only if not already present
cp -n /etc/init.d/wazuh-indexer.new /etc/init.d/wazuh-indexer
cp -n %{config_dir}/jvm.options.new %{config_dir}/jvm.options
cp -n %{config_dir}/opensearch.yml.new %{config_dir}/opensearch.yml
cp -n %{config_dir}/opensearch-security/roles.yml.new %{config_dir}/opensearch-security/roles.yml
cp -n %{config_dir}/opensearch-security/internal_users.yml.new %{config_dir}/opensearch-security/internal_users.yml

# Reload systemctl daemon
if command -v systemctl > /dev/null; then
systemctl daemon-reload
Expand Down Expand Up @@ -234,16 +249,16 @@ exit 0
# Service files
%attr(0644, root, root) %{_prefix}/lib/systemd/system/%{name}.service
%attr(0644, root, root) %{_prefix}/lib/systemd/system/%{name}-performance-analyzer.service
%attr(0750, root, root) %{_sysconfdir}/init.d/%{name}
%attr(0750, root, root) %{_sysconfdir}/init.d/%{name}.new
%attr(0644, root, root) %config(noreplace) %{_prefix}/lib/sysctl.d/%{name}.conf
%attr(0644, root, root) %config(noreplace) %{_prefix}/lib/tmpfiles.d/%{name}.conf


# Configuration files
%attr(660, %{name}, %{name}) %{config_dir}/jvm.options.new
%attr(660, %{name}, %{name}) %{config_dir}/opensearch.yml.new
f-galland marked this conversation as resolved.
Show resolved Hide resolved
%config(noreplace) %attr(0660, root, %{name}) "%{_sysconfdir}/sysconfig/%{name}"
%config(noreplace) %attr(660, %{name}, %{name}) %{config_dir}/log4j2.properties
%config(noreplace) %attr(660, %{name}, %{name}) %{config_dir}/jvm.options
%config(noreplace) %attr(660, %{name}, %{name}) %{config_dir}/opensearch.yml


%if %observability_plugin
Expand Down
2 changes: 1 addition & 1 deletion packaging_scripts/assemble.sh
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ function main() {
echo "Assembling wazuh-indexer for $PLATFORM-$DISTRIBUTION-$ARCHITECTURE"

VERSION=$(bash packaging_scripts/upstream_version.sh)
ARTIFACT_BUILD_NAME=$(ls "${OUTPUT}/dist/" | grep "wazuh-indexer-min.*$SUFFIX.*\.$EXT")
ARTIFACT_BUILD_NAME=$(ls "${OUTPUT}/dist/" | grep "wazuh-indexer-min-$(<VERSION).*$SUFFIX.*\.$EXT")
AlexRuiz7 marked this conversation as resolved.
Show resolved Hide resolved
ARTIFACT_PACKAGE_NAME=${ARTIFACT_BUILD_NAME/-min/}

# Create temporal directory and copy the min package there for extraction
Expand Down
2 changes: 1 addition & 1 deletion packaging_scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function main() {
# Copy artifact to dist folder in bundle build output
echo "Copying artifact to ${OUTPUT}/dist"
local build_name
build_name=$(ls "distribution/$TYPE/$TARGET/build/distributions/" | grep "wazuh-indexer-min.*$SUFFIX.$EXT")
build_name=$(ls "distribution/$TYPE/$TARGET/build/distributions/" | grep "wazuh-indexer-min-$(<VERSION).*$SUFFIX.$EXT" | tr -d "\n")
AlexRuiz7 marked this conversation as resolved.
Show resolved Hide resolved
local package_name=${NAME:-$build_name}
mkdir -p "${OUTPUT}/dist"
cp "distribution/$TYPE/$TARGET/build/distributions/$build_name" "${OUTPUT}/dist/$package_name"
Expand Down