跳转到内容

回滚和运维

Tarsail 的运维命令保持接近 Docker Compose。它们是围绕固定远端目录结构和可预测 Compose 调用的薄封装。

显示远端 Compose 状态:

Terminal window
tarsail status

指定配置和密钥:

Terminal window
tarsail --config tarsail.production.yml --identity-file ~/.ssh/my-app-deploy-key status

它执行的远端命令等价于:

Terminal window
cd /opt/my-app
docker compose -p my-app --env-file current/.tarsail.env --env-file shared/.env -f current/compose.yaml ps

显示最近日志:

Terminal window
tarsail logs

查看某个服务:

Terminal window
tarsail logs web

控制行数:

Terminal window
tarsail logs --tail 500 web

持续跟随:

Terminal window
tarsail logs -f web

--tail 必须在 110000 之间。

服务名可以包含字母、数字、点、下划线和连字符。

回滚到上一个发布:

Terminal window
tarsail rollback

回滚会:

  • 列出 <target.path>/releases 下的发布;
  • current 符号链接检测当前发布;
  • 选择上一个发布;
  • 从上一个发布重新加载已打包镜像;
  • 更新 current
  • 执行 docker compose up -d
  • 输出状态。

Phase 0 的回滚不会请求确认。

回滚不会恢复:

  • 数据库;
  • Docker volumes;
  • current 外部的 bind-mounted 目录;
  • shared/ 文件;
  • DNS;
  • 证书;
  • 云防火墙规则;
  • 外部服务状态。

如果失败部署已经执行了破坏性迁移,tarsail rollback 无法撤销数据库变更。迁移安全和备份策略需要放在应用部署计划中。

预览并确认删除旧发布:

Terminal window
tarsail prune

跳过确认:

Terminal window
tarsail prune --yes

全局 --yes 也适用:

Terminal window
tarsail --yes prune

prune 会保留当前发布,并根据 deploy.keep_releases 保留最新发布。

prune 删除以下目录里的旧发布目录:

<target.path>/releases/

它不会删除:

  • 当前发布;
  • incoming/ 发布包;
  • shared/
  • Docker images;
  • Docker volumes;
  • 数据库;
  • Tarsail 目标路径外的文件。

排查时经常需要直接检查远端结构:

Terminal window
cd /opt/my-app
ls -la
ls -la releases
readlink current
docker compose -p my-app --env-file current/.tarsail.env --env-file shared/.env -f current/compose.yaml ps

查看当前发布 manifest:

Terminal window
cat current/manifest.json

确认 Compose 收到的 release ID:

Terminal window
cat current/.tarsail.env

日常维护建议:

  • 修改服务器访问、Docker 安装、配置路径或密钥下发方式后运行 doctor
  • 每次部署后运行 status
  • 回滚前先查看服务日志;
  • deploy.keep_releases 设置应满足回滚需要;
  • 确认近期发布健康后再 prune;
  • 数据库备份和迁移策略放在 Tarsail 外部;
  • 记录应用自己的端口、健康检查和恢复步骤。