diff --git a/scripts/components/OpenSearch/install.sh b/scripts/components/OpenSearch/install.sh index 7b384c939d..201a9edf35 100755 --- a/scripts/components/OpenSearch/install.sh +++ b/scripts/components/OpenSearch/install.sh @@ -84,6 +84,9 @@ if [ "$DISTRIBUTION" = "tar" ]; then elif [ "$DISTRIBUTION" = "deb" -o "$DISTRIBUTION" = "rpm" ]; then cp -va ../../../scripts/pkg/service_templates/opensearch/* "$OUTPUT/../" cp -va ../../../scripts/pkg/build_templates/opensearch/$DISTRIBUTION/* "$OUTPUT/../" + if [ "$DISTRIBUTION" = "deb" ]; then + sed -i "s/CHANGE_VERSION/${VERSION}/g" "$OUTPUT/../debian/preinst" + fi elif [ "$DISTRIBUTION" = "zip" ] && [ "$PLATFORM" = "windows" ]; then cp -v ../../../scripts/startup/zip/windows/opensearch-windows-install.bat "$OUTPUT/" fi diff --git a/scripts/pkg/build_templates/opensearch/deb/debian/postinst b/scripts/pkg/build_templates/opensearch/deb/debian/postinst index 515a0e5419..aa1fe82319 100755 --- a/scripts/pkg/build_templates/opensearch/deb/debian/postinst +++ b/scripts/pkg/build_templates/opensearch/deb/debian/postinst @@ -21,9 +21,8 @@ pid_dir=/var/run/opensearch # Apply Security Settings if [ -d ${product_dir}/plugins/opensearch-security ]; then - bash ${product_dir}/plugins/opensearch-security/tools/install_demo_configuration.sh -y -i -s > ${log_dir}/install_demo_configuration.log 2>&1 + bash ${product_dir}/plugins/opensearch-security/tools/install_demo_configuration.sh -y -i -s > ${log_dir}/install_demo_configuration.log 2>&1 || (echo "ERROR: Something went wrong during demo configuration installation. Please see the logs in ${log_dir}/install_demo_configuration.log" && exit 1) fi - # Apply PerformanceAnalyzer Settings chmod a+rw /tmp if ! grep -q '## OpenSearch Performance Analyzer' ${config_dir}/jvm.options; then diff --git a/scripts/pkg/build_templates/opensearch/deb/debian/preinst b/scripts/pkg/build_templates/opensearch/deb/debian/preinst index 1a02cc06c1..0d53bc7cba 100755 --- a/scripts/pkg/build_templates/opensearch/deb/debian/preinst +++ b/scripts/pkg/build_templates/opensearch/deb/debian/preinst @@ -11,6 +11,8 @@ set -e +OPENSEARCH_VERSION=CHANGE_VERSION + echo "Running OpenSearch Pre-Installation Script" # Stop existing service @@ -23,6 +25,29 @@ 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 +# TODO: +# 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. + +# Check if this is an upgrade by checking whether opensearch already exists +if dpkg-query -W opensearch >/dev/null 2>&1; then + OPENSEARCH_ALREADY_INSTALLED=yes +else + OPENSEARCH_ALREADY_INSTALLED=no +fi + +OPENSEARCH_REQUIRED_VERSION="2.12.0" +MINIMUM_OF_TWO_VERSIONS=`echo $OPENSEARCH_REQUIRED_VERSION $OPENSEARCH_VERSION | tr ' ' '\n' | sort -V | uniq | head -n 1` + +if [ $OPENSEARCH_ALREADY_INSTALLED = no ]; then + if [ $MINIMUM_OF_TWO_VERSIONS = $OPENSEARCH_REQUIRED_VERSION ] && [ -z "$OPENSEARCH_INITIAL_ADMIN_PASSWORD" ]; then + echo "ERROR: 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 +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 || \ diff --git a/scripts/pkg/build_templates/opensearch/rpm/opensearch.rpm.spec b/scripts/pkg/build_templates/opensearch/rpm/opensearch.rpm.spec index 6d9eec3bab..179a246bde 100644 --- a/scripts/pkg/build_templates/opensearch/rpm/opensearch.rpm.spec +++ b/scripts/pkg/build_templates/opensearch/rpm/opensearch.rpm.spec @@ -89,6 +89,30 @@ 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 +# TODO: +# 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. + +# Check if this is an upgrade by checking whether opensearch already exists +if rpm -q opensearch >/dev/null 2>&1 || yum list installed opensearch >/dev/null 2>&1; then + OPENSEARCH_ALREADY_INSTALLED=yes +else + OPENSEARCH_ALREADY_INSTALLED=no +fi + +OPENSEARCH_REQUIRED_VERSION="2.12.0" +OPENSEARCH_VERSION=%{_version} +MINIMUM_OF_TWO_VERSIONS=`echo $OPENSEARCH_REQUIRED_VERSION $OPENSEARCH_VERSION | tr ' ' '\n' | sort -V | uniq | head -n 1` + +if [ $OPENSEARCH_ALREADY_INSTALLED = no ]; then + if [ $MINIMUM_OF_TWO_VERSIONS = $OPENSEARCH_REQUIRED_VERSION ] && [ -z "$OPENSEARCH_INITIAL_ADMIN_PASSWORD" ]; then + echo "ERROR: 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 +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 || \ @@ -100,7 +124,7 @@ exit 0 set -e # Apply Security Settings if [ -d %{product_dir}/plugins/opensearch-security ]; then - sh %{product_dir}/plugins/opensearch-security/tools/install_demo_configuration.sh -y -i -s > %{log_dir}/install_demo_configuration.log 2>&1 + sh %{product_dir}/plugins/opensearch-security/tools/install_demo_configuration.sh -y -i -s > %{log_dir}/install_demo_configuration.log 2>&1 || (echo "ERROR: Something went wrong during demo configuration installation. Please see the logs in %{log_dir}/install_demo_configuration.log" && exit 1) fi chown -R %{name}.%{name} %{config_dir} chown -R %{name}.%{name} %{log_dir}