Docs/ CLI/ 命令参考

命令参考

已发布版本(v1.10.2)的 48 个命令,按任务分组。下面每个代码块都是该命令自己的 <code>--help</code>,精简为语法:这里写的就是二进制实际接受的内容。

配置与全局选项

大多数命令通过 API 与 sh0 服务器通信,按以下顺序查找服务器:

  • 环境变量 SH0_API_URL 和 SH0_API_TOKEN(两者都设置时)-- 适用于 CI,优先于配置文件。
  • 配置文件 ~/.sh0/config.toml,由 sh0 login 写入。sh0 config show 显示服务器和打码后的令牌;两者都没有时,命令会以 “No configuration found. Run `sh0 login` or set SH0_API_URL and SH0_API_TOKEN environment variables.” 退出。
  • 全局选项只有 --log-level、-h, --help 和 -V, --version。--config 指向服务器的配置文件(/etc/sh0/config.toml),只对在服务器上运行的命令(如 sh0 serve)有意义。
  • --json 是各命令自己的选项:只在下面参考中出现的地方存在(列表、cron runs 等),并非所有命令都有。
Terminal
$ sh0 whoami
  Server:  https://panel.example.com
  User:    [email protected]
  Role:    owner

$ SH0_API_URL=https://panel.example.com SH0_API_TOKEN=sh0_... sh0 apps
  NAME      STATUS    BRANCH  PORT  REPLICAS  UPDATED
  --------  --------  ------  ----  --------  -------
  my-api    running   main    3001  1         2m ago
Warning
不存在全局的 --url、--token、--json 或 --verbose 选项。按本页旧版本编写、使用了这些选项的脚本会以 “unexpected argument” 失败:请改用上面的环境变量。

阅读方式:<APP> 为必填,[--选项] 为可选,... 表示可重复。以 # 开头的行是命令自带的说明。<APP> 接受应用名称或 ID;大多数服务命令(sh0 db 等)需要 ID,创建资源时以及对应的 list 会显示。

账户与 CLI 配置

将 CLI 连接到服务器,并查看你在服务器上的身份。

sh0 login

sh0 login --help
# Authenticate with a sh0 server
sh0 login [--url <URL>]

sh0 whoami

sh0 whoami --help
# Show current user and server info
sh0 whoami

sh0 config

sh0 config --help
# Show current configuration
sh0 config show
# Get a specific configuration value
sh0 config get <KEY>
# Set a configuration value
sh0 config set <KEY> <VALUE>

sh0 version

sh0 version --help
# Print version information
sh0 version

工作目录

把本地目录关联到应用,部署前检查,并在每次修改后重新部署。

sh0 init

sh0 init --help
# Initialize a project directory for sh0 deployments
sh0 init [PATH]
sh0 link --help
# Link the current directory to an existing app on the server
sh0 link <APP> [--path <PATH>]

sh0 open

sh0 open --help
# Open the app's primary domain in the default browser
sh0 open [APP]

sh0 watch

sh0 watch --help
# Watch for file changes and auto-push
sh0 watch [PATH] [--name <NAME>] [--project <PROJECT>] [--port <PORT>] [--no-check] [--timeout <TIMEOUT>] [--debounce <DEBOUNCE>]

sh0 check

sh0 check --help
# Run Code Health Check on local directory
sh0 check [PATH] [--json]

部署

sh0 push 将目录打包上传并创建或更新应用:这是主要途径,不需要 Git 仓库。见Push 部署。

sh0 push

sh0 push --help
# Push local directory to deploy (create or update)
sh0 push [PATH] [--name <NAME>] [--project <PROJECT>] [--port <PORT>] [--no-check] [--timeout <TIMEOUT>]

sh0 deploy

sh0 deploy --help
# Trigger a deployment
sh0 deploy <APP> [--message <MESSAGE>] [--wait]

sh0 templates

sh0 templates --help
# List available templates
sh0 templates list
# Show template details
sh0 templates info <NAME>
# Deploy a template
sh0 templates deploy --app-name <APP_NAME> <NAME> [--var]

sh0 compose

sh0 compose --help
# Deploy a Docker Compose file
sh0 compose deploy --app-name <APP_NAME> [PATH] [--var] [--wait]
# Validate a Docker Compose file without deploying
sh0 compose validate [PATH]

sh0 yaml

sh0 yaml --help
# Apply a sh0.yaml configuration
sh0 yaml apply [PATH]
# Validate a sh0.yaml configuration without applying
sh0 yaml validate [PATH]
# Export current configuration as sh0.yaml
sh0 yaml export [--project <PROJECT>]

sh0 export

sh0 export --help
# Export app configuration to a platform-specific format
sh0 export <APP> <FORMAT> [--output <OUTPUT>]

管理应用

生命周期、变量、域名、日志,以及在运行中的应用里打开 shell。变量在下一次部署时生效。

sh0 apps

sh0 apps --help
# List all applications
sh0 apps [--json]

sh0 status

sh0 status --help
# Show server or app status
sh0 status [APP] [--json]

sh0 restart

sh0 restart --help
# Restart an application
sh0 restart <APP>
Warning
对于停止较慢的应用,sh0 restart 可能在 30 秒后以 “operation timed out” 结束,而服务器上的重启仍在继续并会成功(实测:API 41 秒后才响应)。重试前请先用 sh0 status <APP> 确认。

sh0 stop

sh0 stop --help
# Stop an application
sh0 stop <APP> [--yes]

sh0 start

sh0 start --help
# Start a stopped application
sh0 start <APP>

sh0 delete

sh0 delete --help
# Delete an application and its resources
sh0 delete <APP> [--yes]

sh0 scale

sh0 scale --help
# Scale application replicas
sh0 scale <APP> [REPLICAS] [--auto] [--status] [--json]

sh0 env

sh0 env --help
# List environment variables
sh0 env <APP> list [--reveal]
# Set an environment variable
sh0 env <APP> set <PAIR> [--build]
# Delete an environment variable
sh0 env <APP> delete <KEY>
Terminal
$ sh0 env my-api set "DATABASE_URL=postgresql://appuser:<password>@my-pg.internal:5432/appdb"
[ok] Set DATABASE_URL for 'my-api'

$ sh0 env my-api list
  KEY           VALUE    BUILD  CREATED
  ------------  -------  -----  -------
  DATABASE_URL  *******  no     4m ago
  GREETING      *******  no     16m ago

sh0 domains

sh0 domains --help
# List domains for the app
sh0 domains <APP> list
# Add a domain to the app
sh0 domains <APP> add <DOMAIN> [--primary]
# Remove a domain from the app
sh0 domains <APP> remove <DOMAIN> [--yes]

sh0 logs

sh0 logs --help
# Stream application logs
sh0 logs <APP> [--follow] [--tail <TAIL>]

sh0 ssh

sh0 ssh --help
# Execute command in app container
sh0 ssh <APP> [COMMAND]...
Note
sh0 ssh 需要交互式终端(在没有终端的脚本中会以 “cannot attach stdin to a TTY-enabled container” 退出)。如果要执行的命令带有自己的选项,请在前面加 --:sh0 ssh my-api -- node --version。

定时任务、钩子与预览

创建定时任务前,请先阅读命令在哪里运行:它看不到应用的变量。

sh0 cron

sh0 cron --help
# List cron jobs
sh0 cron list [--app <APP>] [--json]
# Create a new cron job
sh0 cron create --app <APP> --name <NAME> --schedule <SCHEDULE> --command <COMMAND> [--image <IMAGE>] [--timeout <TIMEOUT>]
# Manually trigger a cron job
sh0 cron trigger <ID>
# Show execution history for a cron job
sh0 cron runs <ID> [--json]
# Delete a cron job
sh0 cron delete <ID> [--yes]

sh0 hooks

sh0 hooks --help
# List deploy hooks for an app
sh0 hooks <APP> list [--json]
# Create a deploy hook
sh0 hooks <APP> create --hook-type <type> --command <COMMAND> [--timeout <TIMEOUT>]
# Delete a deploy hook
sh0 hooks <APP> delete <ID>

sh0 preview

sh0 preview --help
# List preview environments for an app
sh0 preview <APP> list [--json]
# Destroy a preview environment
sh0 preview <APP> delete <ID>
# Enable preview environments for an app
sh0 preview <APP> enable [--ttl <TTL>]
# Disable preview environments for an app
sh0 preview <APP> disable

服务

数据库、认证、实时、函数、邮件、存储和可用性监控服务器。每个命令都有短别名(db、auth、realtime、fn、storage),完整名称同样可用。

sh0 db

sh0 db --help
# List all database servers
sh0 db list [--json]
# Show database server details
sh0 db info <ID> [--json]
# Create a new database server
sh0 db create --name <NAME> --engine <ENGINE> [--project <PROJECT>]
# Update a database server
sh0 db update <ID> [--name <NAME>] [--project <PROJECT>]
# Delete a database server
sh0 db delete <ID> [--yes]
# Start a database server
sh0 db start <ID>
# Stop a database server
sh0 db stop <ID>
# Recreate a database server container
sh0 db recreate <ID>
# Show connection info for a database server
sh0 db connection-info <ID> [--json]
# Create a database on a server
sh0 db create-database --name <NAME> <ID>
# Create a user on a database server
sh0 db create-user --username <USERNAME> --password <PASSWORD> <ID>
# Grant a user access to a database
sh0 db grant --user <USER> --database <DATABASE> <ID> [--privileges <PRIVILEGES>]
# Enable PostgREST sidecar
sh0 db enable-postgrest <ID> [--anon-role <ANON_ROLE>] [--schemas <SCHEMAS>]
# Disable PostgREST sidecar
sh0 db disable-postgrest <ID>

sh0 auth

sh0 auth --help
# List all auth servers
sh0 auth-servers list [--json]
# Show auth server details
sh0 auth-servers info <ID> [--json]
# Create a new auth server
sh0 auth-servers create --name <NAME> --database-server <DATABASE_SERVER> [--project <PROJECT>]
# Delete an auth server
sh0 auth-servers delete <ID> [--yes]
# Start an auth server
sh0 auth-servers start <ID>
# Stop an auth server
sh0 auth-servers stop <ID>

sh0 realtime

sh0 realtime --help
# List all realtime servers
sh0 realtime-servers list [--json]
# Show realtime server details
sh0 realtime-servers info <ID> [--json]
# Create a new realtime server
sh0 realtime-servers create --name <NAME> [--project <PROJECT>]
# Delete a realtime server
sh0 realtime-servers delete <ID> [--yes]
# Start a realtime server
sh0 realtime-servers start <ID>
# Stop a realtime server
sh0 realtime-servers stop <ID>

sh0 fn

sh0 fn --help
# List all function servers
sh0 function-servers list [--json]
# Show function server details
sh0 function-servers info <ID> [--json]
# Create a new function server
sh0 function-servers create --name <NAME> [--project <PROJECT>]
# Delete a function server
sh0 function-servers delete <ID> [--yes]
# Start a function server
sh0 function-servers start <ID>
# Stop a function server
sh0 function-servers stop <ID>

sh0 mail

sh0 mail --help
# List all mail domains
sh0 mail list [--json]
# Show mail domain details
sh0 mail info <ID> [--json]
# Create a new mail domain
sh0 mail create --domain <DOMAIN> [--project <PROJECT>]
# Delete a mail domain
sh0 mail delete <ID> [--yes]
# Start a mail domain
sh0 mail start <ID>
# Stop a mail domain
sh0 mail stop <ID>
# Check DNS records for a mail domain
sh0 mail dns-check <ID> [--json]
# Create a mailbox on a mail domain
sh0 mail create-mailbox --email <EMAIL> --password <PASSWORD> <ID> [--display-name <DISPLAY_NAME>]
# Create an email alias on a mail domain
sh0 mail create-alias --source <SOURCE> --destination <DESTINATION> <ID>

sh0 storage

sh0 storage --help
# List all file storage instances
sh0 file-storage list [--json]
# Show file storage instance details
sh0 file-storage info <ID> [--json]
# Create a new file storage instance
sh0 file-storage create --name <NAME> [--project <PROJECT>]
# Delete a file storage instance
sh0 file-storage delete <ID> [--yes]
# Start a file storage instance
sh0 file-storage start <ID>
# Stop a file storage instance
sh0 file-storage stop <ID>
# Create a bucket in a storage instance
sh0 file-storage create-bucket --name <NAME> <ID>
# Create an access key for a storage instance
sh0 file-storage create-key <ID> [--json]
# Show storage usage statistics
sh0 file-storage usage <ID> [--json]

sh0 uptime

sh0 uptime --help
# List uptime checks
sh0 uptime list [--app <APP>] [--json]
# Show uptime check details
sh0 uptime info <ID> [--json]
# Create a new uptime check
sh0 uptime create --app <APP> --url <URL> [--interval <INTERVAL>] [--method <METHOD>] [--timeout <TIMEOUT>] [--expected-status <EXPECTED_STATUS>] [--failure-threshold <FAILURE_THRESHOLD>]
# Delete an uptime check
sh0 uptime delete <ID> [--yes]
# List uptime incidents for a check
sh0 uptime incidents <CHECK_ID> [--json]

服务器与面板

远程节点以及面板自身的域名。

sh0 nodes

sh0 nodes --help
# List all server nodes
sh0 nodes list [--json]
# Show node details
sh0 nodes info <ID> [--json]
# Register a new server node
sh0 nodes create --name <NAME> --host <HOST> --ssh-user <SSH_USER> [--ssh-key <SSH_KEY>] [--password <PASSWORD>] [--port <PORT>]
# Remove a node from the cluster
sh0 nodes delete <ID> [--yes]
# Test SSH and Docker connectivity to a node
sh0 nodes test <ID> [--json]

sh0 panel-domain

sh0 panel-domain --help
# Domaine du panneau d'administration : le lire, le poser, le retirer.
sh0 panel-domain [COMMAND] [--data-dir <DATA_DIR>] [--db <DB>] [--caddy-data <CADDY_DATA>] [--jwt-secret-path <JWT_SECRET_PATH>] [--port <PORT>]
# Poser le domaine et attendre l'émission du certificat
sh0 panel-domain set <DOMAIN> [--no-wait]
# Retirer la route et le réglage
sh0 panel-domain clear

服务器管理

这些命令以 root 身份在服务器上运行,直接作用于本机安装,而不经过 API。当前版本中有几个命令的帮助以法语输出。

sh0 serve

sh0 serve --help
# Start the sh0 server
sh0 serve [OPTIONS]    # sh0 serve --help lists every option

sh0 setup

sh0 setup --help
# Run initial setup wizard
sh0 setup

sh0 install-dns-caddy

sh0 install-dns-caddy --help
# Install a Caddy that can answer the DNS-01 ACME challenge (ISSUE-158).
sh0 install-dns-caddy

sh0 users

sh0 users --help
# List all users (reads the local database when run on the server box, the API otherwise)
sh0 users list [--json] [--data-dir <DATA_DIR>] [--db <DB>]
# Invite a new user
sh0 users invite <EMAIL> [--password <PASSWORD>] [--role <ROLE>] [--display-name <DISPLAY_NAME>]
# Update a user
sh0 users update <ID> [--role <ROLE>] [--display-name <DISPLAY_NAME>]
# Remove a user
sh0 users remove <ID> [--yes]
# Reset a user's password locally (recovery path; run on the server box, no login required)
sh0 users reset-password <EMAIL> [--password <PASSWORD>] [--disable-2fa] [--data-dir <DATA_DIR>] [--db <DB>]

sh0 projects

sh0 projects --help
# List all projects
sh0 projects list [--json]
# Create a new project
sh0 projects create <NAME> [--description <DESCRIPTION>] [--color <COLOR>]
# Delete an empty project (refused while it still holds apps, databases or services)
sh0 projects delete <PROJECT> [--yes]
# List project members
sh0 projects members <PROJECT> [--json]
# Add a member to a project
sh0 projects add-member <PROJECT> <USER> [--role <ROLE>]
# Remove a member from a project
sh0 projects remove-member <PROJECT> <USER>

sh0 update

sh0 update --help
# Update sh0, or roll back to the previous version
sh0 update [--rollback] [--channel <CHANNEL>] [--force] [--yes]

sh0 doctor

sh0 doctor --help
# Préflight d'hôte : Docker, ports, disque, certificats, horloge.
sh0 doctor [COMMAND] [--json] [--db <DB>] [--data-dir <DATA_DIR>] [--caddy-data <CADDY_DATA>] [--port <PORT>]
# Count restore rows that migration 055 could not reach (ISSUE-086).
sh0 doctor backup-rows [--json] [--db <DB>]
# List host mounts that the bind whitelist would refuse today (ISSUE-176).
sh0 doctor bind-mounts [--json] [--db <DB>] [--all]

sh0 instance

sh0 instance --help
# Écrire un instantané de cette instance dans un fichier
sh0 instance backup [--data-dir <DATA_DIR>] [--out <OUT>] [--encrypt]
# Reposer une instance sauvegardée sur cette machine
sh0 instance restore --file <FILE> [--data-dir <DATA_DIR>] [--dry-run] [--force]
# Remplacer la clé maîtresse et rechiffrer tous les secrets de la base
sh0 instance rotate-key [--data-dir <DATA_DIR>] [--dry-run] [--yes] [--backup-out <BACKUP_OUT>]

sh0 uninstall

sh0 uninstall --help
# Uninstall sh0 (remove binary and optionally data)
sh0 uninstall [--purge]

sh0 destroy

sh0 destroy --help
# Destroy everything: stop and remove all containers, images, volumes, networks, data, and binary
sh0 destroy