From 9c070e39a0d55d2b66a2e52c1848b661320bc414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fern=C3=A1ndez?= Date: Wed, 9 Feb 2022 12:23:37 +0100 Subject: [PATCH] Added restart file to RPM SPECs --- stack/indexer/rpm/wazuh-indexer.spec | 105 ++++++++++++++++----------- 1 file changed, 61 insertions(+), 44 deletions(-) diff --git a/stack/indexer/rpm/wazuh-indexer.spec b/stack/indexer/rpm/wazuh-indexer.spec index 15ad03abe9..8dbf6caaf0 100644 --- a/stack/indexer/rpm/wazuh-indexer.spec +++ b/stack/indexer/rpm/wazuh-indexer.spec @@ -122,6 +122,34 @@ if [ $1 = 1 ];then # Install fi fi +# Stop the services to upgrade the package +if [ $1 = 2 ]; then + if command -v systemctl > /dev/null 2>&1 && systemctl > /dev/null 2>&1 && systemctl is-active --quiet %{name} > /dev/null 2>&1; then + systemctl stop %{name}.service > /dev/null 2>&1 + touch %{INSTALL_DIR}/%{name}.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 + service %{name} stop > /dev/null 2>&1 + touch %{INSTALL_DIR}/%{name}.restart + elif [ -x /etc/init.d/%{name} ]; then + if command -v invoke-rc.d >/dev/null; then + invoke-rc.d %{name} stop > /dev/null 2>&1 + touch %{INSTALL_DIR}/%{name}.restart + else + /etc/init.d/%{name} stop > /dev/null 2>&1 + touch %{INSTALL_DIR}/%{name}.restart + fi + + # Older Suse linux distributions do not ship with systemd + # but do not have an /etc/init.d/ directory + # this tries to stop the %{name} service on these + # as well without failing this script + elif [ -x /etc/rc.d/init.d/%{name} ] ; then + /etc/rc.d/init.d/%{name} stop > /dev/null 2>&1 + touch %{INSTALL_DIR}/%{name}.restart + fi +fi + # ----------------------------------------------------------------------------- %post @@ -140,33 +168,6 @@ if [ $1 = 1 ];then # Install fi fi -if [ $1 = 2 ];then # Upgrade - echo -n "Restarting wazuh-indexer service..." - if command -v systemctl > /dev/null 2>&1 && systemctl is-active --quiet wazuh-indexer > /dev/null 2>&1; then - systemctl daemon-reload > /dev/null 2>&1 - 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 - - elif [ -x /etc/init.d/wazuh-indexer ]; then - if command -v invoke-rc.d >/dev/null; then - invoke-rc.d wazuh-indexer restart > /dev/null 2>&1 - else - /etc/init.d/wazuh-indexer restart > /dev/null 2>&1 - fi - - # Older Suse linux distributions do not ship with systemd - # but do not have an /etc/init.d/ directory - # this tries to stop the wazuh-indexer service on these - # as well without failing this script - elif [ -x /etc/rc.d/init.d/wazuh-indexer ] ; then - /etc/rc.d/init.d/wazuh-indexer restart > /dev/null 2>&1 - fi - echo " OK" -fi - # ----------------------------------------------------------------------------- %preun @@ -175,26 +176,20 @@ export OPENSEARCH_PATH_CONF=${OPENSEARCH_PATH_CONF:-%{CONFIG_DIR}} if [ $1 = 0 ];then # Remove echo -n "Stopping wazuh-indexer service..." - if command -v systemctl > /dev/null 2>&1 && systemctl is-active --quiet wazuh-indexer > /dev/null 2>&1; then - systemctl --no-reload stop wazuh-indexer.service > /dev/null 2>&1 + if command -v systemctl > /dev/null 2>&1 && systemctl is-active --quiet %{name} > /dev/null 2>&1; then + systemctl --no-reload stop %{name}.service > /dev/null 2>&1 # Check for SysV elif command -v service > /dev/null 2>&1; then - service wazuh-indexer stop > /dev/null 2>&1 - - elif [ -x /etc/init.d/wazuh-indexer ]; then + service %{name} stop > /dev/null 2>&1 + elif [ -x /etc/init.d/%{name} ]; then if command -v invoke-rc.d >/dev/null; then - invoke-rc.d wazuh-indexer stop > /dev/null 2>&1 + invoke-rc.d %{name} stop > /dev/null 2>&1 else - /etc/init.d/wazuh-indexer stop > /dev/null 2>&1 + /etc/init.d/%{name} stop > /dev/null 2>&1 fi - - # Older Suse linux distributions do not ship with systemd - # but do not have an /etc/init.d/ directory - # this tries to stop the wazuh-indexer service on these - # as well without failing this script - elif [ -x /etc/rc.d/init.d/wazuh-indexer ] ; then - /etc/rc.d/init.d/wazuh-indexer stop > /dev/null 2>&1 + elif [ -x /etc/rc.d/init.d/%{name} ] ; then + /etc/rc.d/init.d/%{name} stop > /dev/null 2>&1 else # Anything else kill -15 `pgrep -f opensearch` > /dev/null 2>&1 fi @@ -202,12 +197,12 @@ if [ $1 = 0 ];then # Remove # Check for systemd if command -v systemctl > /dev/null 2>&1 && systemctl > /dev/null 2>&1; then - systemctl disable wazuh-indexer > /dev/null 2>&1 + systemctl disable %{name} > /dev/null 2>&1 systemctl daemon-reload > /dev/null 2>&1 # 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 + chkconfig %{name} off > /dev/null 2>&1 + chkconfig --del %{name} > /dev/null 2>&1 fi fi @@ -243,6 +238,28 @@ fi export OPENSEARCH_PATH_CONF=${OPENSEARCH_PATH_CONF:-%{CONFIG_DIR}} +if [ -f %{INSTALL_DIR}/%{name}.restart ]; then + echo -n "Starting wazuh-indexer service..." + rm -f %{INSTALL_DIR}/%{name}.restart + if command -v systemctl > /dev/null 2>&1; then + systemctl daemon-reload > /dev/null 2>&1 + systemctl restart %{name}.service > /dev/null 2>&1 + + # Check for SysV + elif command -v service > /dev/null 2>&1; then + service %{name} restart > /dev/null 2>&1 + elif [ -x /etc/init.d/%{name} ]; then + if command -v invoke-rc.d >/dev/null; then + invoke-rc.d %{name} restart > /dev/null 2>&1 + else + /etc/init.d/%{name} restart > /dev/null 2>&1 + fi + elif [ -x /etc/rc.d/init.d/%{name} ] ; then + /etc/rc.d/init.d/%{name} restart > /dev/null 2>&1 + fi + echo " OK" +fi + if [ ! -f "%{CONFIG_DIR}"/opensearch.keystore ]; then "%{INSTALL_DIR}"/bin/opensearch-keystore create chown %{USER}:%{GROUP} "%{CONFIG_DIR}"/opensearch.keystore