yarn.social v0.16.0 常用 CLI 命令详解
yarnd v0.16.0 命令行全解:版本/帮助/启动形态/--skip-setup 实测、flag 与环境变量优先级、compose 服务管理、CSRF 登录发帖与 PoW 注册脚本化、feed/metrics/备份/锁排查等数据维护命令、yarnc 客户端官方溯源,附 --help 60+ 参数完整回显。
yarn.social v0.16.0 常用 CLI 命令详解
本文汇总 yarn.social Pod 服务器 yarnd v0.16.0 日常运维与操作中最常用的命令行:服务端二进制的版本/帮助/启动形态、环境变量注入、经 HTTP 表单与 API 的自动化操作(登录、发帖、PoW 注册)、数据目录维护与监控取数。除第 8 节 yarnc 客户端(官方 README 溯源引用,查询日期 2026-11-02)外,其余命令与输出均为真实 Pod 实测回显。前置部署见 《yarn.social v0.16.0 Docker Compose 部署指南》,参数含义见 《yarn.social v0.16.0 配置参数详解》。
1. 命令体系总览
| 命令 | 角色 | 获取方式 |
|---|---|---|
yarnd | Pod 服务器(本文主体) | 官方镜像 / Releases 预编译二进制 / make server |
yarnc | Pod 命令行客户端(基于 API) | Releases / Homebrew / make cli |
curl | 表单与 API 自动化 | 系统自带 |
yarnd 是单二进制带全套 flag 的"服务器即 CLI":--help 就是配置手册(60+ 参数),无子命令树;日常服务管理在 Compose 编排下走 docker compose 一族。
2. 版本与帮助
# docker compose exec yarnd yarnd --version
2026-11-02 11:06:02 INFO memory is not limited, skipping package=github.com/KimMachineGun/automemlimit/memlimit
yarnd 0.16.0@1e81cc4e 2026-07-13T14:54:06+10:00 go1.26.5
版本串三段式:0.16.0(tag)+ @1e81cc4e(commit)+ 构建时间 + go1.26.5(编译器)。升级后先跑这条确认二进制真的换了。
--help 完整输出收录在文末附录 A(逐行照抄),速查也可 docker compose logs 看启动回显的生效配置。
3. 启动命令形态
最小可用(开发/试用):
yarnd -d /data -s bitcask:///data/yarn.db
生产常用(对应 B2 编排的 command 段):
yarnd -d /data -s bitcask:///data/yarn.db \
-n pod.example.com -u https://pod.example.com \
-I -O --cookie-secret <64位> --magiclink-secret <64位> --api-signing-key <64位>
全自动 IaC 冷启动(跳过 Setup 向导)——--skip-setup 实测,全新空数据目录直接可服务:
# docker run -d --name yarn-skiptest -p 8130:8000 -v .../skiptest:/data prologic/yarnd:latest yarnd -d /data -s bitcask:///data/yarn.db --skip-setup -b 0.0.0.0:8000
# curl -sS -o /dev/null -w 'GET / with --skip-setup: %{http_code}\n' http://127.0.0.1:8130/
GET / with --skip-setup: 200
(对比:不带 --skip-setup 的全新实例所有请求 302 到 /setup。)
排障:加 -D/--debug 提高日志级别;--log-file 把日志落盘替代 stderr。
4. 环境变量注入(与 flag 等价)
规则:长选项全大写、- 换 _。实测对照:
# docker run --rm -e NAME=env-pod-demo ... prologic/yarnd:latest yarnd -d /data -s bitcask:///data/yarn.db --skip-setup -b 0.0.0.0:8000
time="2026-11-02T10:50:14Z" level=info msg="Instance Name: env-pod-demo"
同名参数 flag 与 env 并存时 flag 胜出(实测 -n flag-name + NAME=env-name → Instance Name: flag-name)。compose 场景推荐:结构性参数进 command:,密钥进 environment:/.env。
5. 服务管理(Compose 编排下)
# docker compose up -d # 拉起/更新
# docker compose ps # 状态(healthy 由内置健康检查给出)
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
yarn-v0.16.0-web prologic/yarnd:latest "/init yarnd -d /dat…" yarnd 7 seconds ago Up 6 seconds (health: starting) 0.0.0.0:8129->8000/tcp, [::]:8129->8000/tcp
# docker compose logs -f yarnd # 跟踪日志
# docker compose restart # 重启(配置变更经 command/env 修改后需 down/up)
# docker compose down # 停止并移除(数据目录保留)
docker compose exec yarnd <yarnd 参数> 可直接对编排内二进制取版本/帮助,不必进 shell。
6. HTTP 表单自动化(登录/发帖/注册)
yarnd 0.16.0 的 Web 表单走 CSRF + htmx,脚本化两个要点:表单里的 csrf_token 值含 HTML 实体 +,必须先反转义;POST 成功一律回 302 -> /。实测脚本核心与回显:
LOGIN: HTTP/1.1 302 Found -> /
POST: HTTP/1.1 302 Found -> /
发帖即 POST /post,字段 text(示例账号 admin / q1w2e3r4):
curl -sS -b cj.txt -c cj.txt -X POST http://127.0.0.1:8129/post \
--data-urlencode "csrf_token=$TOKEN" --data-urlencode "text=Hello yarn.social from compose 🧶"
注册含 PoW:/register 表单带 pow_challenge/pow_timestamp/pow_signature/pow_difficulty/pow_nonce 五字段,算法为 sha256(pow_challenge + nonce) 摘要前 difficulty 比特全 0。求解并注册 root 用户实测:
nonce solved: 194318 difficulty: 16
REGISTER: HTTP/1.1 302 Found -> /login
Python 求解片段(难度 16 时毫秒级):
import hashlib
nonce = 0
while int.from_bytes(hashlib.sha256((chal + str(nonce)).encode()).digest(), 'big') >> (256 - diff):
nonce += 1
读取任意用户 feed(twtxt 协议入口,无需登录):
# curl -sS http://127.0.0.1:8129/user/admin/twtxt.txt | tail -1
2026-11-02T10:49:38Z Hello yarn.social from compose 🧶
# curl -sS http://127.0.0.1:8129/user/root/twtxt.txt | tail -1
2026-11-02T10:55:52Z root 用户的第一条 twt
注意路径是 /user/<nick>/twtxt.txt,/user/<nick>.txt 形态会返回 Feed Not Found。
7. 数据维护与监控命令
看 Pod 家底(数据目录全在这,备份=打包):
# ls -la data/
-rw-r--r-- 1 yahui yahui 4096 cache.db
-rw-r--r-- 1 yahui yahui 32768 cache.db-shm
-rw-r--r-- 1 yahui yahui 346112 cache.db-wal
-rw------- 1 yahui yahui 175 config.yml
drwxr-xr-x 2 yahui yahui 4096 feeds
-rw-r--r-- 1 yahui yahui 3 followers.json
-rw-r--r-- 1 yahui yahui 5 peers.json
-rw-r--r-- 1 yahui yahui 18 websub.json
drwx------ 2 yahui yahui 4096 yarn.db
单用户 feed 直接 cat(纯文本,一行一条):
# cat data/feeds/admin
2026-11-02T10:41:20Z Hello from yarn.social test pod 🧶
备份/还原:
# tar czf yarn-backup-$(date +%F).tar.gz data
# ls -la yarn-backup-2026-11-02.tar.gz
-rw-r--r-- 1 root root 10118 Nov 2 18:56 yarn-backup-2026-11-02.tar.gz
# tar tzf yarn-backup-2026-11-02.tar.gz | head -4
data/
data/cache.db
data/cache.db-shm
data/websub.json
还原:tar xzf 回原位 → chown -R 1000:1000 data → 起服务。
查 Bitcask 锁持有者(database locked 排障):
# fuser -v data/yarn.db/*
USER PID ACCESS COMMAND
/data/yarn.db/000000000.data:
yahui 1197764 f.... yarnd
/data/yarn.db/000000001.data:
yahui 1197764 F.... yarnd
监控取数:/metrics 为 Prometheus 文本格式,实测节选:
# curl -sS http://127.0.0.1:8129/metrics | grep -E '^yarnd_cache' | head -4
yarnd_cache_corrected_twts 0
yarnd_cache_feed_fetch_duration_seconds{quantile="0.5"} 0.001065749
yarnd_cache_feed_fetch_duration_seconds{quantile="0.9"} 0.001065749
yarnd_cache_feed_fetch_duration_seconds{quantile="0.95"} 0.001065749
资源基线(选型佐证):
# docker stats --no-stream yarn-v0.16.0-web
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
ea9a69bb816f yarn-v0.16.0-web 0.00% 31.67MiB / 15.57GiB 0.20% 3kB / 11.2kB 0B / 8.19kB 9
8. yarnc 命令行客户端(官方 README 溯源)
yarnc 是官方 Go 终端客户端,走 Pod 的 /api/v1 API(token 认证,-t 传入或 YARNC_TOKEN 环境变量)。以下命令与回显引自官方 README(来源:pkg.go.dev git.mills.io/yarnsocial/yarn 页 Command-line Client 章节,查询日期 2026-11-02,非本地实测):
$ ./yarnc login
INFO[0000] Using config file: /Users/prologic/.twt.yaml
Username:
$ ./yarnc timeline
INFO[0000] Using config file: /Users/prologic/.twt.yaml
> prologic (50 minutes ago)
Hey @rosaelefanten 👋 Nice to see you have a Twtxt feed! ...
$ ./yarnc post
INFO[0000] Using config file: /Users/prologic/.twt.yaml
Testing `yarn` the command-line client
INFO[0015] posting twt...
INFO[0016] post successful
yarnc help(官方 README 原文)子命令:login / timeline / post / stats(对任意 twtxt URL/文件做统计分析)/ completion;全局 flag -c 配置文件(默认 ~/.yarnc.yml)、-t token、-U API 地址(默认 http://localhost:8000/api/v1/)。
实测说明:yarnc 二进制仅发布于
git.mills.io/yarnsocial/yarn/releases,本次部署环境到该自建 Git 服务的 HTTPS 通道持续被中间设备干扰(curl报Empty reply from server/HTTP2 INTERNAL_ERROR,多次重试未果;GitHub 无主仓库镜像,Go 模块代理亦未缓存该模块),故 yarnc 未能本地实测,本节内容以官方 README 为准。服务器本体yarnd的功能不受影响——其 Web 表单等价操作已全部实测(见第 6 节)。
9. 常用命令速查表
| 任务 | 命令 |
|---|---|
| 查版本 | docker compose exec yarnd yarnd --version |
| 查全量参数 | docker compose exec yarnd yarnd --help |
| 拉起/停止/重启 | docker compose up -d / down / restart |
| 跟踪日志 | docker compose logs -f yarnd |
| 备份数据 | tar czf yarn-$(date +%F).tar.gz data |
| 查某用户 feed | curl -sS https://pod/user/<nick>/twtxt.txt |
| 查指标 | curl -sS https://pod/metrics |
| 查数据锁 | fuser -v data/yarn.db/* |
| 密钥生成 | cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head -n 1 |
附录 A:yarnd --help 完整实测输出
Usage of /usr/local/bin/yarnd:
-E, --admin-email string default admin user email (default "support@yarn.social")
-N, --admin-name string default admin user name (default "Administrator")
-A, --admin-user string default admin user to use (default "admin")
--api-session-time duration timeout for api tokens to expire (default 240h0m0s)
--api-signing-key string secret to use for signing api tokens (default "INVALID CONFIG VALUE - PLEASE CHANGE THIS VALUE")
-a, --auth string auth to use (proxy or session) (default "session")
--auth-header string auth header to use for proxy auth (default "X-User")
-u, --base-url string base url to use (default "http://0.0.0.0:8000")
-b, --bind string [int]:<port> to bind to (default "0.0.0.0:8000")
--blocked-feeds strings blocked feeds (regexes) to prohibit fetching (default [port70\.dk,enotty\.dk,gopher\.floodgap\.com,lublin\.se])
--bridge-url string URL to proxy webfinger requests through when configured
--config string path to the instance config file (defaults to data/config.yml)
--cookie-secret string cookie secret to use secure sessions (default "INVALID CONFIG VALUE - PLEASE CHANGE THIS VALUE")
-d, --data string data directory (default "./data")
-D, --debug enable debug logging
-m, --description string set the pod's description (default "🧶 Yarn.social is a Self-Hosted, Twitter™-like Decentralised Microblogging social media platform. No ads, no tracking, your content, your data!")
--disable-ffmpeg whether or not to disable ffmpeg support for video and audio
--disable-gzip whether or not to disable Gzip compression
--disable-logger whether or not to disable the Logger (access logs)
--disable-media whether or not to disable media support entirely
--disable-support whether or not to disable support (support and abuse)
--enable-feature feature enable the named feature
--fetch-interval string cache fetch interval (how often to update feeds) in cron syntax (https://pkg.go.dev/github.com/robfig/cron) (default "@every 5m")
--front-page string sets the behaviour of the front page (anonymous discover view) (default "local")
-I, --invite-only whether or not to have invite-only registrations (users may request an invite)
-l, --lang string set the default language (default "auto")
--log-file string log to file instead of stderr
--magiclink-secret string magiclink secret to use for password reset tokens (default "INVALID CONFIG VALUE - PLEASE CHANGE THIS VALUE")
--max-age-days int maximum age of cached twts in days (default 10)
--max-cache-fetchers int set maximum numnber of fetchers to use for feed cache updates (default 6)
-S, --max-feed-size int maximum feed size before a feed is rorated inbytes (default 524288)
-F, --max-fetch-limit int maximum feed fetch limit in bytes (default 1048576)
-L, --max-twt-length int maximum length of posts (default 1024)
-U, --max-upload-size int maximum upload size of media (default 16777216)
-n, --name string set the pod's name (default "yarn.local")
-O, --open-profiles whether or not to have open user profiles
-R, --open-registrations whether or not to have open user registrations
--permitted-images strings permitted image domain (regexes) for display of inline images (default [imgur\.com,giphy\.com,imgs\.xkcd\.com,reactiongifs\.com,githubusercontent\.com])
--queue-buffer-size int buffer size for the fetcher work queue
--session-cache-ttl duration time-to-live for cached sessions (default 1h0m0s)
--session-expiry duration timeout for sessions to expire (default 240h0m0s)
--skip-setup treat this pod as already configured without running the setup wizard
--smtp-from string SMTP From to use for email sending (default "INVALID CONFIG VALUE - PLEASE CHANGE THIS VALUE")
--smtp-host string SMTP Host to use for email sending (default "INVALID CONFIG VALUE - PLEASE CHANGE THIS VALUE")
--smtp-pass string SMTP Pass to use for email sending (default "INVALID CONFIG VALUE - PLEASE CHANGE THIS VALUE")
--smtp-port int SMTP Port to use for email sending
--smtp-user string SMTP User to use for email sending (default "INVALID CONFIG VALUE - PLEASE CHANGE THIS VALUE")
-s, --store string store to use (default "bitcask://yarn.db")
-t, --theme string set the theme to use for templates and static assets (if not specified, uses builtin theme)
--tls enable TLS (HTTPS)
--tls-cert string path to TLS certificate (if blank uses Let's Encrypt)
--tls-key string path to TLS private key (if blank uses Let's Encrypt)
--transcoder-timeout duration timeout for the video transcoder (default 10m0s)
-T, --twts-per-page int maximum twts per page to display (default 50)
-v, --version display version information