From c5996a4d01f466854b88b2bd04de323571dfdc9b Mon Sep 17 00:00:00 2001 From: QU3B1M Date: Wed, 8 Jan 2025 13:48:45 -0300 Subject: [PATCH] Fix typo on debian prerm Ensure the init.d script is always executable Improve validations --- .../packages/src/common/init.d/wazuh-indexer | 2 +- distribution/packages/src/deb/debian/postinst | 19 +++++++++---------- distribution/packages/src/deb/debian/prerm | 2 +- .../packages/src/rpm/wazuh-indexer.rpm.spec | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/distribution/packages/src/common/init.d/wazuh-indexer b/distribution/packages/src/common/init.d/wazuh-indexer index f495f570e4d6b..e424334a825ef 100644 --- a/distribution/packages/src/common/init.d/wazuh-indexer +++ b/distribution/packages/src/common/init.d/wazuh-indexer @@ -88,7 +88,7 @@ start() { cd $OPENSEARCH_HOME || exit echo -n $"Starting $prog: " # if not running, start it up here, usually something like "daemon $exec" - if command -v systemctl; then + if command -v daemon; then daemon --user wazuh-indexer --pidfile $pidfile $exec -p $pidfile -d else runuser wazuh-indexer --shell="/bin/bash" --command="$exec -p $pidfile -d" diff --git a/distribution/packages/src/deb/debian/postinst b/distribution/packages/src/deb/debian/postinst index 8d5508ab4d507..93144a06430f9 100644 --- a/distribution/packages/src/deb/debian/postinst +++ b/distribution/packages/src/deb/debian/postinst @@ -32,12 +32,6 @@ chown -R wazuh-indexer:wazuh-indexer ${data_dir} chown -R wazuh-indexer:wazuh-indexer ${pid_dir} chown -R wazuh-indexer:wazuh-indexer ${tmp_dir} -# Check if the script is executed on upgrade -is_upgrade=false -if [ -n "$2" ]; then - is_upgrade=true -fi - export OPENSEARCH_PATH_CONF=${OPENSEARCH_PATH_CONF:-${config_dir}} # Apply Performance Analyzer settings, as per https://github.com/opensearch-project/opensearch-build/blob/2.18.0/scripts/pkg/build_templates/current/opensearch/deb/debian/postinst#L28-L37 if ! grep -q '## OpenSearch Performance Analyzer' "$OPENSEARCH_PATH_CONF/jvm.options"; then @@ -66,10 +60,16 @@ if command -v systemd-tmpfiles > /dev/null 2>&1 && systemctl > /dev/null 2>&1; t systemd-tmpfiles --create wazuh-indexer.conf > /dev/null 2>&1 fi -# Check if its upgrade and restart service -if [ "$is_upgrade" = true ]; then +if command -v /etc/init.d/wazuh-indexer > /dev/null 2>&1; then + # Ensure the script is executable + chmod +x /etc/init.d/wazuh-indexer > /dev/null 2>&1 +fi + +# Check if the script is executed on upgrade +if [ -n "$2" ]; then if [ -f $restart_service ]; then echo "Restarting wazuh-indexer service after upgrade" + rm -f $restart_service if command -v systemctl > /dev/null 2>&1 && systemctl > /dev/null 2>&1; then systemctl restart wazuh-indexer.service > /dev/null 2>&1 elif command -v service > /dev/null 2>&1; then @@ -77,7 +77,6 @@ if [ "$is_upgrade" = true ]; then elif command -v /etc/init.d/wazuh-indexer > /dev/null 2>&1; then /etc/init.d/wazuh-indexer restart > /dev/null 2>&1 fi - rm -f $restart_service else echo "### NOT restarting wazuh-indexer service after upgrade" echo "### You can start wazuh-indexer service by executing" @@ -102,7 +101,7 @@ else echo " sudo chkconfig --add wazuh-indexer" echo "### You can start wazuh-indexer service by executing" echo " sudo service wazuh-indexer start" - elif command -v update-rc.d > /dev/null 2>&1; then + elif command -v update-rc.d > /dev/null 2>&1 && command -v /etc/init.d/wazuh-indexer > /dev/null 2>&1; then echo "### NOT starting on installation, please execute the following statements to configure wazuh-indexer service to start automatically using update-rc.d" echo " sudo update-rc.d wazuh-indexer defaults 95 10" echo "### You can start wazuh-indexer service by executing" diff --git a/distribution/packages/src/deb/debian/prerm b/distribution/packages/src/deb/debian/prerm index 1ba8ce36448b8..b73f8f72558c9 100644 --- a/distribution/packages/src/deb/debian/prerm +++ b/distribution/packages/src/deb/debian/prerm @@ -16,7 +16,7 @@ case "$1" in ;; remove) echo "Running Wazuh Indexer Pre-Removal Script" - # Stop existin wazuh-indexer.service + # Stop existing wazuh-indexer.service if command -v systemctl > /dev/null 2>&1 && systemctl > /dev/null 2>&1 && systemctl is-active wazuh-indexer.service > /dev/null 2>&1; then echo "Stop existing wazuh-indexer.service" systemctl --no-reload stop wazuh-indexer.service > /dev/null 2>&1 diff --git a/distribution/packages/src/rpm/wazuh-indexer.rpm.spec b/distribution/packages/src/rpm/wazuh-indexer.rpm.spec index ce9f64051fd37..70b18cfd90fc0 100644 --- a/distribution/packages/src/rpm/wazuh-indexer.rpm.spec +++ b/distribution/packages/src/rpm/wazuh-indexer.rpm.spec @@ -230,8 +230,8 @@ fi if [ $1 = 2 ]; then if [ -f %{restart_service} ]; then - rm -f %{restart_service} echo "Restarting wazuh-indexer service after upgrade" + rm -f %{restart_service} if command -v systemctl > /dev/null 2>&1 && systemctl > /dev/null 2>&1; then systemctl restart wazuh-indexer.service > /dev/null 2>&1 elif command -v service > /dev/null 2>&1; then