Skip to content

Commit

Permalink
Added preun to stop wazuh-indexer on removal and postun to remove all…
Browse files Browse the repository at this point in the history
… files
  • Loading branch information
okynos committed Jan 14, 2022
1 parent 5ab72b8 commit c55bced
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion indexer/rpm/wazuh-indexer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Vendor: Wazuh, Inc <[email protected]>
Packager: Wazuh, Inc <[email protected]>
AutoReqProv: no
Requires: coreutils initscripts
Requires: coreutils initscripts chkconfig
ExclusiveOS: linux
BuildRequires: tar shadow-utils

Expand Down Expand Up @@ -144,6 +144,57 @@ rm -rf %{LOG_DIR}/* > /dev/null 2>&1

# -----------------------------------------------------------------------------

%preun

if [ $1 = 0 ];then # Remove
# Stop the services before uninstall the package
# Check for systemd
if command -v systemctl > /dev/null 2>&1 && systemctl > /dev/null 2>&1 && systemctl is-active --quiet wazuh-indexer > /dev/null 2>&1; then
systemctl stop wazuh-indexer.service > /dev/null 2>&1
# Check for SysV
elif command -v service > /dev/null 2>&1 && service wazuh-indexer status 2>/dev/null | grep "running" > /dev/null 2>&1; then
service wazuh-indexer stop > /dev/null 2>&1
else # Anything else
kill -15 `pgrep -f opensearch` > /dev/null 2>&1
fi

# 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 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
fi
fi

# -----------------------------------------------------------------------------

%postun

if [ $1 = 0 ];then
# Cleaning limits file
sed -i '/%{USER}/d' /etc/security/limits.conf

# Remove the user if it exists
if id -u %{USER} > /dev/null 2>&1; then
userdel %{USER} >/dev/null 2>&1
fi

# Remove the group if it exists
if command -v getent > /dev/null 2>&1 && getent group %{GROUP} > /dev/null 2>&1; then
groupdel %{GROUP} >/dev/null 2>&1
elif id -g %{GROUP} > /dev/null 2>&1; then
groupdel %{GROUP} >/dev/null 2>&1
fi

# Remove lingering folders and files
rm -rf %{INSTALL_DIR}
fi

# -----------------------------------------------------------------------------

%clean
rm -fr %{buildroot}

Expand Down

0 comments on commit c55bced

Please sign in to comment.