Skip to content

Commit

Permalink
Added restart file to RPM SPECs
Browse files Browse the repository at this point in the history
  • Loading branch information
okynos committed Feb 9, 2022
1 parent 5b1b913 commit 9c070e3
Showing 1 changed file with 61 additions and 44 deletions.
105 changes: 61 additions & 44 deletions stack/indexer/rpm/wazuh-indexer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -175,39 +176,33 @@ 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
echo " OK"

# 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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9c070e3

Please sign in to comment.