From aebfcc7cfe2e7647166740c01245ceaedf12a75e Mon Sep 17 00:00:00 2001 From: quebim Date: Thu, 24 Oct 2024 16:27:13 -0300 Subject: [PATCH 1/3] Update pre and post inst scripts for deb and rpm to store and restore service status --- distribution/packages/src/deb/debian/postinst | 13 ++++++++++--- distribution/packages/src/deb/debian/preinst | 4 ++++ .../packages/src/rpm/wazuh-indexer.rpm.spec | 10 ++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/distribution/packages/src/deb/debian/postinst b/distribution/packages/src/deb/debian/postinst index 4541f924534df..c523ffa260091 100644 --- a/distribution/packages/src/deb/debian/postinst +++ b/distribution/packages/src/deb/debian/postinst @@ -19,7 +19,7 @@ data_dir=/var/lib/wazuh-indexer log_dir=/var/log/wazuh-indexer pid_dir=/run/wazuh-indexer tmp_dir=/var/log/wazuh-indexer/tmp - +restart_service=/tmp/wazuh-indexer.restart # Create needed directories mkdir -p ${tmp_dir} @@ -46,6 +46,15 @@ if command -v systemd-tmpfiles > /dev/null; then systemd-tmpfiles --create wazuh-indexer.conf fi +if [ -f $restart_service ]; then + rm -f $restart_service + echo "Restarting wazuh-indexer service..." + if command -v systemctl > /dev/null; then + systemctl restart wazuh-indexer.service > /dev/null 2>&1 + fi + exit 0 +fi + # Messages echo "### NOT starting on installation, please execute the following statements to configure wazuh-indexer service to start automatically using systemd" echo " sudo systemctl daemon-reload" @@ -54,5 +63,3 @@ echo "### You can start wazuh-indexer service by executing" echo " sudo systemctl start wazuh-indexer.service" exit 0 - - diff --git a/distribution/packages/src/deb/debian/preinst b/distribution/packages/src/deb/debian/preinst index 2cf7ea70a7466..e36f94b197b5d 100644 --- a/distribution/packages/src/deb/debian/preinst +++ b/distribution/packages/src/deb/debian/preinst @@ -13,10 +13,14 @@ set -e echo "Running Wazuh Indexer Pre-Installation Script" +# Reference to restore actual service status +restart_service=/tmp/wazuh-indexer.restart + # Stop existing service if command -v systemctl >/dev/null && systemctl is-active wazuh-indexer.service >/dev/null; then echo "Stop existing wazuh-indexer.service" systemctl --no-reload stop wazuh-indexer.service + touch $restart_service fi if command -v systemctl >/dev/null && systemctl is-active wazuh-indexer-performance-analyzer.service >/dev/null; then echo "Stop existing wazuh-indexer-performance-analyzer.service" diff --git a/distribution/packages/src/rpm/wazuh-indexer.rpm.spec b/distribution/packages/src/rpm/wazuh-indexer.rpm.spec index 9549893bd3ee8..9a011ee88a026 100644 --- a/distribution/packages/src/rpm/wazuh-indexer.rpm.spec +++ b/distribution/packages/src/rpm/wazuh-indexer.rpm.spec @@ -162,6 +162,7 @@ set -e if command -v systemctl >/dev/null && systemctl is-active %{name}.service >/dev/null; then echo "Stop existing %{name}.service" systemctl --no-reload stop %{name}.service + touch %{tmp_dir}/wazuh-indexer.restart fi if command -v systemctl >/dev/null && systemctl is-active %{name}-performance-analyzer.service >/dev/null; then echo "Stop existing %{name}-performance-analyzer.service" @@ -204,6 +205,15 @@ if command -v systemd-tmpfiles > /dev/null; then systemd-tmpfiles --create %{name}.conf fi +if [ -f %{tmp_dir}/wazuh-indexer.restart ]; then + rm -f %{tmp_dir}/wazuh-indexer.restart + if command -v systemctl > /dev/null; then + echo "Restarting wazuh-indexer service..." + systemctl restart wazuh-server.service > /dev/null 2>&1 + exit 0 + fi +fi + # Messages echo "### NOT starting on installation, please execute the following statements to configure wazuh-indexer service to start automatically using systemd" echo " sudo systemctl daemon-reload" From 12082b971641fa0e159565402788d9770f5a3b0e Mon Sep 17 00:00:00 2001 From: quebim Date: Thu, 24 Oct 2024 17:51:26 -0300 Subject: [PATCH 2/3] Update prerm script to avoid stopping the service on upgrade --- distribution/packages/src/deb/debian/prerm | 37 +++++++++++++++------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/distribution/packages/src/deb/debian/prerm b/distribution/packages/src/deb/debian/prerm index a5222b2caae40..11f8e6762b99f 100644 --- a/distribution/packages/src/deb/debian/prerm +++ b/distribution/packages/src/deb/debian/prerm @@ -11,16 +11,31 @@ set -e -echo "Running Wazuh Indexer Pre-Removal Script" - -# Stop existing service -if command -v systemctl >/dev/null && systemctl is-active wazuh-indexer.service >/dev/null; then - echo "Stop existing wazuh-indexer.service" - systemctl --no-reload stop wazuh-indexer.service -fi -if command -v systemctl >/dev/null && systemctl is-active wazuh-indexer-performance-analyzer.service >/dev/null; then - echo "Stop existing wazuh-indexer-performance-analyzer.service" - systemctl --no-reload stop wazuh-indexer-performance-analyzer.service -fi +case "$1" in + upgrade|deconfigure) + ;; + + remove) + echo "Running Wazuh Indexer Pre-Removal Script" + # Stop existing service + if command -v systemctl >/dev/null && systemctl is-active wazuh-indexer.service >/dev/null; then + echo "Stop existing wazuh-indexer.service" + systemctl --no-reload stop wazuh-indexer.service + fi + if command -v systemctl >/dev/null && systemctl is-active wazuh-indexer-performance-analyzer.service >/dev/null; then + echo "Stop existing wazuh-indexer-performance-analyzer.service" + systemctl --no-reload stop wazuh-indexer-performance-analyzer.service + fi + ;; + + failed-upgrade) + ;; + + *) + echo "prerm called with unknown argument \`$1'" >&2 + exit 0 + ;; + +esac exit 0 From a7ffe9af1b669d734116e1233c22ac511b2c4864 Mon Sep 17 00:00:00 2001 From: quebim Date: Fri, 25 Oct 2024 10:42:39 -0300 Subject: [PATCH 3/3] Remove extra spaces and update rpm restart command --- distribution/packages/src/deb/debian/prerm | 4 ---- distribution/packages/src/rpm/wazuh-indexer.rpm.spec | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/distribution/packages/src/deb/debian/prerm b/distribution/packages/src/deb/debian/prerm index 11f8e6762b99f..f92bbfcf3b69f 100644 --- a/distribution/packages/src/deb/debian/prerm +++ b/distribution/packages/src/deb/debian/prerm @@ -14,7 +14,6 @@ set -e case "$1" in upgrade|deconfigure) ;; - remove) echo "Running Wazuh Indexer Pre-Removal Script" # Stop existing service @@ -27,15 +26,12 @@ case "$1" in systemctl --no-reload stop wazuh-indexer-performance-analyzer.service fi ;; - failed-upgrade) ;; - *) echo "prerm called with unknown argument \`$1'" >&2 exit 0 ;; - esac exit 0 diff --git a/distribution/packages/src/rpm/wazuh-indexer.rpm.spec b/distribution/packages/src/rpm/wazuh-indexer.rpm.spec index 9a011ee88a026..e460631679888 100644 --- a/distribution/packages/src/rpm/wazuh-indexer.rpm.spec +++ b/distribution/packages/src/rpm/wazuh-indexer.rpm.spec @@ -209,7 +209,7 @@ if [ -f %{tmp_dir}/wazuh-indexer.restart ]; then rm -f %{tmp_dir}/wazuh-indexer.restart if command -v systemctl > /dev/null; then echo "Restarting wazuh-indexer service..." - systemctl restart wazuh-server.service > /dev/null 2>&1 + systemctl restart wazuh-indexer.service > /dev/null 2>&1 exit 0 fi fi