Skip to content

Remote Scripts

Matrtex edited this page Jun 7, 2026 · 1 revision

远程执行

远程执行逻辑集中在 gcp_remote.py

执行模式

支持两种模式:

  • gcloud compute ssh/scp
  • 原生 ssh/scp

默认优先使用 gcloud 模式。只有显式传 --remote-method ssh 或本机无法使用 gcloud 时,才使用原生 SSH。

远程脚本

本地脚本位于 scripts/

脚本 用途
apt.sh Debian / Ubuntu 换源
dae.sh 安装 dae
net_iptables.sh 按月流量限额追加 iptables 限制
net_shutdown.sh 超额自动关机

上传脚本前会统一转换为 LF 行尾,避免 Windows CRLF 导致远程 shell 执行异常。

远程脚本执行命令内置 trap cleanup EXIT,正常和失败路径都会删除远端临时脚本。

dae 配置部署

deploy_dae_config() 会:

  1. 解析本地 config.dae
  2. 检测远程 OS。
  3. 上传到 /tmp/gcp_free_config_*.dae
  4. 复制到 /usr/local/etc/dae/config.dae
  5. 设置权限为 600
  6. enable 并 restart dae
  7. 删除远端临时文件。

如果上传后应用命令构建失败或应用步骤失败,会额外发起 rm -f 清理远端临时配置文件。清理失败只告警,不覆盖原始失败结果。

dry-run

dry-run 只打印命令,不实际执行远程操作:

.\start.ps1 run-script --project-id <项目ID> --account <账号邮箱> --instance <实例名> --zone <可用区> --dry-run apt

Clone this wiki locally