Repository navigation
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·107 lines (93 loc) · 3.08 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·107 lines (93 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
# uninstall.sh — remove hive scripts + systemd units.
# Two modes:
#
# sudo ./uninstall.sh # remove single-instance + scripts + templates
# sudo ./uninstall.sh --instance <name> # remove just that named instance
#
# Env files under /etc/hive/ and heartbeat log files are left
# intact in both modes.
set -euo pipefail
BIN_DIR="/usr/local/bin"
SYSTEMD_DIR="/etc/systemd/system"
INSTANCE=""
while [ $# -gt 0 ]; do
case "$1" in
--instance) INSTANCE="$2"; shift 2 ;;
--instance=*) INSTANCE="${1#--instance=}"; shift ;;
*) echo "unknown flag: $1" >&2; exit 1 ;;
esac
done
if [ "$(id -u)" -ne 0 ]; then
echo "uninstall.sh must run as root (use sudo)" >&2
exit 1
fi
load_env_if_present() {
local env="$1"
if [ -f "$env" ]; then
# shellcheck disable=SC1090
set -a; . "$env"; set +a
fi
}
kill_session_if_present() {
if [ -n "${AGENT_USER:-}" ] && id "$AGENT_USER" >/dev/null 2>&1; then
sudo -u "$AGENT_USER" tmux kill-session -t "${AGENT_SESSION_NAME:-hive}" 2>/dev/null || true
fi
}
if [ -n "$INSTANCE" ]; then
# Remove just this named instance. Leave shared scripts + templated unit
# files in place because other instances may use them.
load_env_if_present "/etc/hive/${INSTANCE}.env"
kill_session_if_present
echo "==> stopping + disabling instance $INSTANCE"
for unit in \
"hive@${INSTANCE}.service" \
"supervised-agent@${INSTANCE}.service"; do
systemctl disable --now "$unit" 2>/dev/null || true
done
systemctl daemon-reload
echo
echo "Instance '$INSTANCE' removed."
echo "Left intact: /etc/hive/${INSTANCE}.env, heartbeat log, shared scripts and templated units."
exit 0
fi
# Full uninstall: stop everything, remove scripts and all unit files (both
# single-instance and templated).
load_env_if_present "/etc/hive/agent.env"
kill_session_if_present
echo "==> stopping + disabling single-instance units"
for unit in \
hive.service \
supervised-agent@scanner.service \
supervised-agent@ci-maintainer.service \
supervised-agent@architect.service \
supervised-agent@outreach.service \
supervised-agent@supervisor.service; do
systemctl disable --now "$unit" 2>/dev/null || true
done
echo "==> removing unit files (single + templated + legacy)"
for unit in \
hive.service \
"hive@.service" \
"supervised-agent@.service" \
agent-healthcheck.service \
agent-healthcheck.timer \
agent-renew.service \
agent-renew.timer; do
rm -f "$SYSTEMD_DIR/$unit"
done
echo "==> removing scripts"
rm -f "$BIN_DIR/supervisor.sh" "$BIN_DIR/agent-healthcheck.sh" \
"$BIN_DIR/agent-launch.sh" "$BIN_DIR/kick-agents.sh" \
"$BIN_DIR/kick-governor.sh" "$BIN_DIR/notify.sh" \
"$BIN_DIR/supervisor-kick.sh" "$BIN_DIR/hive-config.sh" \
"$BIN_DIR/gh-wrapper.sh"
# Clean up legacy names from prior installs.
rm -f "$BIN_DIR/agent-supervisor.sh" "$BIN_DIR/agent-pause.sh"
echo "==> systemctl daemon-reload"
systemctl daemon-reload
echo
echo "Removed scripts + all unit files. Left intact:"
echo " /etc/hive/*.env"
echo " Heartbeat log files"
echo " /tmp/hive-healthcheck/ (state dir, wiped on reboot)"