mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 05:56:38 +08:00
[优化] 安装脚本更新
This commit is contained in:
@@ -161,7 +161,8 @@ curl -fsSL https://raw.githubusercontent.com/Rain-kl/ATSFlare/main/scripts/insta
|
||||
* `--server-url` 替换为实际控制面地址,例如 `http://192.168.1.10:3000`
|
||||
* 默认安装目录为 `/opt/atsflare-agent`
|
||||
* 脚本会创建 `atsflare-agent.service` 并启动 systemd 服务
|
||||
* 重复执行安装命令可用于升级 Agent 到最新 Release
|
||||
* 重复执行安装命令可用于重装或升级 Agent 到最新 Release
|
||||
* 重装时会先删除整个安装目录,再重新生成 `agent.json`、本地状态和二进制;旧数据不会保留
|
||||
|
||||
## 典型使用流程
|
||||
|
||||
|
||||
+14
-13
@@ -415,19 +415,20 @@ curl -fsSL https://raw.githubusercontent.com/Rain-kl/ATSFlare/main/scripts/insta
|
||||
| `--repo` | GitHub Release 仓库 | `Rain-kl/ATSFlare` |
|
||||
| `--no-service` | 不创建 systemd 服务 | - |
|
||||
|
||||
安装脚本会:
|
||||
|
||||
1. 从 GitHub Releases 下载最新 Agent 二进制(`atsflare-agent-{os}-{arch}`)
|
||||
2. 先下载到临时文件,再替换安装目录中的 Agent 二进制,避免覆盖运行中进程导致写入失败
|
||||
3. 生成 `agent.json` 配置文件
|
||||
4. 创建 systemd 服务 `atsflare-agent.service`
|
||||
5. 启动并启用自启
|
||||
|
||||
说明:
|
||||
|
||||
* 脚本可重复执行,用于升级到最新 Release
|
||||
* 若检测到已运行的 `atsflare-agent` systemd 服务,会先停止服务、替换二进制,再重新启动
|
||||
* 已存在的 `agent.json` 不会被覆盖
|
||||
安装脚本会:
|
||||
|
||||
1. 从 GitHub Releases 下载最新 Agent 二进制(`atsflare-agent-{os}-{arch}`)
|
||||
2. 若检测到已存在安装目录,会先停止运行中的 `atsflare-agent` 服务并删除整个安装目录
|
||||
3. 先下载到临时文件,再写入全新的安装目录,避免覆盖运行中进程导致写入失败
|
||||
4. 生成 `agent.json` 配置文件
|
||||
5. 创建 systemd 服务 `atsflare-agent.service`
|
||||
6. 启动并启用自启
|
||||
|
||||
说明:
|
||||
|
||||
* 脚本可重复执行,用于重装或升级到最新 Release
|
||||
* 若检测到已运行的 `atsflare-agent` systemd 服务,会先停止服务、清空安装目录,再重新安装
|
||||
* 重装会删除旧的 `agent.json`、本地状态、缓存数据和旧二进制,因此节点会按新的 Token 或 Discovery Token 重新接入
|
||||
|
||||
### 7.2 管理端生成部署命令
|
||||
|
||||
|
||||
+19
-15
@@ -37,6 +37,10 @@ Examples:
|
||||
|
||||
# Install with node-specific token
|
||||
install-agent.sh --server-url http://10.0.0.1:3000 --agent-token node-token-xyz
|
||||
|
||||
Notes:
|
||||
Reinstall will remove the entire install directory before installing again,
|
||||
including the old agent.json, local state, cached data, and downloaded binary.
|
||||
EOF
|
||||
exit 0
|
||||
}
|
||||
@@ -99,13 +103,9 @@ fi
|
||||
TAG=$(echo "$RELEASE_INFO" | grep -o '"tag_name"[[:space:]]*:[[:space:]]*"[^"]*"' | grep -o '"[^"]*"$' | tr -d '"')
|
||||
echo "Latest release: ${TAG}"
|
||||
|
||||
# Create install directory
|
||||
echo "Installing to ${INSTALL_DIR}..."
|
||||
mkdir -p "${INSTALL_DIR}/data"
|
||||
|
||||
# Download binary
|
||||
echo "Downloading ${ASSET_NAME}..."
|
||||
TMP_BINARY="$(mktemp "${INSTALL_DIR}/atsflare-agent.tmp.XXXXXX")"
|
||||
TMP_BINARY="$(mktemp "/tmp/atsflare-agent.tmp.XXXXXX")"
|
||||
cleanup() {
|
||||
rm -f "$TMP_BINARY"
|
||||
}
|
||||
@@ -117,19 +117,26 @@ chmod +x "$TMP_BINARY"
|
||||
SERVICE_WAS_ACTIVE="false"
|
||||
if [[ "$OS" == "linux" && "$SYSTEMCTL_AVAILABLE" == "true" ]] && systemctl is-active --quiet "$SERVICE_NAME"; then
|
||||
SERVICE_WAS_ACTIVE="true"
|
||||
echo "Stopping running service before upgrade..."
|
||||
echo "Stopping running service before reinstall..."
|
||||
systemctl stop "$SERVICE_NAME"
|
||||
fi
|
||||
|
||||
if [[ -d "$INSTALL_DIR" ]]; then
|
||||
echo "Removing existing installation directory: ${INSTALL_DIR}"
|
||||
rm -rf "$INSTALL_DIR"
|
||||
fi
|
||||
|
||||
echo "Installing to ${INSTALL_DIR}..."
|
||||
mkdir -p "${INSTALL_DIR}/data"
|
||||
|
||||
mv -f "$TMP_BINARY" "${INSTALL_DIR}/atsflare-agent"
|
||||
trap - EXIT
|
||||
|
||||
# Generate config
|
||||
CONFIG_FILE="${INSTALL_DIR}/agent.json"
|
||||
if [[ ! -f "$CONFIG_FILE" ]]; then
|
||||
echo "Generating agent.json..."
|
||||
if [[ -n "$AGENT_TOKEN" ]]; then
|
||||
cat > "$CONFIG_FILE" <<CFGEOF
|
||||
echo "Generating agent.json..."
|
||||
if [[ -n "$AGENT_TOKEN" ]]; then
|
||||
cat > "$CONFIG_FILE" <<CFGEOF
|
||||
{
|
||||
"server_url": "${SERVER_URL}",
|
||||
"agent_token": "${AGENT_TOKEN}",
|
||||
@@ -139,8 +146,8 @@ if [[ ! -f "$CONFIG_FILE" ]]; then
|
||||
"request_timeout": 10000
|
||||
}
|
||||
CFGEOF
|
||||
else
|
||||
cat > "$CONFIG_FILE" <<CFGEOF
|
||||
else
|
||||
cat > "$CONFIG_FILE" <<CFGEOF
|
||||
{
|
||||
"server_url": "${SERVER_URL}",
|
||||
"discovery_token": "${DISCOVERY_TOKEN}",
|
||||
@@ -150,9 +157,6 @@ CFGEOF
|
||||
"request_timeout": 10000
|
||||
}
|
||||
CFGEOF
|
||||
fi
|
||||
else
|
||||
echo "Config file already exists, skipping generation"
|
||||
fi
|
||||
|
||||
# Create systemd service
|
||||
|
||||
Reference in New Issue
Block a user