merge: p12-agent-rename (agent 改名 xui-agent+脚本迁移)
CI / go-test (push) Waiting to run
CI / postgres-durable-first (push) Waiting to run
CI / codegen (push) Waiting to run
CI / govulncheck (push) Waiting to run
CI / race (push) Waiting to run
CI / fuzz-smoke (push) Waiting to run
CI / golangci (push) Waiting to run
CI / frontend (push) Waiting to run
CodeQL Advanced / Analyze (go) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
Docs CI / build (push) Waiting to run
Docs Deploy (GitHub Pages) / build (push) Waiting to run
Docs Deploy (GitHub Pages) / deploy (push) Blocked by required conditions
Release 3X-UI / build (386) (push) Waiting to run
Release 3X-UI / build (amd64) (push) Waiting to run
Release 3X-UI / build (arm64) (push) Waiting to run
Release 3X-UI / build (armv5) (push) Waiting to run
Release 3X-UI / build (armv6) (push) Waiting to run
Release 3X-UI / build (armv7) (push) Waiting to run
Release 3X-UI / build (s390x) (push) Waiting to run
Release 3X-UI / Build for Windows (amd64) (push) Waiting to run
Release 3X-UI / Publish rolling dev release (push) Blocked by required conditions

This commit is contained in:
Muse
2026-10-22 18:40:28 +08:00
5 changed files with 32 additions and 11 deletions
+2 -2
View File
@@ -45,8 +45,8 @@ cp geoip.dat geosite.dat /usr/local/x-ui/bin/
```bash ```bash
mkdir -p /usr/local/x-ui/bin /etc/x-ui mkdir -p /usr/local/x-ui/bin /etc/x-ui
# 1. 放同一个 x-ui 二进制(与主控同版本) # 1. 放同一个二进制(与主控同版本),在节点上改名为 xui-agent(与主控进程区分、避免同机覆盖)
cp x-ui-linux-amd64 /usr/local/x-ui/x-ui && chmod +x /usr/local/x-ui/x-ui cp x-ui-linux-amd64 /usr/local/x-ui/xui-agent && chmod +x /usr/local/x-ui/xui-agent
# 2. 放 xray 二进制与 geo 文件(agent 不负责下载,需手动放置) # 2. 放 xray 二进制与 geo 文件(agent 不负责下载,需手动放置)
cp xray-linux-amd64 /usr/local/x-ui/bin/xray && chmod +x /usr/local/x-ui/bin/xray cp xray-linux-amd64 /usr/local/x-ui/bin/xray && chmod +x /usr/local/x-ui/bin/xray
+2 -2
View File
@@ -37,8 +37,8 @@ curl -sk -H "Authorization: Bearer <PANEL_API_TOKEN>" \
```bash ```bash
mkdir -p /usr/local/x-ui/bin /etc/x-ui mkdir -p /usr/local/x-ui/bin /etc/x-ui
# 1. 放 x-ui 二进制(agent 补丁版,与主控同版本) # 1. 放 x-ui 二进制(agent 补丁版,与主控同版本),在节点上改名为 xui-agent(与主控进程区分)
cp x-ui /usr/local/x-ui/x-ui && chmod +x /usr/local/x-ui/x-ui cp x-ui /usr/local/x-ui/xui-agent && chmod +x /usr/local/x-ui/xui-agent
# 2. 放 xray 二进制与 geo 文件(agent 不负责下载,手动放置) # 2. 放 xray 二进制与 geo 文件(agent 不负责下载,手动放置)
cp xray-linux-amd64 /usr/local/x-ui/bin/xray && chmod +x /usr/local/x-ui/bin/xray cp xray-linux-amd64 /usr/local/x-ui/bin/xray && chmod +x /usr/local/x-ui/bin/xray
+26 -5
View File
@@ -7,6 +7,12 @@
# XUI_ROOT 安装路径前缀(假根目录验证用),默认空 = 真实路径 # XUI_ROOT 安装路径前缀(假根目录验证用),默认空 = 真实路径
# XUI_INIT_SYSTEM 强制 init 系统: systemd | openrc | none,默认 auto 探测 # XUI_INIT_SYSTEM 强制 init 系统: systemd | openrc | none,默认 auto 探测
# XUI_URL agent 二进制下载地址覆盖 # XUI_URL agent 二进制下载地址覆盖
#
# 二进制命名(P12 改名):agent 独立装为 /usr/local/x-ui/xui-agent,不再与主控共用
# x-ui 文件——①ps 里进程名即 xui-agent,与主控一眼可辨;②同机部署时 agent 的
# 安装/升级永不写主控文件,不再撞 Text file busy;③进程清理只按 "xui-agent agent"
# 精确匹配 agent 自身。存量旧 agent 的进程形态是 "x-ui agent"(带 agent 子命令),
# 与主控的裸 "x-ui"(无参数)天然可区分,迁移清理只杀前者、绝不误杀主控。
set -e set -e
@@ -44,14 +50,17 @@ XRAY_VER="26.6.27"
ROOT="${XUI_ROOT:-}" ROOT="${XUI_ROOT:-}"
XUI_HOME="${ROOT}/usr/local/x-ui" XUI_HOME="${ROOT}/usr/local/x-ui"
CONF_DIR="${ROOT}/etc/x-ui" CONF_DIR="${ROOT}/etc/x-ui"
AGENT_BIN="${XUI_HOME}/x-ui" AGENT_BIN="${XUI_HOME}/xui-agent"
info "创建目录..." info "创建目录..."
mkdir -p "${XUI_HOME}/bin" "${CONF_DIR}" mkdir -p "${XUI_HOME}/bin" "${CONF_DIR}"
info "下载 agent 二进制..." info "下载 agent 二进制..."
curl -fL -o "${AGENT_BIN}" "$XUI_URL" || error "agent 下载失败" # 先下到 .new 再改名覆盖:改名是原子替换,正在运行的旧 agent 进程不受影响,
chmod +x "${AGENT_BIN}" # 也不会因目标文件正被执行而报 Text file busy;全程只写 xui-agent,不碰主控的 x-ui。
curl -fL -o "${AGENT_BIN}.new" "$XUI_URL" || error "agent 下载失败"
chmod +x "${AGENT_BIN}.new"
mv -f "${AGENT_BIN}.new" "${AGENT_BIN}"
info "下载 xray v${XRAY_VER}..." info "下载 xray v${XRAY_VER}..."
cd "${XUI_HOME}/bin" cd "${XUI_HOME}/bin"
@@ -121,6 +130,15 @@ probe_master() {
probe_master probe_master
# 存量迁移清理:旧版脚本把 agent 装在主控文件 x-ui 上(进程形态 "x-ui agent"),
# 重跑本脚本升级时先停掉这类旧进程,服务定义随后会被新单元覆盖。
# 安全边界:只精确匹配带 agent 子命令的旧路径进程;主控是裸 x-ui(无 agent 参数),
# 同机部署时绝不误杀。本脚本任何地方都不写、不删主控文件 x-ui 本身——agent-only
# 节点上它在迁移后成为无用残留,确认该机不跑主控后可人工删除。
stop_legacy_agent() {
pkill -f "${XUI_HOME}/x-ui agent" 2>/dev/null || true
}
detect_init_system() { detect_init_system() {
case "${XUI_INIT_SYSTEM:-auto}" in case "${XUI_INIT_SYSTEM:-auto}" in
systemd|openrc|none) echo "${XUI_INIT_SYSTEM}"; return;; systemd|openrc|none) echo "${XUI_INIT_SYSTEM}"; return;;
@@ -144,7 +162,7 @@ Description=3x-ui agent
After=network.target After=network.target
[Service] [Service]
ExecStart=/usr/local/x-ui/x-ui agent ExecStart=/usr/local/x-ui/xui-agent agent
Restart=on-failure Restart=on-failure
RestartSec=5 RestartSec=5
@@ -157,6 +175,7 @@ EOF
return 0 return 0
fi fi
systemctl stop x-ui-agent 2>/dev/null || true systemctl stop x-ui-agent 2>/dev/null || true
stop_legacy_agent
pkill -f "${AGENT_BIN} agent" 2>/dev/null || true; sleep 1 pkill -f "${AGENT_BIN} agent" 2>/dev/null || true; sleep 1
systemctl daemon-reload systemctl daemon-reload
systemctl enable x-ui-agent systemctl enable x-ui-agent
@@ -183,7 +202,7 @@ start_via_openrc() {
name="x-ui-agent" name="x-ui-agent"
description="3x-ui lightweight node agent" description="3x-ui lightweight node agent"
command="/usr/local/x-ui/x-ui" command="/usr/local/x-ui/xui-agent"
command_args="agent" command_args="agent"
command_background="yes" command_background="yes"
pidfile="/run/x-ui-agent.pid" pidfile="/run/x-ui-agent.pid"
@@ -201,6 +220,7 @@ EOF
return 0 return 0
fi fi
rc-service x-ui-agent stop 2>/dev/null || true rc-service x-ui-agent stop 2>/dev/null || true
stop_legacy_agent
pkill -f "${AGENT_BIN} agent" 2>/dev/null || true; sleep 1 pkill -f "${AGENT_BIN} agent" 2>/dev/null || true; sleep 1
rc-update add x-ui-agent default rc-update add x-ui-agent default
rc-service x-ui-agent restart rc-service x-ui-agent restart
@@ -221,6 +241,7 @@ EOF
start_via_nohup() { start_via_nohup() {
warn "未检测到 systemd / OpenRC,退回 nohup 方式启动" warn "未检测到 systemd / OpenRC,退回 nohup 方式启动"
warn "注意:nohup 方式没有开机自启,机器重启后 agent 不会自动恢复,需手动重跑本脚本!" warn "注意:nohup 方式没有开机自启,机器重启后 agent 不会自动恢复,需手动重跑本脚本!"
stop_legacy_agent
pkill -f "${AGENT_BIN} agent" 2>/dev/null || true; sleep 1 pkill -f "${AGENT_BIN} agent" 2>/dev/null || true; sleep 1
# -config 显式给出(生产环境即其默认路径 /etc/x-ui/agent.json,行为不变), # -config 显式给出(生产环境即其默认路径 /etc/x-ui/agent.json,行为不变),
# 这样 XUI_ROOT 假根验证时 agent 也能找到刚写下的配置。 # 这样 XUI_ROOT 假根验证时 agent 也能找到刚写下的配置。
+1 -1
View File
@@ -9,7 +9,7 @@ STOP=10
start_service() { start_service() {
procd_open_instance x-ui-agent procd_open_instance x-ui-agent
procd_set_param command /usr/local/x-ui/x-ui agent --config /etc/x-ui/agent.json procd_set_param command /usr/local/x-ui/xui-agent agent --config /etc/x-ui/agent.json
procd_set_param env XUI_BIN_FOLDER=/usr/local/x-ui/bin procd_set_param env XUI_BIN_FOLDER=/usr/local/x-ui/bin
procd_set_param respawn 3600 5 5 procd_set_param respawn 3600 5 5
procd_set_param stdout 1 procd_set_param stdout 1
+1 -1
View File
@@ -5,7 +5,7 @@ After=network.target
[Service] [Service]
Type=simple Type=simple
Environment=XUI_BIN_FOLDER=/usr/local/x-ui/bin Environment=XUI_BIN_FOLDER=/usr/local/x-ui/bin
ExecStart=/usr/local/x-ui/x-ui agent --config /etc/x-ui/agent.json ExecStart=/usr/local/x-ui/xui-agent agent --config /etc/x-ui/agent.json
Restart=on-failure Restart=on-failure
RestartSec=5 RestartSec=5
LimitNOFILE=1048576 LimitNOFILE=1048576