Town CLI
town start
后台启动 Town runtime
town start
后台启动 Town runtime。
启动时会初始化 Town runtime 的 registry 和进程状态。
如果当前还没有任何本机 token,启动过程会自动初始化一个 console-bootstrap token,并在启动日志里显示一次明文 token。
启动过程还会尝试自动发现当前机器的公网 IP,并写入 City 侧 Env 的 DOWNCITY_PUBLIC_HOST。后续 agent 生成 contact link 时会优先使用这个地址,避免 link code 回退到 127.0.0.1。
在交互式终端中,直接运行裸 town 也会打开 Town manager,可以在里面选择启动、停止、重启和查看总览,不需要手动输入子命令。
如果你希望一并启动 Console,请使用 town start --console、town start -a 或 town start -p。
如果你传入 -p/--public 或 -h/--host,CLI 也会自动一并启动 Console。
如果你之前通过 town public 开启过持久化公网模式,那么普通 town start 也会沿用这份已保存的 Console 绑定,除非本次显式覆盖。
用法
town starttown start --consoletown start -p常用参数
-a, --all:同时启动 Console--console:同时启动 Console-p, --public [enabled]:以公网模式启动 Console,并绑定0.0.0.0-h, --host <host>:Console 主机;传入后默认同时启动 Console
对外访问
- 默认
town start只启动 runtime,不暴露 Web Console。 town start --console默认仍绑定127.0.0.1:5315。town start -p会自动启动 Console,并把监听地址切到0.0.0.0:5315,适合服务器对外访问。town public on可以把这类公网 Console 行为持久化到后续普通town start。- 如果绑定的是
0.0.0.0,外部访问时请使用服务器实际 IP 或域名,而不是127.0.0.1。 - 在公网模式下,启动结果会额外打印
Public URL。 - 如果机器本身拿不到公网 IP(例如处在 NAT / SLB / 反向代理后面),请在可达服务器、域名或 tunnel 后启动 Town。
town start会把自动发现的公网 IP 保存为全局DOWNCITY_PUBLIC_HOST;如果部署环境已经注入DOWNCITY_PUBLIC_URL或DOWNCITY_PUBLIC_HOST,不会覆盖已有值。
端口说明
5314:Town runtime API 端口,用于health、托管 plugin、plugin 等接口。5315:Console Web UI 端口,用于浏览器访问控制台。
相关命令
示例输出(基于当前实现)
以下示例直接对齐 cli/town/src 当前命令实现(含默认输出模式与字段结构),示例值使用占位符表示。
$ town start --console
town v1.0.0
✅ Town runtime started
pid: <runtimePid>
log: <bayRuntimeLogPath>
port: 5314
usage: Runtime API / managed-plugin endpoints (health, plugin, task, chat)
✅ Console started
pid: <consolePid>
url: http://127.0.0.1:5315
public_url: http://203.0.113.10:5315
log: <consoleLogPath>
port: 5315
usage: Console Web UI / Town gateway
✅ Console token initialized
subject: local-cli
name: console-bootstrap
token: dc_xxx
next: 把上面的 Bearer Token 粘贴到 Console UI / Extension$ town start
town v1.0.0
✅ Town runtime started
pid: <runtimePid>
log: <bayRuntimeLogPath>
port: 5314
usage: Runtime API / managed-plugin endpoints (health, plugin, task, chat)