Skip to content

Commit

Permalink
Updates rpm and deb distribution to adapt to admin password change
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Jan 9, 2024
1 parent 8897650 commit c375c21
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions scripts/pkg/build_templates/opensearch/deb/debian/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ pid_dir=/var/run/opensearch

# Apply Security Settings
if [ -d ${product_dir}/plugins/opensearch-security ]; then
set +e
bash ${product_dir}/plugins/opensearch-security/tools/install_demo_configuration.sh -y -i -s > ${log_dir}/install_demo_configuration.log 2>&1
DEMO_INSTALLER_EXIT_CODE=$?
set -e
# The demo script will throw exit code -1 in case of error. Hence we are checking for 255 here (i.e. 256 minus 1)
if [ $DEMO_INSTALLER_EXIT_CODE == 255 ]; then
echo "Something went wrong during demo configuration installation. Please see the logs in ${log_dir}/install_demo_configuration.log."
exit $DEMO_INSTALLER_EXIT_CODE
fi
fi

# Apply PerformanceAnalyzer Settings
Expand Down
11 changes: 11 additions & 0 deletions scripts/pkg/build_templates/opensearch/deb/debian/preinst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ if command -v systemctl >/dev/null && systemctl is-active opensearch-performance
systemctl --no-reload stop opensearch-performance-analyzer.service
fi

# Check if OPENSEARCH_INITIAL_ADMIN_PASSWORD is defined
# NOTE:
# 1. This check will need to be modified if there will be a min dist for deb in future (currently there is none)
# 2. Currently, the demo config setup is defined to run, in postinst, if `opensearch-security` is present. Cannot apply the same check here since the plugins folder is not available yet.
# 3. There is no version check here as it assumes that this change will be present in preinst scripts for deb distribution of OpenSearch 2.12 and later
if [ -z "$OPENSEARCH_INITIAL_ADMIN_PASSWORD" ]; then
echo "Opensearch 2.12 and later requires the env variable OPENSEARCH_INITIAL_ADMIN_PASSWORD to be defined to setup the opensearch-security demo configuration"
exit -1
fi


# Create user and group if they do not already exist.
getent group opensearch > /dev/null 2>&1 || groupadd -r opensearch
getent passwd opensearch > /dev/null 2>&1 || \
Expand Down
19 changes: 19 additions & 0 deletions scripts/pkg/build_templates/opensearch/rpm/opensearch.rpm.spec
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ if command -v systemctl >/dev/null && systemctl is-active opensearch-performance
echo "Stop existing opensearch-performance-analyzer.service"
systemctl --no-reload stop opensearch-performance-analyzer.service
fi

# Check if OPENSEARCH_INITIAL_ADMIN_PASSWORD is defined
# NOTE:
# 1. This check will need to be modified if there will be a min dist for rpm in future (currently there is none)
# 2. Currently, the demo config setup is defined to run, in postinstall, if `opensearch-security` is present. Cannot apply the same check here since the plugins folder is not available yet.
# 3. There is no version check here as it assumes that this change will be present in preinst scripts for rpm distribution of OpenSearch 2.12 and later
if [ -z "$OPENSEARCH_INITIAL_ADMIN_PASSWORD" ]; then
echo "Opensearch 2.12 and later requires the env variable OPENSEARCH_INITIAL_ADMIN_PASSWORD to be defined to setup the opensearch-security demo configuration"
exit -1
fi

# Create user and group if they do not already exist.
getent group %{name} > /dev/null 2>&1 || groupadd -r %{name}
getent passwd %{name} > /dev/null 2>&1 || \
Expand All @@ -100,7 +111,15 @@ exit 0
set -e
# Apply Security Settings
if [ -d %{product_dir}/plugins/opensearch-security ]; then
set +e
sh %{product_dir}/plugins/opensearch-security/tools/install_demo_configuration.sh -y -i -s > %{log_dir}/install_demo_configuration.log 2>&1
DEMO_INSTALLER_EXIT_CODE=$?
set -e
# The demo script will throw exit code -1 in case of error. Hence we are checking for 255 here (i.e. 256 minus 1)
if [ $DEMO_INSTALLER_EXIT_CODE == 255 ]; then
echo "Something went wrong during demo configuration installation. Please see the logs in %{log_dir}/install_demo_configuration.log."
exit $DEMO_INSTALLER_EXIT_CODE
fi
fi
chown -R %{name}.%{name} %{config_dir}
chown -R %{name}.%{name} %{log_dir}
Expand Down

0 comments on commit c375c21

Please sign in to comment.