AVX-only CPU + qemu 模拟 + Bun 运行时 · 赛博风格技术文档
当服务器 CPU 不支持 AVX2(如 Intel Xeon E5-2650v2),无法直接运行 Bun 二进制时,需通过 qemu-x86_64-static 模拟运行 Bun,部署 OpenCode Web 服务。
# 浅克隆,避免仓库过大超时
git clone --depth 1 https://用户名:私人令牌@gitee.com/xusuai/opencode-cn.git /opt/opencode-cn
用户名:令牌 格式,直接用令牌会 403。
--depth 1,否则 clone 会超时。
cd /opt/opencode-cn
qemu-x86_64-static /opt/bun/bun-linux-x64/bun install --ignore-scripts
--ignore-scripts!SIGILL(非法指令)崩溃。--ignore-scripts 是唯一解。
文件:/usr/local/bin/opencode-cn-launch.sh
#!/bin/bash
export HOME=/root
export OPENCODE_DISABLE_AUTOUPDATE=true
export OPENCODE_DISABLE_LSP_DOWNLOAD=true
export PATH="/opt/bun/bun-linux-x64:$PATH"
cd /opt/opencode-cn/packages/opencode
exec /usr/bin/qemu-x86_64-static /opt/bun/bun-linux-x64/bun run ./src/index.ts serve --port 8090 --hostname 0.0.0.0
chmod +x /usr/local/bin/opencode-cn-launch.sh
文件:/etc/systemd/system/opencode-cn.service
[Unit]
Description=OpenCode-CN Source Dev Mode (qemu + bun serve on port 8090)
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/opencode-cn-launch.sh
Restart=on-failure
RestartSec=5
Environment=HOME=/root
Environment=OPENCODE_DISABLE_AUTOUPDATE=true
Environment=OPENCODE_DISABLE_LSP_DOWNLOAD=true
WorkingDirectory=/opt/opencode-cn/packages/opencode
NoNewPrivileges=true
ProtectSystem=strict
ReadWritePaths=/opt/opencode-cn /root /tmp
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload && systemctl enable --now opencode-cn.service
# qemu 模拟下启动极慢,需循环等待
for i in $(seq 1 12); do
ss -tlnp | grep -q ':8090 ' && echo "READY after ${i}0s" && break
sleep 10
done
# 验证服务(curl 必须 -m 30 延长超时)
curl -m 30 -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8090/
curl 默认 10s 超时不够,必须用 -m 30。
使用 Hermes Cron Job 工具,每分钟检查:
systemctl is-active opencode-cn.service — 服务是否运行curl -m 30 返回 200 — 端口是否响应systemctl restart opencode-cn.servicesystemctl is-active opencode-cn.service # 期望: active
systemctl is-enabled opencode-cn.service # 期望: enabled
ss -tlnp | grep 8090 # 期望: LISTEN
curl -m 30 -s http://127.0.0.1:8090/ # 期望: HTML 内容
--depth 1 浅克隆用户名:令牌--ignore-scripts-m 30 延长