fix: release v3.0.1 agent service cleanup

This commit is contained in:
JetSprow
2026-04-29 18:52:24 +10:00
parent a5f962db84
commit fa962cbe71
6 changed files with 189 additions and 75 deletions

View File

@@ -1,5 +1,5 @@
BINARY := jboard-agent
VERSION := 3.0.0
VERSION := 3.0.1
LDFLAGS := -s -w
.PHONY: build build-linux clean

View File

@@ -12,7 +12,7 @@ import (
"github.com/jboard/jboard-agent/internal/probe"
)
const version = "3.0.0"
const version = "3.0.1"
func main() {
debug.SetGCPercent(50)

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "j-board",
"version": "3.0.0",
"version": "3.0.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "j-board",
"version": "3.0.0",
"version": "3.0.1",
"dependencies": {
"@base-ui/react": "^1.4.1",
"@marsidev/react-turnstile": "^1.5.0",

View File

@@ -1,6 +1,6 @@
{
"name": "j-board",
"version": "3.0.0",
"version": "3.0.1",
"private": true,
"scripts": {
"dev": "next dev",

View File

@@ -146,73 +146,49 @@ Then restart x-ui and rerun this installer, or add XRAY_ACCESS_LOG_PATH=/usr/loc
HINT
}
ASSET="$(detect_asset)"
RESOLVED_TAG="$(resolve_release_tag)"
service_candidates() {
printf '%s\n' "$SERVICE_NAME" jboard-agent jboard-probe-agent j-board-agent jboard-probe \
| awk 'NF && !seen[$0]++'
}
if [ -z "$RESOLVED_TAG" ]; then
echo "Failed to resolve release tag for ${GH_REPO}" >&2
exit 1
agent_service_exists() {
local candidate="$1"
run_as_root_output test -f "/etc/systemd/system/${candidate}.service" 2>/dev/null \
|| run_as_root_output test -f "/lib/systemd/system/${candidate}.service" 2>/dev/null \
|| run_as_root_output test -f "/usr/lib/systemd/system/${candidate}.service" 2>/dev/null \
|| run_as_root_output systemctl is-active --quiet "${candidate}.service" 2>/dev/null \
|| run_as_root_output systemctl is-enabled --quiet "${candidate}.service" 2>/dev/null
}
remove_old_agent_services() {
local removed=0
local candidate=""
while IFS= read -r candidate; do
[ -n "$candidate" ] || continue
if agent_service_exists "$candidate"; then
echo "Removing old agent service: ${candidate}.service"
run_as_root systemctl stop "${candidate}.service" >/dev/null 2>&1 || true
run_as_root systemctl disable "${candidate}.service" >/dev/null 2>&1 || true
run_as_root systemctl reset-failed "${candidate}.service" >/dev/null 2>&1 || true
run_as_root rm -f \
"/etc/systemd/system/${candidate}.service" \
"/lib/systemd/system/${candidate}.service" \
"/usr/lib/systemd/system/${candidate}.service"
removed=1
fi
done < <(service_candidates)
DOWNLOAD_BASE="https://github.com/${GH_REPO}/releases/download/${RESOLVED_TAG}"
DOWNLOAD_URL="${DOWNLOAD_BASE}/${ASSET}"
CHECKSUM_URL="${DOWNLOAD_BASE}/SHA256SUMS"
echo "[1/9] Release tag: ${RESOLVED_TAG}"
echo "[2/9] Downloading probe agent binary: ${ASSET}"
curl -fsSL "$DOWNLOAD_URL" -o "$TMP_DIR/$ASSET"
if curl -fsSL "$CHECKSUM_URL" -o "$TMP_DIR/SHA256SUMS" 2>/dev/null; then
echo "[3/9] Verifying checksum..."
grep " ${ASSET}$" "$TMP_DIR/SHA256SUMS" > "$TMP_DIR/SHA256SUMS.current"
(
cd "$TMP_DIR"
if command -v sha256sum >/dev/null 2>&1; then
sha256sum -c SHA256SUMS.current >/dev/null
if [ "$removed" = "1" ]; then
run_as_root systemctl daemon-reload
else
shasum -a 256 -c SHA256SUMS.current >/dev/null
fi
)
else
echo "[3/9] Checksum file not found; skipping verification."
echo "No old agent service found."
fi
}
echo "[4/9] Installing binary..."
run_as_root install -m 0755 "$TMP_DIR/$ASSET" "${INSTALL_DIR}/jboard-agent"
run_as_root mkdir -p /var/log/jboard /var/lib/jboard-agent
if [ "$INSTALL_NEXTTRACE" = "1" ] && ! command -v nexttrace >/dev/null 2>&1; then
echo "[5/9] Installing nexttrace for route probing..."
curl -fsSL https://raw.githubusercontent.com/nxtrace/NTrace-core/main/nt_install.sh -o "$TMP_DIR/nt_install.sh"
run_as_root bash "$TMP_DIR/nt_install.sh"
else
echo "[5/9] nexttrace already installed or skipped."
fi
echo "[6/9] Detecting Xray access log..."
if prepare_xray_access_log; then
echo "Found Xray access log: ${XRAY_ACCESS_LOG_PATH}"
else
echo "Xray access log not found; continuing without node access risk telemetry."
fi
echo "[7/9] Writing environment file..."
ENV_TMP="$TMP_DIR/jboard-agent.env"
{
printf 'SERVER_URL=%q\n' "$SERVER_URL"
printf 'AUTH_TOKEN=%q\n' "$AUTH_TOKEN"
printf 'LATENCY_INTERVAL=%q\n' "$LATENCY_INTERVAL"
printf 'TRACE_INTERVAL=%q\n' "$TRACE_INTERVAL"
printf 'XRAY_ACCESS_LOG_PATH=%q\n' "$XRAY_ACCESS_LOG_PATH"
printf 'XRAY_LOG_INTERVAL=%q\n' "$XRAY_LOG_INTERVAL"
printf 'XRAY_LOG_STATE_FILE=%q\n' "$XRAY_LOG_STATE_FILE"
printf 'XRAY_LOG_START_AT_END=%q\n' "$XRAY_LOG_START_AT_END"
} > "$ENV_TMP"
run_as_root install -m 0600 "$ENV_TMP" "$ENV_FILE"
echo "[8/9] Writing systemd service..."
SERVICE_TMP="$TMP_DIR/${SERVICE_NAME}.service"
cat > "$SERVICE_TMP" <<SERVICE
write_systemd_service() {
local service_tmp="$TMP_DIR/${SERVICE_NAME}.service"
cat > "$service_tmp" <<SERVICE
[Unit]
Description=J-Board Probe Agent
After=network-online.target
@@ -229,9 +205,80 @@ MemoryMax=64M
[Install]
WantedBy=multi-user.target
SERVICE
run_as_root install -m 0644 "$SERVICE_TMP" "/etc/systemd/system/${SERVICE_NAME}.service"
run_as_root install -m 0644 "$service_tmp" "/etc/systemd/system/${SERVICE_NAME}.service"
}
echo "[9/9] Enabling and starting service..."
ASSET="$(detect_asset)"
RESOLVED_TAG="$(resolve_release_tag)"
if [ -z "$RESOLVED_TAG" ]; then
echo "Failed to resolve release tag for ${GH_REPO}" >&2
exit 1
fi
DOWNLOAD_BASE="https://github.com/${GH_REPO}/releases/download/${RESOLVED_TAG}"
DOWNLOAD_URL="${DOWNLOAD_BASE}/${ASSET}"
CHECKSUM_URL="${DOWNLOAD_BASE}/SHA256SUMS"
echo "[1/10] Release tag: ${RESOLVED_TAG}"
echo "[2/10] Downloading probe agent binary: ${ASSET}"
curl -fsSL "$DOWNLOAD_URL" -o "$TMP_DIR/$ASSET"
if curl -fsSL "$CHECKSUM_URL" -o "$TMP_DIR/SHA256SUMS" 2>/dev/null; then
echo "[3/10] Verifying checksum..."
grep " ${ASSET}$" "$TMP_DIR/SHA256SUMS" > "$TMP_DIR/SHA256SUMS.current"
(
cd "$TMP_DIR"
if command -v sha256sum >/dev/null 2>&1; then
sha256sum -c SHA256SUMS.current >/dev/null
else
shasum -a 256 -c SHA256SUMS.current >/dev/null
fi
)
else
echo "[3/10] Checksum file not found; skipping verification."
fi
echo "[4/10] Removing old agent service..."
remove_old_agent_services
echo "[5/10] Installing binary..."
run_as_root install -m 0755 "$TMP_DIR/$ASSET" "${INSTALL_DIR}/jboard-agent"
run_as_root mkdir -p /var/log/jboard /var/lib/jboard-agent
if [ "$INSTALL_NEXTTRACE" = "1" ] && ! command -v nexttrace >/dev/null 2>&1; then
echo "[6/10] Installing nexttrace for route probing..."
curl -fsSL https://raw.githubusercontent.com/nxtrace/NTrace-core/main/nt_install.sh -o "$TMP_DIR/nt_install.sh"
run_as_root bash "$TMP_DIR/nt_install.sh"
else
echo "[6/10] nexttrace already installed or skipped."
fi
echo "[7/10] Detecting Xray access log..."
if prepare_xray_access_log; then
echo "Found Xray access log: ${XRAY_ACCESS_LOG_PATH}"
else
echo "Xray access log not found; continuing without node access risk telemetry."
fi
echo "[8/10] Writing environment file..."
ENV_TMP="$TMP_DIR/jboard-agent.env"
{
printf 'SERVER_URL=%q\n' "$SERVER_URL"
printf 'AUTH_TOKEN=%q\n' "$AUTH_TOKEN"
printf 'LATENCY_INTERVAL=%q\n' "$LATENCY_INTERVAL"
printf 'TRACE_INTERVAL=%q\n' "$TRACE_INTERVAL"
printf 'XRAY_ACCESS_LOG_PATH=%q\n' "$XRAY_ACCESS_LOG_PATH"
printf 'XRAY_LOG_INTERVAL=%q\n' "$XRAY_LOG_INTERVAL"
printf 'XRAY_LOG_STATE_FILE=%q\n' "$XRAY_LOG_STATE_FILE"
printf 'XRAY_LOG_START_AT_END=%q\n' "$XRAY_LOG_START_AT_END"
} > "$ENV_TMP"
run_as_root install -m 0600 "$ENV_TMP" "$ENV_FILE"
echo "[9/10] Writing systemd service..."
write_systemd_service
echo "[10/10] Enabling and starting service..."
run_as_root systemctl daemon-reload
run_as_root systemctl enable --now "$SERVICE_NAME"

View File

@@ -178,6 +178,68 @@ Then restart x-ui and rerun this upgrade script, or add XRAY_ACCESS_LOG_PATH=/us
HINT
}
service_candidates() {
printf '%s\n' "$SERVICE_NAME" jboard-agent jboard-probe-agent j-board-agent jboard-probe \
| awk 'NF && !seen[$0]++'
}
agent_service_exists() {
local candidate="$1"
run_as_root_output test -f "/etc/systemd/system/${candidate}.service" 2>/dev/null \
|| run_as_root_output test -f "/lib/systemd/system/${candidate}.service" 2>/dev/null \
|| run_as_root_output test -f "/usr/lib/systemd/system/${candidate}.service" 2>/dev/null \
|| run_as_root_output systemctl is-active --quiet "${candidate}.service" 2>/dev/null \
|| run_as_root_output systemctl is-enabled --quiet "${candidate}.service" 2>/dev/null
}
remove_old_agent_services() {
local removed=0
local candidate=""
while IFS= read -r candidate; do
[ -n "$candidate" ] || continue
if agent_service_exists "$candidate"; then
echo "Removing old agent service: ${candidate}.service"
run_as_root systemctl stop "${candidate}.service" >/dev/null 2>&1 || true
run_as_root systemctl disable "${candidate}.service" >/dev/null 2>&1 || true
run_as_root systemctl reset-failed "${candidate}.service" >/dev/null 2>&1 || true
run_as_root rm -f \
"/etc/systemd/system/${candidate}.service" \
"/lib/systemd/system/${candidate}.service" \
"/usr/lib/systemd/system/${candidate}.service"
removed=1
fi
done < <(service_candidates)
if [ "$removed" = "1" ]; then
run_as_root systemctl daemon-reload
else
echo "No old agent service found."
fi
}
write_systemd_service() {
local service_tmp="$TMP_DIR/${SERVICE_NAME}.service"
cat > "$service_tmp" <<SERVICE
[Unit]
Description=J-Board Probe Agent
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
EnvironmentFile=${ENV_FILE}
ExecStart=${INSTALL_DIR}/jboard-agent
Restart=always
RestartSec=10
MemoryMax=64M
[Install]
WantedBy=multi-user.target
SERVICE
run_as_root install -m 0644 "$service_tmp" "/etc/systemd/system/${SERVICE_NAME}.service"
}
ASSET="$(detect_asset)"
RESOLVED_TAG="$(resolve_release_tag)"
@@ -190,12 +252,12 @@ DOWNLOAD_BASE="https://github.com/${GH_REPO}/releases/download/${RESOLVED_TAG}"
DOWNLOAD_URL="${DOWNLOAD_BASE}/${ASSET}"
CHECKSUM_URL="${DOWNLOAD_BASE}/SHA256SUMS"
echo "[1/6] Release tag: ${RESOLVED_TAG}"
echo "[2/6] Downloading probe agent binary: ${ASSET}"
echo "[1/7] Release tag: ${RESOLVED_TAG}"
echo "[2/7] Downloading probe agent binary: ${ASSET}"
curl -fsSL "$DOWNLOAD_URL" -o "$TMP_DIR/$ASSET"
if curl -fsSL "$CHECKSUM_URL" -o "$TMP_DIR/SHA256SUMS" 2>/dev/null; then
echo "[3/6] Verifying checksum..."
echo "[3/7] Verifying checksum..."
grep " ${ASSET}$" "$TMP_DIR/SHA256SUMS" > "$TMP_DIR/SHA256SUMS.current"
(
cd "$TMP_DIR"
@@ -206,14 +268,17 @@ if curl -fsSL "$CHECKSUM_URL" -o "$TMP_DIR/SHA256SUMS" 2>/dev/null; then
fi
)
else
echo "[3/6] Checksum file not found; skipping verification."
echo "[3/7] Checksum file not found; skipping verification."
fi
echo "[4/6] Installing binary..."
echo "[4/7] Removing old agent service..."
remove_old_agent_services
echo "[5/7] Installing binary..."
run_as_root install -m 0755 "$TMP_DIR/$ASSET" "${INSTALL_DIR}/jboard-agent"
run_as_root mkdir -p /var/log/jboard /var/lib/jboard-agent
echo "[5/6] Detecting Xray access log..."
echo "[6/7] Detecting Xray access log..."
if configure_xray_log_env; then
echo "Node access risk telemetry: enabled (${XRAY_ACCESS_LOG_PATH})"
else
@@ -221,8 +286,10 @@ else
print_xray_log_hint
fi
echo "[6/6] Restarting service..."
echo "[7/7] Writing service and starting..."
write_systemd_service
run_as_root systemctl daemon-reload
run_as_root systemctl enable "$SERVICE_NAME"
run_as_root systemctl restart "$SERVICE_NAME"
echo