diff --git a/distribution/packages/src/common/scripts/prerm b/distribution/packages/src/common/scripts/prerm index 7609abb950339..570e9dcb7043b 100644 --- a/distribution/packages/src/common/scripts/prerm +++ b/distribution/packages/src/common/scripts/prerm @@ -55,6 +55,9 @@ if [ "$STOP_REQUIRED" = "true" ]; then if command -v systemctl >/dev/null; then systemctl --no-reload stop wazuh-indexer.service + elif command -v service >/dev/null && service wazuh-indexer status >/dev/null 2>&1; then + service wazuh-indexer stop + elif [ -x /etc/init.d/wazuh-indexer ]; then if command -v invoke-rc.d >/dev/null; then invoke-rc.d wazuh-indexer stop @@ -81,13 +84,13 @@ fi if [ "$REMOVE_SERVICE" = "true" ]; then if command -v systemctl >/dev/null; then systemctl disable wazuh-indexer.service > /dev/null 2>&1 || true - fi - if command -v chkconfig >/dev/null; then - chkconfig --del wazuh-indexer 2> /dev/null || true - fi + # Check for SysV + elif command -v service > /dev/null 2>&1 && command -v chkconfig > /dev/null 2>&1; then + chkconfig wazuh-indexer off > /dev/null 2>&1 + chkconfig --del wazuh-indexer > /dev/null 2>&1 - if command -v update-rc.d >/dev/null; then + elif command -v update-rc.d >/dev/null; then update-rc.d wazuh-indexer remove >/dev/null || true fi fi diff --git a/distribution/packages/src/deb/debian/postinst b/distribution/packages/src/deb/debian/postinst index c523ffa260091..587bedf6391f3 100644 --- a/distribution/packages/src/deb/debian/postinst +++ b/distribution/packages/src/deb/debian/postinst @@ -33,17 +33,23 @@ chown -R wazuh-indexer:wazuh-indexer ${pid_dir} chown -R wazuh-indexer:wazuh-indexer ${tmp_dir} # Reload systemctl daemon -if command -v systemctl > /dev/null; then +if command -v systemctl >/dev/null 2>&1 && systemctl >/dev/null 2>&1; then systemctl daemon-reload fi # Reload other configs if command -v systemctl > /dev/null; then systemctl restart systemd-sysctl.service || true +elif command -v sysctl > /dev/null; then + echo "Load configurations from /etc/sysctl.conf" + sysctl -p fi if command -v systemd-tmpfiles > /dev/null; then systemd-tmpfiles --create wazuh-indexer.conf +else + echo "touch wazuh-indexer.conf" + touch wazuh-indexer.conf fi if [ -f $restart_service ]; then @@ -51,15 +57,32 @@ if [ -f $restart_service ]; then echo "Restarting wazuh-indexer service..." if command -v systemctl > /dev/null; then systemctl restart wazuh-indexer.service > /dev/null 2>&1 + # Check for SysV + elif command -v service > /dev/null 2>&1; then + service wazuh-indexer restart > /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" -echo " sudo systemctl enable wazuh-indexer.service" -echo "### You can start wazuh-indexer service by executing" -echo " sudo systemctl start wazuh-indexer.service" +if command -v systemctl >/dev/null; then + 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" + echo " sudo systemctl enable wazuh-indexer.service" + echo "### You can start wazuh-indexer service by executing" + echo " sudo systemctl start wazuh-indexer.service" + +elif command -v chkconfig >/dev/null; then + echo "### NOT starting on installation, please execute the following statements to configure wazuh-indexer service to start automatically using chkconfig" + 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; then + echo "### NOT starting on installation, please execute the following statements to configure wazuh-indexer service to start automatically using chkconfig" + echo " sudo update-rc.d wazuh-indexer defaults 95 10" + echo "### You can start wazuh-indexer service by executing" + echo " sudo /etc/init.d/wazuh-indexer start" +fi exit 0 diff --git a/distribution/packages/src/deb/debian/preinst b/distribution/packages/src/deb/debian/preinst index e36f94b197b5d..bf08a9a3bcb16 100644 --- a/distribution/packages/src/deb/debian/preinst +++ b/distribution/packages/src/deb/debian/preinst @@ -21,10 +21,18 @@ if command -v systemctl >/dev/null && systemctl is-active wazuh-indexer.service echo "Stop existing wazuh-indexer.service" systemctl --no-reload stop wazuh-indexer.service touch $restart_service +elif command -v service >/dev/null && service wazuh-indexer status >/dev/null 2>&1; then + echo "Stop existing wazuh-indexer" + service wazuh-indexer stop + 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" systemctl --no-reload stop wazuh-indexer-performance-analyzer.service +elif command -v service >/dev/null && service wazuh-indexer-performance-analyzer status >/dev/null 2>&1; then + echo "Stop existing wazuh-indexer-performance-analyzer" + service wazuh-indexer-performance-analyzer stop fi # Create user and group if they do not already exist. diff --git a/distribution/packages/src/deb/debian/prerm b/distribution/packages/src/deb/debian/prerm index f92bbfcf3b69f..a77868d4541ec 100644 --- a/distribution/packages/src/deb/debian/prerm +++ b/distribution/packages/src/deb/debian/prerm @@ -20,10 +20,19 @@ case "$1" in 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 + # Check for SysV + elif command -v service > /dev/null && service wazuh-indexer status >/dev/null 2>&1; then + echo "Stop existing wazuh-indexer" + service wazuh-indexer stop 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 + # Check for SysV + elif command -v service >/dev/null && service wazuh-indexer-performance-analyzer status >/dev/null 2>&1; then + echo "Stop existing wazuh-indexer-performance-analyzer" + service wazuh-indexer-performance-analyzer stop fi ;; failed-upgrade) diff --git a/distribution/packages/src/rpm/wazuh-indexer.cicd.spec b/distribution/packages/src/rpm/wazuh-indexer.cicd.spec index 6bb77d059e6b2..0234fd70a31f5 100644 --- a/distribution/packages/src/rpm/wazuh-indexer.cicd.spec +++ b/distribution/packages/src/rpm/wazuh-indexer.cicd.spec @@ -160,6 +160,9 @@ if [ $1 = 1 ];then # Install # To pick up /usr/lib/sysctl.d/wazuh-indexer.conf if command -v systemctl > /dev/null 2>&1; then systemctl restart systemd-sysctl > /dev/null 2>&1 || true + elif command -v sysctl > /dev/null; then + # Load configurations from /etc/sysctl.conf + sysctl -p fi fi diff --git a/distribution/packages/src/rpm/wazuh-indexer.rpm.spec b/distribution/packages/src/rpm/wazuh-indexer.rpm.spec index e9420754c1136..0dcda34e0322b 100644 --- a/distribution/packages/src/rpm/wazuh-indexer.rpm.spec +++ b/distribution/packages/src/rpm/wazuh-indexer.rpm.spec @@ -163,10 +163,20 @@ if command -v systemctl >/dev/null && systemctl is-active %{name}.service >/dev/ echo "Stop existing %{name}.service" systemctl --no-reload stop %{name}.service touch %{tmp_dir}/wazuh-indexer.restart +# Check for SysV +elif command -v service > /dev/null 2>&1 && service %{name} status 2>/dev/null | grep "is running" > /dev/null 2>&1; then + echo "Stop existing %{name}" + service %{name} stop > /dev/null 2>&1 + 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" systemctl --no-reload stop %{name}-performance-analyzer.service +# Check for SysV +elif command -v service > /dev/null 2>&1 && service %{name}}-performance-analyzer status 2>/dev/null | grep "is running" > /dev/null 2>&1; then + echo "Stop existing %{name}-performance-analyzer" + service %{name}-performance-analyzer stop > /dev/null 2>&1 fi # Create user and group if they do not already exist. getent group %{name} > /dev/null 2>&1 || groupadd -r %{name} @@ -199,10 +209,15 @@ fi # Reload other configs if command -v systemctl > /dev/null; then systemctl restart systemd-sysctl.service || true +elif command -v sysctl > /dev/null; then + # Load configurations from /etc/sysctl.conf + sysctl -p fi if command -v systemd-tmpfiles > /dev/null; then systemd-tmpfiles --create %{name}.conf +else + touch wazuh-indexer.conf fi if [ -f %{tmp_dir}/wazuh-indexer.restart ]; then @@ -211,15 +226,44 @@ if [ -f %{tmp_dir}/wazuh-indexer.restart ]; then echo "Restarting wazuh-indexer service..." systemctl restart wazuh-indexer.service > /dev/null 2>&1 exit 0 + # Check for SysV + elif command -v service > /dev/null 2>&1; then + echo "Restarting wazuh-indexer service..." + service wazuh-indexer restart > /dev/null 2>&1 + exit 0 + elif [ -x /etc/init.d/wazuh-indexer ]; then + if command -v invoke-rc.d >/dev/null; then + invoke-rc.d wazuh-indexer stop || true + invoke-rc.d wazuh-indexer start || true + exit 0 + else + /etc/init.d/wazuh-indexer restart || true + exit 0 + fi 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" -echo " sudo systemctl enable wazuh-indexer.service" -echo "### You can start wazuh-indexer service by executing" -echo " sudo systemctl start wazuh-indexer.service" +# Check for systemd presence +if command -v systemctl >/dev/null 2>&1; then + # 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" + echo " sudo systemctl enable wazuh-indexer.service" + echo "### You can start wazuh-indexer service by executing" + echo " sudo systemctl start wazuh-indexer.service" + + elif command -v chkconfig >/dev/null; then + echo "### NOT starting on installation, please execute the following statements to configure wazuh-indexer service to start automatically using chkconfig" + 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; then + echo "### NOT starting on installation, please execute the following statements to configure wazuh-indexer service to start automatically using chkconfig" + echo " sudo update-rc.d wazuh-indexer defaults 95 10" + echo "### You can start wazuh-indexer service by executing" + echo " sudo /etc/init.d/wazuh-indexer start" + fi exit 0 %preun @@ -227,10 +271,18 @@ 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 +# Check for SysV +elif command -v service > /dev/null 2>&1 && service %{name} status 2>/dev/null | grep "is running" > /dev/null 2>&1; then + echo "Stop existing %{name}" + service %{name} stop > /dev/null 2>&1 fi if command -v systemctl >/dev/null && systemctl is-active %{name}-performance-analyzer.service >/dev/null; then echo "Stop existing %{name}-performance-analyzer.service" systemctl --no-reload stop %{name}-performance-analyzer.service +# Check for SysV +elif command -v service > /dev/null 2>&1 && service %{name}}-performance-analyzer status 2>/dev/null | grep "is running" > /dev/null 2>&1; then + echo "Stop existing %{name}-performance-analyzer" + service %{name}-performance-analyzer stop > /dev/null 2>&1 fi exit 0