Script Uninstall PandoraFMS – Script ini berfungsi untuk melakukan uninstall service PandoraFMS, service web server (httpd/apache) service mysql atau percona sampai dengan package PandoraFMS lainnya.
Sehingga tidak perlu melakukan uninstall service secara manual cukup menjalankan script ini maka service service PandoraFMS akan di uninstall dan Anda siap untuk melakukan installasi PandoraFMS kembali.
Script ini cocok digunakan pada environment development atau testing, karena license PandoraFMS hanya 1 bulan atau 30 hari saja.
Perhatian!
Sebelum menjalankan script ini pastikan lakukan backup dahulu seperti backup database, backup konfigurasi dan lainnya.
Table of Contents
Script Uninstall PandoraFMS
Berikut script Uninstall PandoraFMS
#!/bin/bash
set -Eeuo pipefail
LOGFILE="/tmp/pandora-clean-uninstall-$(date +%F-%H%M%S).log"
exec > >(tee -a "$LOGFILE") 2>&1
[ "$(id -u)" -eq 0 ] || { echo "Run as root"; exit 1; }
PANDORA_HOST="${PANDORA_HOST:-$(hostname -I 2>/dev/null | awk '{print $1}')}"
DB_MODE="${DB_MODE:-local}" # local | remote
DB_HOST="${DB_HOST:-127.0.0.1}"
DB_PORT="${DB_PORT:-3306}"
DB_NAME="${DB_NAME:-pandora}"
DB_USER="${DB_USER:-pandora}"
DB_ROOT_USER="${DB_ROOT_USER:-root}"
DB_ROOT_PASS="${DB_ROOT_PASS:-}"
SSH_USER="${SSH_USER:-root}"
SSH_PASS="${SSH_PASS:-}"
ALLOW_FROM_IP="${ALLOW_FROM_IP:-$PANDORA_HOST}"
DROP_DB="${DROP_DB:-1}"
REMOVE_DB_SERVER="${REMOVE_DB_SERVER:-1}"
REMOVE_DB_DATADIR="${REMOVE_DB_DATADIR:-1}"
REMOVE_MYSQL_CLIENT="${REMOVE_MYSQL_CLIENT:-1}"
REMOVE_REPOS="${REMOVE_REPOS:-1}"
REMOVE_PHP_HTTPD="${REMOVE_PHP_HTTPD:-1}"
REMOVE_HTTPD_CONTENT="${REMOVE_HTTPD_CONTENT:-1}"
REMOVE_FIREWALL_RULES="${REMOVE_FIREWALL_RULES:-1}"
REMOVE_USERS="${REMOVE_USERS:-1}"
CLEAN_SSH="${CLEAN_SSH:-0}"
REBOOT_HINT="${REBOOT_HINT:-1}"
info() { echo; echo "==> $*"; }
warn() { echo "WARN: $*"; }
ssh_exec() {
local cmd="$1"
if ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=5 \
"${SSH_USER}@${DB_HOST}" "true" >/dev/null 2>&1; then
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10 \
"${SSH_USER}@${DB_HOST}" "$cmd"
else
if ! command -v sshpass >/dev/null 2>&1; then
dnf install -y sshpass openssh-clients >/dev/null 2>&1 || true
fi
sshpass -p "${SSH_PASS}" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10 \
"${SSH_USER}@${DB_HOST}" "$cmd"
fi
}
stop_disable_services() {
local services=(
pandora_server pandora_agent_daemon pandora_websocket_engine pandora_iot_server pandora_made pandora_db
tentacle_serverd tentacle_rmm tentacle_clientd
mysqld mysql mariadb percona mysql-router mysqlrouter
httpd nginx php-fpm
)
info "Stopping and disabling Pandora/DB related services"
for s in "${services[@]}"; do
systemctl stop "$s" 2>/dev/null || true
systemctl disable "$s" 2>/dev/null || true
systemctl mask "$s" 2>/dev/null || true
systemctl reset-failed "$s" 2>/dev/null || true
done
systemctl daemon-reload || true
}
kill_leftovers_safely() {
info "Killing leftover Pandora/MySQL processes without killing this script"
local me="$$"
local pats='(^|/)(pandora_server|pandora_db|pandora_ha|pandora_agent|pandora_agent_daemon|tentacle_serverd|tentacle_clientd|tentacle_rmm|mysqld|mariadbd|mysqlrouter|httpd|nginx|php-fpm)([[:space:]]|$)'
local line pid cmd
local -a hits=()
while IFS= read -r line; do
[ -n "$line" ] && hits+=("$line")
done < <(pgrep -af "$pats" 2>/dev/null || true)
if [ "${#hits[@]}" -eq 0 ]; then
echo "No matching leftover processes"
return 0
fi
for line in "${hits[@]}"; do
pid="${line%% *}"
cmd="${line#* }"
[ -n "${pid:-}" ] || continue
[ "$pid" = "$me" ] && continue
echo "Killing PID $pid :: $cmd"
kill -9 "$pid" 2>/dev/null || true
done
sleep 2
}
remove_local_packages() {
info "Removing Pandora/Tentacle packages"
mapfile -t PFMS_PKGS < <(rpm -qa | grep -Ei 'pandora|pandorafms|tentacle' | sort -u || true)
if [ "${#PFMS_PKGS[@]}" -gt 0 ]; then
printf '%s\n' "${PFMS_PKGS[@]}"
dnf remove -y "${PFMS_PKGS[@]}" || rpm -e --nodeps "${PFMS_PKGS[@]}" || true
else
echo "No Pandora/Tentacle RPMs found"
fi
if [ "$REMOVE_DB_SERVER" = "1" ] || [ "$REMOVE_MYSQL_CLIENT" = "1" ]; then
info "Removing MySQL/Percona/MariaDB packages"
mapfile -t DB_PKGS < <(rpm -qa | grep -Ei '^(mysql|mysql80|mysql-shell|mysql-community|mysql-router|mysqlrouter|mysql-server|mysql-common|mysql-community-server|mysql-community-client|percona|Percona|mariadb|galera)' | sort -u || true)
if [ "${#DB_PKGS[@]}" -gt 0 ]; then
printf '%s\n' "${DB_PKGS[@]}"
dnf remove -y "${DB_PKGS[@]}" || rpm -e --nodeps "${DB_PKGS[@]}" || true
else
echo "No MySQL/Percona/MariaDB RPMs found"
fi
fi
}
remove_units_and_links() {
info "Removing service units, init scripts, rc links, cron, firewalld service files"
rm -f /etc/systemd/system/*pandora* /etc/systemd/system/*tentacle* /etc/systemd/system/*mysql* /etc/systemd/system/*mariadb* /etc/systemd/system/*percona* /etc/systemd/system/*httpd* /etc/systemd/system/*nginx* /etc/systemd/system/*php-fpm* 2>/dev/null || true
rm -f /usr/lib/systemd/system/*pandora* /usr/lib/systemd/system/*tentacle* /usr/lib/systemd/system/*mysql* /usr/lib/systemd/system/*mariadb* /usr/lib/systemd/system/*percona* /usr/lib/systemd/system/*httpd* /usr/lib/systemd/system/*nginx* /usr/lib/systemd/system/*php-fpm* 2>/dev/null || true
find /etc/systemd/system -type l \( -iname '*pandora*' -o -iname '*tentacle*' -o -iname '*mysql*' -o -iname '*mariadb*' -o -iname '*percona*' -o -iname '*httpd*' -o -iname '*nginx*' -o -iname '*php-fpm*' \) -delete 2>/dev/null || true
find /usr/lib/systemd/system -type l \( -iname '*pandora*' -o -iname '*tentacle*' -o -iname '*mysql*' -o -iname '*mariadb*' -o -iname '*percona*' -o -iname '*httpd*' -o -iname '*nginx*' -o -iname '*php-fpm*' \) -delete 2>/dev/null || true
rm -f /etc/init.d/pandora_* /etc/init.d/tentacle_* /etc/init.d/mysql* /etc/init.d/mariadb* /etc/init.d/percona* /etc/init.d/httpd /etc/init.d/nginx /etc/init.d/php-fpm 2>/dev/null || true
rm -f /etc/rc.d/rc?.d/K*pandora_* /etc/rc.d/rc?.d/K*tentacle_* /etc/rc.d/rc?.d/S*pandora_* /etc/rc.d/rc?.d/S*tentacle_* /etc/rc.d/rc?.d/*mysql* /etc/rc.d/rc?.d/*mariadb* /etc/rc.d/rc?.d/*percona* /etc/rc.d/rc?.d/*httpd* /etc/rc.d/rc?.d/*nginx* /etc/rc.d/rc?.d/*php-fpm* 2>/dev/null || true
rm -f /etc/cron.hourly/pandora_db /etc/cron.d/*pandora* /etc/cron.daily/*pandora* /etc/cron.hourly/*pandora* 2>/dev/null || true
rm -f /usr/lib/firewalld/services/tentacle.xml /usr/lib/firewalld/services/mysql.xml /usr/lib/firewalld/services/mariadb.xml /usr/lib/firewalld/services/http.xml /usr/lib/firewalld/services/https.xml 2>/dev/null || true
systemctl daemon-reload || true
}
remove_local_files() {
info "Removing Pandora files and directories"
rm -rf \
/var/www/html/pandora_console \
/usr/share/pandora_server \
/usr/share/pandora_agent \
/usr/lib/perl5/PandoraFMS \
/usr/lib64/perl5/PandoraFMS \
/opt/pandorafms \
/etc/pandora /etc/pandora_gotty /etc/tentacle \
/var/spool/pandora /var/log/pandora /var/lib/pandora /var/lib/pandorafms \
/var/cache/pandora* /tmp/percona_install_pandora_* /root/pandora_deploy_tmp* /tmp/par-* \
/run/pandora_ha.pid /var/run/pandora_ha.pid \
/etc/logrotate.d/pandora* /usr/lib/tmpfiles.d/pandora* \
/etc/httpd/conf.d/pandora.conf /etc/httpd/conf.d/timeout.conf \
/etc/nginx/conf.d/pandora*.conf /etc/php-fpm.d/pandora*.conf 2>/dev/null || true
rm -f /usr/bin/pandora_* /usr/bin/tentacle_* /usr/bin/pandorafsnmp /usr/bin/pandorawmic /usr/bin/braa 2>/dev/null || true
rm -f /usr/share/man/man1/pandora_server.1.gz /usr/share/man/man1/tentacle_server.1.gz 2>/dev/null || true
}
cleanup_local_db() {
[ "$DB_MODE" = "local" ] || return 0
info "Cleaning local Pandora database/user and local DB leftovers"
if [ "$DROP_DB" = "1" ] && command -v mysql >/dev/null 2>&1; then
MYSQL_PWD="$DB_ROOT_PASS" mysql -u"$DB_ROOT_USER" -h"$DB_HOST" -P"$DB_PORT" --protocol=tcp <<SQL || true
SET SESSION sql_log_bin=0;
DROP DATABASE IF EXISTS \`$DB_NAME\`;
DROP USER IF EXISTS '$DB_USER'@'%';
DROP USER IF EXISTS '$DB_USER'@'localhost';
DROP USER IF EXISTS '$DB_USER'@'127.0.0.1';
DROP USER IF EXISTS '$DB_USER'@'$ALLOW_FROM_IP';
FLUSH PRIVILEGES;
SQL
fi
systemctl stop mysqld mariadb 2>/dev/null || true
if [ "$REMOVE_DB_DATADIR" = "1" ]; then
rm -rf /var/lib/mysql /var/lib/mysql-files /var/lib/mysql-keyring /var/lib/mariadb /var/lib/percona 2>/dev/null || true
else
rm -rf "/var/lib/mysql/$DB_NAME" 2>/dev/null || true
fi
rm -rf /etc/my.cnf /etc/my.cnf.d /etc/mysql /etc/percona-server.conf.d /etc/percona \
/var/log/mysqld.log /var/log/mysql* /var/log/mariadb* /var/log/percona* \
/var/run/mysqld /run/mysqld /var/run/mysql /run/mysql \
/usr/lib/tmpfiles.d/mysql.conf /usr/lib/tmpfiles.d/mariadb.conf \
/etc/tmpfiles.d/mysql.conf /etc/tmpfiles.d/mariadb.conf 2>/dev/null || true
}
cleanup_remote_db() {
[ "$DB_MODE" = "remote" ] || return 0
info "Cleaning remote DB host ${DB_HOST}"
if [ "$DROP_DB" = "1" ]; then
ssh_exec "MYSQL_PWD='${DB_ROOT_PASS}' mysql -u'${DB_ROOT_USER}' -h'127.0.0.1' -P'${DB_PORT}' --protocol=tcp <<'SQL'
SET SESSION sql_log_bin=0;
DROP DATABASE IF EXISTS \`${DB_NAME}\`;
DROP USER IF EXISTS '${DB_USER}'@'%';
DROP USER IF EXISTS '${DB_USER}'@'localhost';
DROP USER IF EXISTS '${DB_USER}'@'127.0.0.1';
DROP USER IF EXISTS '${DB_USER}'@'${ALLOW_FROM_IP}';
FLUSH PRIVILEGES;
SQL" || true
fi
ssh_exec "systemctl stop mysqld mariadb 2>/dev/null || true; systemctl disable mysqld mariadb 2>/dev/null || true; systemctl mask mysqld mariadb 2>/dev/null || true; systemctl reset-failed mysqld mariadb 2>/dev/null || true" || true
if [ "$REMOVE_DB_SERVER" = "1" ]; then
ssh_exec "rpm -qa | grep -Ei '^(mysql|mysql80|mysql-shell|mysql-community|mysql-router|mysqlrouter|mysql-server|mysql-common|mysql-community-server|mysql-community-client|percona|Percona|mariadb|galera)' | xargs -r dnf remove -y || true" || true
fi
if [ "$REMOVE_DB_DATADIR" = "1" ]; then
ssh_exec "rm -rf /var/lib/mysql /var/lib/mysql-files /var/lib/mysql-keyring /var/lib/mariadb /var/lib/percona 2>/dev/null || true" || true
else
ssh_exec "rm -rf /var/lib/mysql/${DB_NAME} 2>/dev/null || true" || true
fi
ssh_exec "rm -rf /etc/my.cnf /etc/my.cnf.d /etc/mysql /etc/percona-server.conf.d /etc/percona /var/log/mysqld.log /var/log/mysql* /var/log/mariadb* /var/log/percona* /var/run/mysqld /run/mysqld /var/run/mysql /run/mysql /usr/lib/systemd/system/*mysql* /usr/lib/systemd/system/*mariadb* /usr/lib/systemd/system/*percona* /usr/lib/tmpfiles.d/mysql.conf /usr/lib/tmpfiles.d/mariadb.conf /etc/tmpfiles.d/mysql.conf /etc/tmpfiles.d/mariadb.conf 2>/dev/null || true" || true
}
remove_repos_and_web() {
if [ "$REMOVE_REPOS" = "1" ]; then
info "Removing Pandora/MySQL/Percona/MariaDB repository definitions"
rm -f /etc/yum.repos.d/*pandora* /etc/yum.repos.d/*mysql* /etc/yum.repos.d/*percona* /etc/yum.repos.d/*mariadb* 2>/dev/null || true
fi
if [ "$REMOVE_PHP_HTTPD" = "1" ]; then
info "Removing httpd/nginx/php-fpm/php packages as requested"
mapfile -t WEB_PKGS < <(rpm -qa | grep -Ei '^(httpd|httpd-tools|httpd-filesystem|mod_ssl|nginx|php|php-fpm|mod_php)' | sort -u || true)
if [ "${#WEB_PKGS[@]}" -gt 0 ]; then
printf '%s\n' "${WEB_PKGS[@]}"
dnf remove -y "${WEB_PKGS[@]}" || rpm -e --nodeps "${WEB_PKGS[@]}" || true
fi
fi
if [ "$REMOVE_HTTPD_CONTENT" = "1" ]; then
info "Removing Apache/Nginx/PHP content and configuration"
rm -rf /etc/httpd /var/log/httpd /var/cache/httpd /usr/share/httpd /var/www/html \
/etc/nginx /var/log/nginx /var/cache/nginx /usr/share/nginx \
/etc/php.ini /etc/php.d /etc/php-fpm.d /var/log/php-fpm /var/lib/php /var/cache/php* \
/run/httpd /var/run/httpd /run/php-fpm /var/run/php-fpm /run/nginx /var/run/nginx 2>/dev/null || true
fi
}
remove_users_and_firewall() {
if [ "$REMOVE_USERS" = "1" ]; then
info "Removing Pandora/MySQL related users and groups if they exist"
for u in pandora mysql apache nginx; do
if id "$u" >/dev/null 2>&1; then
userdel -r "$u" 2>/dev/null || userdel "$u" 2>/dev/null || true
fi
done
for g in pandora tentacle mysql apache nginx; do
if getent group "$g" >/dev/null 2>&1; then
groupdel "$g" 2>/dev/null || true
fi
done
fi
if [ "$REMOVE_FIREWALL_RULES" = "1" ] && command -v firewall-cmd >/dev/null 2>&1; then
info "Removing likely Pandora/MySQL firewall rules"
firewall-cmd --permanent --remove-service=mysql 2>/dev/null || true
firewall-cmd --permanent --remove-service=http 2>/dev/null || true
firewall-cmd --permanent --remove-service=https 2>/dev/null || true
firewall-cmd --permanent --remove-port=3306/tcp 2>/dev/null || true
firewall-cmd --permanent --remove-port=41121/tcp 2>/dev/null || true
firewall-cmd --permanent --remove-port=80/tcp 2>/dev/null || true
firewall-cmd --permanent --remove-port=443/tcp 2>/dev/null || true
firewall-cmd --reload 2>/dev/null || true
fi
}
clean_ssh_keys_mutual() {
[ "$CLEAN_SSH" = "1" ] || return 0
[ "$DB_MODE" = "remote" ] || return 0
info "Cleaning SSH authorized_keys entries (best-effort)"
ssh_exec "test -f /root/.ssh/authorized_keys && sed -i '/${PANDORA_HOST//./\\.}/d' /root/.ssh/authorized_keys || true" || true
if [ -f /root/.ssh/authorized_keys ]; then
sed -i "/${DB_HOST//./\\.}/d" /root/.ssh/authorized_keys || true
fi
}
clean_pkg_cache() {
info "Cleaning package metadata"
dnf clean all || true
rm -rf /var/cache/dnf /var/cache/yum 2>/dev/null || true
}
residual_checks() {
info "Residual checks"
echo "[rpm]"
rpm -qa | grep -Ei 'pandora|pandorafms|tentacle|^(mysql|mysql80|mysql-shell|mysql-community|mysql-router|mysqlrouter|mysql-server|mysql-common|mysql-community-server|mysql-community-client|percona|Percona|mariadb|galera)|^(httpd|httpd-tools|httpd-filesystem|mod_ssl|nginx|php|php-fpm|mod_php)' || true
echo "[services]"
systemctl list-unit-files | grep -Ei 'pandora|tentacle|mysql|mariadb|percona|httpd|nginx|php-fpm' || true
echo "[files]"
find /etc /usr /var /run /opt -maxdepth 4 \( -iname '*pandora*' -o -iname '*tentacle*' -o -iname '*mysql*' -o -iname '*mariadb*' -o -iname '*percona*' -o -iname '*httpd*' -o -iname '*nginx*' -o -iname '*php*' -o -iname '*apache*' \) 2>/dev/null | sort || true
if [ "$DB_MODE" = "local" ]; then
echo "[db query]"
if command -v mysql >/dev/null 2>&1; then
MYSQL_PWD="$DB_ROOT_PASS" mysql -u"$DB_ROOT_USER" -h"127.0.0.1" -P"$DB_PORT" --protocol=tcp -e "SHOW DATABASES LIKE '$DB_NAME'; SELECT User,Host FROM mysql.user WHERE User='$DB_USER';" || true
else
echo "mysql client not present"
fi
fi
}
main() {
echo "Starting merged Pandora cleanup"
echo "PANDORA_HOST=$PANDORA_HOST"
echo "DB_MODE=$DB_MODE"
echo "DB_HOST=$DB_HOST"
echo "DB_PORT=$DB_PORT"
echo "DB_NAME=$DB_NAME"
echo "DROP_DB=$DROP_DB REMOVE_DB_SERVER=$REMOVE_DB_SERVER REMOVE_DB_DATADIR=$REMOVE_DB_DATADIR"
echo "REMOVE_REPOS=$REMOVE_REPOS REMOVE_PHP_HTTPD=$REMOVE_PHP_HTTPD REMOVE_HTTPD_CONTENT=$REMOVE_HTTPD_CONTENT REMOVE_FIREWALL_RULES=$REMOVE_FIREWALL_RULES REMOVE_USERS=$REMOVE_USERS"
echo "LOGFILE=$LOGFILE"
stop_disable_services
kill_leftovers_safely
remove_local_packages
remove_units_and_links
remove_local_files
if [ "$DB_MODE" = "local" ]; then
cleanup_local_db
else
cleanup_remote_db
fi
remove_repos_and_web
remove_users_and_firewall
clean_ssh_keys_mutual
clean_pkg_cache
residual_checks
echo
echo "Done. Log: $LOGFILE"
if [ "$REBOOT_HINT" = "1" ]; then
echo "Recommended next step: reboot this node before running the Pandora installer again."
fi
}
main "$@"
Download Script Uninstall PandoraFMS
Download script pandorafms melalui github dibawah ini.


