Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade the 360 Monitoring uninstallation script #43

Merged
merged 1 commit into from
May 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 50 additions & 19 deletions 360-monitoring-uninstall/360-monitoring-uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,57 @@
###############################################################################
# The script uninstalls the 360 Monitoring agent and remove all the configuration
# Requirements : bash 3.x
# Version : 1.0
# Version : 2.0
#########

systemctl stop agent360 &&
echo -e "\\e[32mThe agent360 service has been stopped\\e[m"

systemctl disable agent360 &&
echo -e "\\e[32mThe agent360 service has been disabled\\e[m"

rm -f /etc/systemd/system/agent360 &&
echo -e "\\e[32mThe agent360 service configuration has been removed\\e[m"

rm -f /etc/agent360* &&
echo -e "\\e[32mThe 360 Monitoring configuration files have been deleted\\e[m"

pip3 uninstall -y agent360 &&
echo -e "\\e[32mThe Python modules for 360 Monitoring have been removed\\e[m"

userdel agent360 &&
echo -e "\\e[32mThe corresponding user has been deleted\\e[m"
handle_cmd () {
noservicestop="Unit agent360.service not loaded"
noservicedisable="Unit file agent360.service does not exist"
nomodule="Cannot uninstall requirement agent360, not installed"
nouser="user 'agent360' does not exist"
if result=$($1 2>&1) ; then
echo -e "\\e[32m[SUCCESS] $2\\e[m"
else
if [[ $result = *$noservicestop* ]] ; then
echo -e "\\e[33m[WARNING] Unable to stop the service agent360 because it was not found\n\t Probably, it was removed earlier\\e[m"
elif [[ $result = *$noservicedisable* ]] ; then
echo -e "\\e[33m[WARNING] The service agent360 can not be disabled because it was not found\n\t Probably, it was removed earlier\\e[m"
elif [[ $result = *$nomodule* ]] ; then
echo -e "\\e[33m[WARNING] The Python modules for 360 Monitoring are not found\n\t Probably, it was removed earlier\\e[m"
elif [[ $result = *$nouser* ]] ; then
echo -e "\\e[33m[WARNING] The user agent360 does not exist\n\t Probably, it was removed earlier\\e[m"
else
echo -e "\\e[31m[ERROR] $result\\e[m"
fi
fi
}

handle_cmd 'systemctl stop agent360' 'The service agent360 has been stopped'
handle_cmd 'systemctl disable agent360' 'The service agent360 has been disabled'
handle_cmd 'pip3 uninstall -y agent360' 'The Python modules for 360 Monitoring have been removed'
handle_cmd 'userdel agent360' 'The user agent360 has been deleted'

if [[ -f /etc/systemd/system/agent360.service ]] || [[ -f /etc/systemd/system/agent360 ]] ; then
handle_cmd 'rm -f /etc/systemd/system/agent360*' 'The configuration of the service agent360 has been removed'
handle_cmd 'systemctl reset-failed' 'The systemd data has been updated'
else
echo -e "\\e[33m[WARNING] The configuration file of the service agent360 is not found\n\t Probably, it was removed earlier\\e[m"
fi
if [[ -f /etc/agent360.ini ]] || [[ -f /etc/agent360-token.ini ]] ; then
handle_cmd 'rm -f /etc/agent360*' 'The 360 Monitoring configuration files have been deleted'
else
echo -e "\\e[33m[WARNING] The 360 Monitoring configuration files are not found\n\t Probably, they were removed earlier\\e[m"
fi

if [[ -f /var/log/agent360.log ]] || [[ -f /var/log/agent360-install.log ]]; then
echo
read -r -p "Do you want to remove agent360 logs (y/n)? " choice
case "$choice" in
y|Y ) handle_cmd 'rm -f /var/log/agent360*' 'The logs have been removed';;
n|N ) echo -e "\\e[32m[SUCCESS] The logs remain on the server\n\t You might remove them manually later\\e[m";;
* ) echo -e "\\e[31m[ERROR] The input is invalid! The logs have not been removed\\e[m";;
esac
fi

echo
echo -e "\\e[34m[!] Please wait for 15 minutes and, then, remove the server from Plesk 360 > Monitoring > Servers\\e[m"
echo -e "\\e[34m[INFO] Please wait for 15 minutes and, then, remove the server from 360 Monitoring > Servers\\e[m"