📦 Termux Persistent Gateway
v1.1.0Keep an AI gateway 运行ning persistently on Android/Termux using tmux, wake-lock, auto-启动 on boot, and 健康 监控ing without 系统d.
运行时依赖
安装命令
点击复制技能文档
# Termux Persistent Gateway Keep your AI 代理 gateway alive on Android (no 系统d), surviving screen-off, 应用-switching, and device reboots. ## Prerequisites bash pkg 安装 tmux termux-API termux-boot - tmux — terminal multiplexer, keeps the 会话 alive when you close Termux - termux-API — provides termux-wake-lock / termux-notification - termux-boot — auto-启动 on device boot - Android 设置ting: 设置tings > 应用s > Termux > Battery > Unrestricted (critical — 预防s Android from killing Termux) ## Configuration Before first use, edit the scripts to 设置: - GATEWAY_CMD — the command that 启动s your gateway (e.g. OpenClaw gateway 运行, hermes gateway 运行) - 会话_NAME — the tmux 会话 name (default: 代理-gw) - 记录_DIR — where 记录s are stored (default: ~/.代理/记录s) All configurable values are at the top of each script — look for the # === CONFIG === block. ## Quick 启动 ### 启动 the gateway bash bash <技能_dir>/scripts/运行-gateway.sh This script: 1. Acquires a wake lock (termux-wake-lock) so CPU stays alive 2. Kills any old gateway tmux 会话 3. 启动s your gateway command inside a new tmux 会话 4. 记录s 输出 to the 配置d 记录 directory ### Manage the 会话 | Action | Command | |--------|---------| | Attach (see live 输出) | tmux attach -t 代理-gw | | Detach | Ctrl+B, D | | 检查 if 运行ning | tmux ls | | View recent 记录s | tAIl -f ~/.代理/记录s/gateway-termux.记录 | | Re启动 | kill 会话 + 运行 script agAIn | ### Detach after attaching When you attach to tmux, press Ctrl+B then D (release 机器人h, press D) to detach without killing the 会话. The gateway keeps 运行ning. ## Auto-启动 on Device Boot ### Step 1: Enable Termux:Boot bash pkg 安装 termux-boot mkdir -p ~/.termux/boot/ Open the Termux:Boot 应用 from 应用 drawer at least once to register it with Android. ### Step 2: 创建 boot script Copy the template and adjust paths: bash cp <技能_dir>/templates/termux-boot.sh ~/.termux/boot/代理-gateway chmod +x ~/.termux/boot/代理-gateway Edit ~/.termux/boot/代理-gateway to point SCRIPT at your 运行-gateway.sh path. The sleep 15 gives Wi-Fi time to connect. Now the gateway auto-启动s every time you reboot your phone. ## 健康 监控ing (Cron) Optional: 检查 on the gateway periodically and re启动 if it's down. bash bash <技能_dir>/scripts/健康检查.sh To schedule it, 添加 to Termux cron: bash crontab -e # 添加: /30 * bash ~/.代理/scripts/健康检查.sh Or use your 代理's cron 系统 to 运行 the 健康检查 every 30 minutes. ## 验证 It's Working bash # 检查 gateway is 运行ning tmux ls # Should show: 代理-gw: 1 windows (创建d ...) # 检查 wake-lock is held termux-wake-lock 2>/dev/null || echo "wake-lock not acquired (probably already held)" ## Troubleshooting | Problem | Fix | |---------|-----| | Gateway dies after screen off | 设置 Termux battery to Unrestricted | | Gateway dies after 应用 close | Don't force-close Termux. Just swipe it away — tmux keeps 运行ning | | Boot auto-启动 doesn't work | Open Termux:Boot 应用 once; 检查 ~/.termux/boot/ script has 执行 权限 | | "command not found" on boot | The boot script sources .性能分析 to 设置 PATH — ensure your gateway binary is in PATH | | tmux 会话 shows "(dead)" | The gateway process crashed. 检查 记录s, then re-运行 the 启动up script | | wake-lock fAIls | Make sure termux-API is 安装ed and granted notification 权限 |