Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·132 lines (116 loc) · 4.07 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·132 lines (116 loc) · 4.07 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# install.sh — install hive scripts + systemd units.
# Run as root. Two modes:
#
# sudo ./install.sh # single-instance (back-compat)
# sudo ./install.sh --instance <name> # named instance for multi-agent
#
# Single-instance uses /etc/hive/agent.env and the non-templated
# units (hive.service etc.). Named instance uses the templated
# units (hive@<name>.service) and /etc/hive/<name>.env.
# You can mix both on the same host — each call installs what it needs.
#
# The kick-governor is always installed alongside the agent supervisor.
# It replaces the old per-agent kick timers (kick-scanner, kick-ci-maintainer,
# kick-architect, kick-outreach) with a single adaptive timer that adjusts
# cadences based on the live issue/PR queue depth across all 5 repos.
set -euo pipefail
# Per-agent timers superseded by kick-governor. Disabled on install.
LEGACY_KICK_TIMERS=(
kick-scanner.timer
kick-ci-maintainer.timer
kick-architect.timer
kick-outreach.timer
)
REPO_DIR="$(cd "$(dirname "$0")" && pwd)"
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
echo "usage: $0 [--instance <name>]" >&2
exit 1
;;
esac
done
if [ -n "$INSTANCE" ]; then
ENV_FILE="/etc/hive/${INSTANCE}.env"
UNIT_SUPERVISOR="hive@${INSTANCE}.service"
TEMPLATED=1
else
ENV_FILE="/etc/hive/agent.env"
UNIT_SUPERVISOR="hive.service"
TEMPLATED=0
fi
if [ "$(id -u)" -ne 0 ]; then
echo "install.sh must run as root (use sudo)" >&2
exit 1
fi
if [ ! -f "$ENV_FILE" ]; then
echo "Missing $ENV_FILE"
echo "Copy the template first:"
echo " sudo mkdir -p $(dirname "$ENV_FILE")"
echo " sudo install -m 600 $REPO_DIR/config/agent.env.example $ENV_FILE"
echo " sudo \$EDITOR $ENV_FILE"
exit 1
fi
# shellcheck disable=SC1090
set -a; . "$ENV_FILE"; set +a
for var in AGENT_USER AGENT_WORKDIR AGENT_LAUNCH_CMD AGENT_LOOP_PROMPT AGENT_LOG_FILE; do
if [ -z "${!var:-}" ]; then
echo "Required env var $var is empty in $ENV_FILE" >&2
exit 1
fi
done
if ! id "$AGENT_USER" >/dev/null 2>&1; then
echo "AGENT_USER '$AGENT_USER' does not exist on this system" >&2
exit 1
fi
echo "==> installing scripts to $BIN_DIR"
install -m 0755 "$REPO_DIR/bin/supervisor.sh" "$BIN_DIR/supervisor.sh"
install -m 0755 "$REPO_DIR/bin/agent-launch.sh" "$BIN_DIR/agent-launch.sh"
install -m 0755 "$REPO_DIR/bin/agent-healthcheck.sh" "$BIN_DIR/agent-healthcheck.sh"
install -m 0755 "$REPO_DIR/bin/kick-agents.sh" "$BIN_DIR/kick-agents.sh"
install -m 0755 "$REPO_DIR/bin/kick-governor.sh" "$BIN_DIR/kick-governor.sh"
install -m 0755 "$REPO_DIR/bin/notify.sh" "$BIN_DIR/notify.sh"
install -m 0755 "$REPO_DIR/bin/supervisor-kick.sh" "$BIN_DIR/supervisor-kick.sh"
install -m 0755 "$REPO_DIR/bin/hive-config.sh" "$BIN_DIR/hive-config.sh"
install -m 0755 "$REPO_DIR/bin/gh-wrapper.sh" "$BIN_DIR/gh-wrapper.sh"
# Clean up scripts from prior installs that no longer exist.
rm -f "$BIN_DIR/agent-supervisor.sh" "$BIN_DIR/agent-pause.sh"
if [ "$TEMPLATED" = 1 ]; then
UNITS=( "hive@.service" )
else
UNITS=( "hive.service" )
fi
echo "==> installing systemd units to $SYSTEMD_DIR (User=$AGENT_USER)"
for unit in "${UNITS[@]}"; do
sed "s/__AGENT_USER__/$AGENT_USER/g" "$REPO_DIR/systemd/$unit" \
> "$SYSTEMD_DIR/$unit"
chmod 0644 "$SYSTEMD_DIR/$unit"
done
echo "==> creating log dir for $AGENT_USER"
LOG_DIR="$(dirname "$AGENT_LOG_FILE")"
install -d -o "$AGENT_USER" -g "$AGENT_USER" -m 0755 "$LOG_DIR"
echo "==> systemctl daemon-reload"
systemctl daemon-reload
echo "==> enabling + starting units"
systemctl enable --now "$UNIT_SUPERVISOR"
echo
echo "Installed."
echo " systemctl status $UNIT_SUPERVISOR"
echo " journalctl -u $UNIT_SUPERVISOR -f"
echo
echo "Attach to the agent session:"
echo " sudo -u $AGENT_USER tmux attach -t ${AGENT_SESSION_NAME:-hive}"
echo " (Detach with Ctrl+B, D — the session keeps running.)"