Skip to content

Commit a7d1d58

Browse files
author
farfarfun
committed
Update Paperclip setup for npx, remove source clone/pnpm deps, add socat
1 parent 49ff7e1 commit a7d1d58

3 files changed

Lines changed: 287 additions & 367 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# nltdeploy
22

3-
用于在本机快速准备开发环境的 Bash 脚本集合:pip 镜像、Python/uv 虚拟环境、Airflow 3、Celery、[Paperclip](https://github.com/paperclipai/paperclip)(AI 编排,源码安装)、[code-server](https://github.com/coder/code-server)(浏览器内 VS Code,官方 standalone 包)、[new-api](https://github.com/QuantumNous/new-api)(LLM 网关,GitHub Release 预编译二进制)、常用 CLI(如 gum)、以及 GitHub 克隆网络修复。各脚本尽量自包含,可单独 `curl … | bash` 使用;内容已同步到 [Gitee 同名仓库](https://gitee.com/farfarfun/nltdeploy),国内网络可改用下方 Gitee 的 raw 地址。
3+
用于在本机快速准备开发环境的 Bash 脚本集合:pip 镜像、Python/uv 虚拟环境、Airflow 3、Celery、[Paperclip](https://github.com/paperclipai/paperclip)(AI 编排,官方 `npx` 安装/运行)、[code-server](https://github.com/coder/code-server)(浏览器内 VS Code,官方 standalone 包)、[new-api](https://github.com/QuantumNous/new-api)(LLM 网关,GitHub Release 预编译二进制)、常用 CLI(如 gum)、以及 GitHub 克隆网络修复。各脚本尽量自包含,可单独 `curl … | bash` 使用;内容已同步到 [Gitee 同名仓库](https://gitee.com/farfarfun/nltdeploy),国内网络可改用下方 Gitee 的 raw 地址。
44

55
## 项目概述
66

@@ -12,7 +12,7 @@
1212
- **utils**:安装 **gum**`~/opt/gum`)与可选 shell 别名(`ll` / `la` / `lla`)。
1313
- **github-net**:诊断并修复「网页能开但 `git clone` 失败」的常见 HTTPS/SSH 问题。
1414
- **download**`nlt-download`):对 GitHub 族 HTTPS 下载 URL 做可选镜像/前缀改写后再 `curl`(环境变量驱动,默认不改写);仓库内 **new-api / code-server / gum 安装路径** 等已统一经 `_nlt_github_download_curl` / `nlt-github-download.sh` 调用(见 `scripts/tools/download/README.md`)。
15-
- **paperclip****GitHub 克隆** [paperclipai/paperclip](https://github.com/paperclipai/paperclip) 源码、`pnpm install`,并以 **`pnpm paperclipai run`** 启停;默认安装根 `~/opt/paperclip`**默认工作区** **`~/opt/paperclip/workspace`**(环境变量 **`PAPERCLIP_WORKSPACE`**可改)。`start` 会在实例就绪后尽量把上游 **`~/.paperclip/instances/<id>/workspaces`** 符号链接到该目录(若该 `workspaces` 已非空则跳过)。数据目录另见上游 `~/.paperclip/…`。无实例配置时 **`start` 会先非交互执行 `onboard --yes`**(依赖 `script(1)`);也可手动 **`nlt-paperclip onboard`**`NONINTERACTIVE=1 nlt-paperclip onboard`)。**`run`** 为同准备下的前台附着(不写 PID;后台已在跑时拒绝)
15+
- **paperclip**直接按上游官方 Quickstart 使用 **`npx paperclipai@latest`**,不再克隆源码、不依赖 `pnpm``install` 只做 **Node.js 20+** / **socat** 预检查与 CLI 缓存预热;`onboard` 对应官方 **`npx paperclipai onboard --yes`**`start` / `run` 对应 **`npx paperclipai run`**。默认内部监听 **`127.0.0.1:18804`**`start` 时会额外拉起 **`socat`**,把 **`0.0.0.0:8804`** 转发到 **`127.0.0.1:18804`**,便于公网访问;`run` 为前台附着,**不启动 socat**。脚本健康检查统一走 **`/api/health`**。默认服务目录 `~/opt/paperclip` 仅存放日志/PID/npm 缓存;默认数据目录遵循上游,为 **`~/.paperclip`**可用 **`PAPERCLIP_HOME`** 覆盖)。若你的全局 `~/.npmrc` 指向私有 registry,可设置 **`PAPERCLIP_NPM_REGISTRY=https://registry.npmjs.org`**
1616
- **code-server**:从 **GitHub Releases** 下载官方 **standalone** 压缩包并解压到 `~/opt/code-server``nohup` 后台运行,默认绑定 `127.0.0.1:8080`;无需本机 Node.js。**`run`** 为前台附着(`PASSWORD``start` 一致;不写 PID;后台已在跑时拒绝)。
1717
- **new-api**:从 **GitHub Releases** 下载 [QuantumNous/new-api](https://github.com/QuantumNous/new-api) 的预编译二进制到 `~/opt/new-api/bin`;数据目录默认 `~/opt/new-api/data`(SQLite 等),默认 **HTTP 端口 8801**;解析版本时会跳过无附件的 nightly,fallback `v0.12.6`**`run`** 为前台 `PORT` 启动(不写 PID;后台已在跑时拒绝)。
1818
- **services**`nlt-services.sh`):**`nlt-services`** 总入口——**`status`** 汇总各常驻服务 PID/端口/HTTP 探测;**`install`** 先选 **安装 / 卸载** 再选模块(或 `install add|remove <模块>`);卸载不含 celery、utils(上游无 uninstall)。
@@ -300,7 +300,7 @@ curl -LsSf https://gitee.com/farfarfun/nltdeploy/raw/master/scripts/tools/github
300300
| `tools/github-net` | `setup.sh` | GitHub 克隆通道诊断与修复 |
301301
| `services/airflow` | `setup.sh` | Airflow 3 安装与日常运维封装(含前台 `run`|
302302
| `services/celery` | `setup.sh` | Celery 安装与进程管理(含前台 `run` / `run-*`|
303-
| `services/paperclip` | `setup.sh` | 克隆 [paperclipai/paperclip](https://github.com/paperclipai/paperclip)、pnpm 安装与启停(含 `run`|
303+
| `services/paperclip` | `setup.sh` | 通过官方 `npx paperclipai@latest` 安装/启停(含 `run`|
304304
| `services/code-server` | `setup.sh` | 下载 [coder/code-server](https://github.com/coder/code-server) standalone 包并启停(含 `run`|
305305
| `services/new-api` | `setup.sh` | 下载 [QuantumNous/new-api](https://github.com/QuantumNous/new-api) Release 二进制并启停(含 `run`|
306306
| `services/`(根) | `nlt-services.sh` | **`nlt-services`**`status``install` 安装/卸载分流与各 `nlt-*` 对接 |
@@ -336,7 +336,7 @@ curl -LsSf https://gitee.com/farfarfun/nltdeploy/raw/master/scripts/tools/github
336336
- **系统**:macOS、Linux(Windows 建议 WSL)。
337337
- **Shell**:Bash 3.2+;**`curl`** 通常必需。
338338
- **`python-env`** 会在需要时安装 **uv**,无需事先安装。
339-
- **Paperclip**:需要 **Node.js 20+**;脚本会尝试用 **corepack** 准备 **pnpm 9+**(见 `scripts/services/paperclip/setup.sh`)。
339+
- **Paperclip**:需要 **Node.js 20+**,并且系统里的 Node 发行版需自带 **npm/npx**;后台公网映射依赖 **`socat`**(见 `scripts/services/paperclip/setup.sh`)。
340340
- **code-server**:需要 **`curl`****`tar`**;安装与运行 **不依赖** 本机 Node(见 `scripts/services/code-server/setup.sh`)。
341341
- **new-api**:需要 **`curl`**;自动选版依赖 **`python3`**(若无则使用脚本内 fallback 版本号)。详见 `scripts/services/new-api/setup.sh`[官方文档](https://docs.newapi.pro/)
342342

scripts/services/nlt-services.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ proc_alive() {
6666
[[ -n "${1:-}" ]] && kill -0 "$1" 2>/dev/null
6767
}
6868

69+
listener_pid_for_port() {
70+
local port="$1"
71+
if command -v lsof >/dev/null 2>&1; then
72+
lsof -tiTCP:"${port}" -sTCP:LISTEN -n -P 2>/dev/null | head -1
73+
return 0
74+
fi
75+
if command -v ss >/dev/null 2>&1; then
76+
ss -ltnp "( sport = :${port} )" 2>/dev/null | awk -F 'pid=' 'NR>1 && NF>1 {split($2,a,","); print a[1]; exit}'
77+
return 0
78+
fi
79+
echo ""
80+
}
81+
6982
status_word() {
7083
if proc_alive "$1"; then
7184
echo "运行中"
@@ -145,8 +158,10 @@ cmd_status() {
145158
pid_cel_f="$(read_pid_file "${CELERY_RUN}/flower.pid")"
146159

147160
PAPERCLIP_SERVICE_HOME="${PAPERCLIP_SERVICE_HOME:-${HOME}/opt/paperclip}"
148-
PAPERCLIP_PORT="${PAPERCLIP_PORT:-8804}"
161+
PAPERCLIP_PORT="${PAPERCLIP_PORT:-18804}"
162+
PAPERCLIP_PUBLIC_PORT="${PAPERCLIP_PUBLIC_PORT:-8804}"
149163
pid_pc="$(read_pid_file "${PAPERCLIP_SERVICE_HOME}/run/paperclip.pid")"
164+
pc_listener_pid="$(listener_pid_for_port "${PAPERCLIP_PORT}")"
150165

151166
CODE_SERVER_SERVICE_HOME="${CODE_SERVER_SERVICE_HOME:-${HOME}/opt/code-server}"
152167
CODE_SERVER_BIND="${CODE_SERVER_BIND:-127.0.0.1:8080}"
@@ -188,10 +203,10 @@ cmd_status() {
188203
"${cel_probe}"
189204
_status_csv_line \
190205
"paperclip" \
191-
"$(status_word "$pid_pc")" \
192-
"${pid_pc:--}" \
193-
"${PAPERCLIP_PORT} /api/health" \
194-
"$(http_probe "http://127.0.0.1:${PAPERCLIP_PORT}/api/health")"
206+
"$(if proc_alive "$pid_pc" || [[ -n "$pc_listener_pid" ]]; then echo "运行中"; else echo "未运行"; fi)" \
207+
"${pid_pc:--}${pc_listener_pid:+ / listen:${pc_listener_pid}}" \
208+
"${PAPERCLIP_PUBLIC_PORT} -> 127.0.0.1:${PAPERCLIP_PORT}" \
209+
"$(http_probe "http://127.0.0.1:${PAPERCLIP_PUBLIC_PORT}/api/health")"
195210
_status_csv_line \
196211
"code-server" \
197212
"$(status_word "$pid_cs")" \

0 commit comments

Comments
 (0)