# 通过 PM2 运行

> 将 Foundry 作为守护进程运行，确保终端关闭后仍可稳定运行，崩溃时自动重启。

Source: https://bifrost5.com/zh/foundry/docs/pm2/

# PM2 集成

Information

Run this for a team without carrying every upgrade alone, since Production-Grade comes with engineering support.

[See editions](/zh/foundry/docs/editions)

将 Foundry 作为守护进程运行，确保终端关闭后仍可稳定运行，崩溃时自动重启。

## 启动

```
pm2 start pnpm --name supervisor -- run cli -- start --redis-host localhost --redis-port 6499 --state-key supervisor:state --queue-name tasks --queue-db 2
```

（如果您使用 npm，请使用 `npm` 代替 `pnpm`。）

## 日志与管理

- **日志**：运行 `pm2 logs supervisor`，或使用 `pm2 logs supervisor --nostream` 查看历史日志

- **状态**：`pm2 list`

- **停止**：`pm2 stop supervisor`

- **重启**：`pm2 restart supervisor`

- **删除**：`pm2 delete supervisor`

## 生态系统文件

您可以在 `ecosystem.config.cjs` 中定义应用并执行 `pm2 start ecosystem.config.cjs`。将 `script` 设为 `pnpm` 或 `npm`，`args` 设为 `run cli -- start ...` 参数，并将 `cwd` 设为项目根目录。
