Livebook 0.19.10 常用 CLI 命令详解

梳理 Livebook 0.19.10 的两层 CLI 体系:hex Escript 命令(livebook server 全参数、deploy、--version)与官方发行版工具 bin/livebook(eval/rpc/version 等 11 个子命令),覆盖 escript 安装全流程、双实例端口冲突与重复启动检测排障、发行版远程命令禁用机制解析与 SIGTERM 优雅关停,全部命令在 0.19.10 实例逐条实测并照抄回显。

LivebookLivebook2026/10/31

Livebook 0.19.10 常用 CLI 命令详解

目标:完整梳理 Livebook 0.19.10 的命令行体系——官方 CLI 分两层:hex Escript 命令 livebook(server/deploy 两个子命令,参数经 CLI 选项传入)与官方发行版工具 bin/livebook(start/eval/rpc/daemon 等 11 个子命令,配置经环境变量传入)。本文给出两条安装路径的完整实测过程、全部子命令的参数表与真实回显、以及双实例端口冲突、远程命令报错等排障实录。配置体系(LIVEBOOK_* 环境变量语义)见 《Livebook 0.19.10 配置参数详解》,部署形态见 《Livebook 0.19.10 Docker Compose 部署指南》,软件背景见 《Livebook 0.19.10 介绍与选型指南》。全部命令在 0.19.10 实测环境逐条执行并照抄回显,测试日期 2026-10-31。

一、环境信息

项目值
验证对象Livebook 0.19.10(hex.pm 最新稳定版,CLI 语义溯源官方 README v0.19.10)
运行环境Linux x86_64 服务器,内核默认参数
Elixir 工具链Elixir 1.19.3(compiled with Erlang/OTP 28)、Erlang/OTP 28(erts-16.1.1)——livebook --version 实测回显
主实例官方 0.19.10 发行版部署于 /app(入口 bin/server,数据目录 /data),Web 端口 8137,密码认证(LIVEBOOK_PASSWORD)
临时验证实例hex Escript 启动的临时 server,监听 127.0.0.1:4040(测试后已清理)
Escript 安装目录$MIX_HOME/escripts(本环境实测为 /home/livebook/.mix/escripts,单文件 12535245 字节)
CLI 语义来源官方 README Installation/Escript 章节 + 0.19.10 CLI 内置帮助(--help 原文照抄),查询日期 2026-10-31
测试日期2026-10-31

二、工具概览

Livebook 0.19.10 官方提供的命令行入口有两层,能力与配置方式不同,先对照再逐个详解:

维度Escript 命令 livebook发行版工具 bin/livebook
安装来源mix escript.install hex livebook(需 Elixir ≥ 1.18)官方发行版自带(/app/bin/livebook,随发行版目录走)
定位官方 README 原文:The livebook package is meant to be used as a CLI toolElixir release 标准包装脚本(启动/守护/远程运维)
子命令server(启动 Web 服务)、deploy(部署笔记本到 Livebook Teams)start、start_iex、daemon、daemon_iex、eval、rpc、remote、restart、stop、pid、version
传参方式CLI 选项(--ip/--port/--name/--cookie)+ LIVEBOOK_* 环境变量仅 LIVEBOOK_* 环境变量(无 CLI 端口选项)
前台/后台仅前台运行(--daemon 选项不存在,实测报错)支持前台 start 与后台 daemon
适用场景服务器上快速起一个单机实例、CI 中拉起服务发行版形态的日常运维(表达式执行、远程命令、守护进程)

💡 技术拓展:livebook server(Escript)与 bin/livebook start(发行版)最终启动的是同一个 OTP 应用,差异在交付形态。同类「单文件可执行」方案里,Escript 是 Elixir 官方分发形式之一;发行版(release)则是自包含目录,不依赖系统 Elixir。第三种交付路径见 《Livebook 0.19.10 Docker Compose 部署指南》。

三、前置条件

3.1 安装 Escript 命令(hex 路径)

官方要求 Elixir v1.18 或更高,且 Erlang 侧需 inets、os_mon、runtime_tools、ssl、xmerl 五个应用(多数发行版自带,Ubuntu 拆分包时按 README 补装 erlang-inets erlang-os-mon erlang-runtime-tools erlang-ssl erlang-xmerl erlang-dev erlang-parsetools)。官方安装命令:

mix do local.rebar --force, local.hex --force   # 首次使用 Mix 时初始化 rebar/hex(官方原文)
mix escript.install hex livebook                # 安装最新稳定版(本环境实测锁定 0.19.10)

实测回显(首次运行,先现场编译再请求确认,节选):

==> phoenix_live_dashboard
Compiling 36 files (.ex)
Generated phoenix_live_dashboard app
==> livebook
Compiling 313 files (.ex)
Generated livebook app
Generated escript livebook with MIX_ENV=prod
Are you sure you want to install "livebook"? [Yn]

回答 Y 后写入 $MIX_HOME/escripts;脚本化安装可加 --force 跳过确认,完成后安装器会给出 PATH 提示(实测原文):

warning: you must append "/home/livebook/.mix/escripts" to your PATH if you want to invoke escripts by name

按提示把目录加入 PATH 并验证安装产物:

export PATH=$PATH:/home/livebook/.mix/escripts    # 安装器提示的 escripts 目录
ls -la /home/livebook/.mix/escripts              # 验证产物

实测回显:

total 12252
drwxr-xr-x 2 root root     4096 Oct 31 04:03 .
drwxrwxrwx 3 root root     4096 Oct 31 04:03 ..
-r-xr-xr-x 1 root root 12535245 Oct 31 04:03 livebook

如需跟踪主分支特性,README 另提供 GitHub 直装:mix escript.install github livebook-dev/livebook。

⚠️ 注意:mix escript.install hex livebook 不带版本号会安装 hex 上的最新发布版;生产环境建议锁版本安装(如本环境实测的 mix escript.install hex livebook 0.19.10),与部署实例版本对齐。

3.2 发行版工具路径(binary 路径)

发行版形态下 bin/livebook 位于发行版根目录的 bin/ 内(本环境为 /app/bin/livebook),无需额外安装。发行版的获取与托管方式见 《Livebook 0.19.10 Docker Compose 部署指南》;从源码构建发行版则按官方 README 执行 git clone https://github.com/livebook-dev/livebook.git && cd livebook && mix setup.prod && MIX_ENV=prod mix phx.server。本文后续小节统一以 $RELEASE_ROOT/bin/livebook 指代该工具(本环境 $RELEASE_ROOT=/app)。

四、各工具详解

4.1 主命令帮助与版本:livebook --help / --version / 未知命令

Escript 主命令直接运行可打印用法:

livebook --help

实测回显(全文照抄):

Livebook is an interactive notebook system for Elixir

Usage: livebook [command] [options]

Available commands:

  livebook server    Starts the Livebook web application
  livebook deploy    Deploys a notebook to Livebook Teams

The --help and --version options can be given instead of a command for usage and versioning information.

版本号一次回显三层(Erlang、Elixir、Livebook):

livebook --version

实测回显:

Erlang/OTP 28 [erts-16.1.1] [source] [64-bit] [smp:128:6] [ds:128:6:10] [async-threads:1] [jit:ns]

Elixir 1.19.3 (compiled with Erlang/OTP 28)

Livebook 0.19.10

传入未知命令时的报错形态(排障时用于辨认是否装对命令):

livebook badcmd; echo "exit=$?"

实测回显:

Unknown command badcmd
Usage: livebook [command] [options]

Available commands:

  livebook server    Starts the Livebook web application
  livebook deploy    Deploys a notebook to Livebook Teams

The --help and --version options can be given instead of a command for usage and versioning information.
exit=1

4.2 启动 Web 服务:livebook server

livebook server 是 Escript 层的核心命令。--help 输出分四段:用法与 open-command 规则、CLI 选项、启动时生效的环境变量清单、示例。先看用法段(--help 原文照抄):

Usage: livebook server [options] [open-command]

An optional open-command can be given as argument. It will open
up a browser window according these rules:

  * If the open-command is "@home", the browser window will point
    to the home page

  * If the open-command is "@new", the browser window will point
    to a new notebook

  * If the open-command is a URL, the notebook at the given URL
    will be imported

  * If the open-command is a directory, the browser window will point
    to the open page with the directory selected

  * If the open-command is a notebook file, the browser window will point
    to the opened notebook

The open-command runs after the server is started. If a server is
already running, the browser window will point to the server
currently running.

## Available options

  --cookie             Sets a cookie for the app distributed node
  --ip                 The ip address to start the web application on, defaults to 127.0.0.1
                       Must be a valid IPv4 or IPv6 address
  --name               Sets a name for the app distributed node
  -p, --port           The port to start the web application on, defaults to 8080

The --help option can be given to print this notice.

CLI 选项只有 4 个,逐一说明:

选项默认值说明
--ip127.0.0.1Web 服务监听地址,仅接受 IPv4/IPv6 地址。默认只绑本机回环——官方 README「Security considerations」明确:Livebook only binds to the 127.0.0.1,对外服务必须显式改地址并同时配置认证
-p, --port8080主端口。设为 0 时随机选端口(该行为由环境变量 LIVEBOOK_PORT=0 定义,CLI 选项与之等价)
--name无本节点分布名(长名格式 name@host),用于集群/远程连接场景
--cookie随机分布式 cookie,与 --name 配合使用

环境变量段是 CLI 内置帮助自带的官方速查(原文照抄如下,语义详解与逐项实测见 C1 指南,两处内容一致):

## Environment variables

The following environment variables can be used to configure Livebook on boot:

  * `LIVEBOOK_ALLOW_URI_SCHEMES` - sets additional allowed hyperlink schemes to the
    Markdown content. Livebook sanitizes links in Markdown, allowing only a few
    standard schemes by default (such as http and https). Set it to a comma-separated
    list of schemes.

  * `LIVEBOOK_APP_SERVICE_NAME` - sets the application name used by the cloud
    provider to aid debugging.

  * `LIVEBOOK_APP_SERVICE_URL` - sets the application url to manage this
    Livebook instance within the cloud provider platform.

  * `LIVEBOOK_APPS_BANNER` - sets the value to render at the top apps banner.

  * `LIVEBOOK_APPS_PATH` - the directory with app notebooks. When set, the apps
    are deployed on Livebook startup with the persisted settings. Password-protected
    notebooks will receive a random password, unless `LIVEBOOK_APPS_PATH_PASSWORD`
    is set. When deploying using Livebook's Docker image, consider using
    `LIVEBOOK_APPS_PATH_WARMUP`.

  * `LIVEBOOK_APPS_PATH_PASSWORD` - the password to use for all protected apps
    deployed from `LIVEBOOK_APPS_PATH`.

  * `LIVEBOOK_APPS_PATH_WARMUP` - sets the warmup mode for apps deployed from
    `LIVEBOOK_APPS_PATH`. Must be either "auto" (apps are warmed up on Livebook
    startup, right before app deployment) or "manual" (apps are warmed up when
    building the Docker image; to do so add "RUN /app/bin/warmup_apps" to
    your image). Defaults to "auto".

  * `LIVEBOOK_AWS_CREDENTIALS` - enable Livebook to read AWS Credentials from
    environment variables, AWS Credentials, EC2/ECS metadata when configuring
    S3 buckets.

  * `LIVEBOOK_BASE_URL_PATH` - sets the base url path the web application is
    served on. Useful when deploying behind a reverse proxy.

  * `LIVEBOOK_PUBLIC_BASE_URL_PATH` - sets the base url path the `/public/*` routes
    are served on. Note that this takes precedence over `LIVEBOOK_BASE_URL_PATH`,
    if both are set. Setting this may be useful to create exceptions when deploying
    behind a reverse proxy that requires authentication.

  * `LIVEBOOK_CACERTFILE` - path to a local file containing CA certificates.
    Those certificates are used during for server authentication when Livebook
    accesses files from external sources.

  * `LIVEBOOK_CLUSTER` - configures clustering strategy when running multiple
    instances of Livebook using either the Docker image or an Elixir release.
    See the "Clustering" docs for more information:
    https://hexdocs.pm/livebook/clustering.html

  * `LIVEBOOK_COOKIE` - sets the cookie for running Livebook in a cluster.
    Defaults to a random string that is generated on boot.

  * `LIVEBOOK_DATA_PATH` - the directory to store Livebook's internal
    configuration. Defaults to "livebook" under the default user data
    directory.

  * `LIVEBOOK_DEFAULT_RUNTIME` - sets the runtime type that is used by default
    when none is started explicitly for the given notebook. Must be either
    "standalone" (Standalone), "attached:NODE:COOKIE" (Attached node)
    or "embedded" (Embedded). Defaults to "standalone".

  * `LIVEBOOK_FORCE_SSL_HOST` - sets a host to redirect to if the request is not over HTTPS.
    Note it does not apply when accessing Livebook via localhost. Defaults to nil.

  * `LIVEBOOK_HOME` - sets the home path for the Livebook instance. This is the
    default path used on file selection screens and others. Defaults to the
    user's operating system home.

  * `LIVEBOOK_IDENTITY_PROVIDER` - controls whether Zero Trust Authentication
    must be used for this Livebook instance. This is useful when deploying
    Livebook inside a cloud platform, such as Cloudflare and Google.
    Supported values are:

      * `basic_auth:<username>:<password>`
      * `cloudflare:<your-team-name (domain)>`
      * `google_iap:<your-audience (aud)>`
      * `tailscale:<tailscale-cli-socket-path>`
      * `custom:YourElixirModule`

    See our authentication docs for more information: https://hexdocs.pm/livebook/authentication.html

  * `LIVEBOOK_IFRAME_PORT` - sets the port that Livebook serves iframes at.
    This is relevant only when running Livebook without TLS. Defaults to 8081.

  * `LIVEBOOK_IFRAME_URL` - sets the URL that Livebook loads iframes from.
    By default iframes are loaded from local `LIVEBOOK_IFRAME_PORT` when accessing
    Livebook over http:// and from https://livebookusercontent.com when accessing over https://.

  * `LIVEBOOK_IMAGE_REGISTRY_URL` - sets the container image registry used to fetch livebook images from.
    By default uses `ghcr.io/livebook-dev/livebook`.

  * `LIVEBOOK_IP` - sets the ip address to start the web application on.
    Must be a valid IPv4 or IPv6 address.

  * `LIVEBOOK_LOG_LEVEL` - sets the logger level, allowing for more verbose
    logging, either of: error, warning, notice, info, debug. Defaults to warning.

  * `LIVEBOOK_LOG_METADATA` - a comma-separated list of metadata keys that should
    be included in the log messages. Livebook-specific keys include:
    - `users` (attached to evaluation and request logs)
    - `session_mode` (attached to evaluation logs, either "default" or "app")
    - `code` (attached to evaluation logs, the code being evaluated)
    - `event` (attached to evaluation logs, currently always "code.evaluate")

    By default includes only `request_id`.

  * `LIVEBOOK_LOG_FORMAT` - sets the log output format, either "text" (default)
    for human-readable logs or "json" for structured JSON.

  * `LIVEBOOK_NODE` - sets the node name for running Livebook in a cluster.
    Note that Livebook always runs using long names distribution, so the
    node host name must use a fully qualified domain name (FQDN) or an IP
    address.

  * `LIVEBOOK_PASSWORD` - sets a password that must be used to access Livebook.
    Must be at least 12 characters. Defaults to token authentication.

  * `LIVEBOOK_PROXY_HEADERS` - a comma-separated list of headers that are set by
    proxies. For example, `x-forwarded-for,x-forwarded-proto`. Configuring those
    may be required when running Livebook behind reverse proxies.

  * `LIVEBOOK_PORT` - sets the port Livebook runs on. If you want to run multiple
    instances on the same domain with the same credentials but on different ports,
    you also need to set `LIVEBOOK_SECRET_KEY_BASE`. Defaults to 8080. If set to 0,
    a random port will be picked.

  * `LIVEBOOK_SECRET_KEY_BASE` - sets a secret key that is used to sign and encrypt
    the session and other payloads used by Livebook. Must be at least 64 characters
    long and it can be generated by commands such as: `openssl rand -base64 48`.
    Defaults to a random secret on every boot.

  * `LIVEBOOK_SHUTDOWN_ENABLED` - controls if a shutdown button should be shown
    in the homepage. Set it to "true" to enable it.

  * `LIVEBOOK_TOKEN_ENABLED` - controls whether token authentication is enabled.
    Enabled by default unless `LIVEBOOK_PASSWORD` is set. Set it to "false" to
    disable it.

  * `LIVEBOOK_UPDATE_INSTRUCTIONS_URL` - sets the URL to direct the user to for
    updating Livebook when a new version becomes available.

  * `LIVEBOOK_WITHIN_IFRAME` - controls if the application is running inside an
    iframe. Set it to "true" to enable it. If you do enable it, then the application
    must run with HTTPS.

The environment variables `ERL_AFLAGS` and `ERL_ZFLAGS` can also be set to configure
Livebook and the notebook runtimes. `ELIXIR_ERL_OPTIONS` are also available to customize
Livebook, but it is not forwarded to runtimes.

末尾示例段(原文照抄):

## Examples

Starts a server:

    livebook server

Starts a server and opens up a browser at a new notebook:

    livebook server @new

Starts a server and imports the notebook at the given URL:

    livebook server https://example.com/my-notebook.livemd

启动实测:token 认证模式

不设 LIVEBOOK_PASSWORD 时 CLI 默认走 token 认证(LIVEBOOK_TOKEN_ENABLED 默认开启)。在独立数据目录以自定义端口启动一个临时实例,日志重定向到文件:

mkdir -p /tmp/lbtest && cd /tmp/lbtest
env -u LIVEBOOK_PASSWORD \
    LIVEBOOK_HOME=/tmp/lbtest LIVEBOOK_DATA_PATH=/tmp/lbtest LIVEBOOK_IFRAME_PORT=4041 \
    livebook server --ip 127.0.0.1 --port 4040 > /tmp/lbtest/server.log 2>&1 &
sleep 12 && cat /tmp/lbtest/server.log

实测回显(节选,token 为本次启动随机生成):

[info] Reading storage from /tmp/lbtest/livebook_config.v1.ets
[info] Running LivebookWeb.IframeEndpoint with Bandit 1.11.1 at 127.0.0.1:4041 (http)
[info] Running LivebookWeb.Endpoint with Bandit 1.11.1 at 127.0.0.1:4040 (http)
[Livebook] Application running at http://localhost:4040/?token=ii7sbfm5jdoybkamssfgpuur7xtvbbnd

日志证实 --ip/--port 均生效;首行说明配置存储落在 LIVEBOOK_DATA_PATH 指定目录的 livebook_config.v1.ets。随后探活验证 HTTP 服务真实可用:

elixir -e '{:ok, {{_, status, _}, _, body}} =
  :httpc.request(:get, {~c"http://127.0.0.1:4040/", []}, [], [])
IO.puts("HTTP #{status}  body_head=" <> String.slice(to_string(body), 0, 17))'

实测回显:

HTTP 200  body_head=<!DOCTYPE html>

重复启动检测

同一端口已有实例运行时再次执行 livebook server,CLI 不会报错而是检测并提示:

livebook server --port 4040

实测回显:

Livebook already running on http://localhost:4040

优雅关停

对前台进程发送 SIGTERM(kill <pid> 默认信号)后日志显示优雅关停,非残留强杀:

[notice] SIGTERM received - shutting down

⚠️ 注意:同机跑多个实例时,--port 只控制主端口,iframe 端口由 LIVEBOOK_IFRAME_PORT 环境变量控制且默认同为 8081——只改 --port 不改 LIVEBOOK_IFRAME_PORT 的双实例必然冲突,实测报错见六、Q2。

4.3 部署到 Teams:livebook deploy

第二个子命令面向 Livebook Teams(商业协作平台),把本地 .livemd 笔记本部署为 Teams 应用。--help 原文照抄:

livebook deploy --help

实测回显:

Usage: livebook deploy [options] filename [filename...]

## Available options

  --org-token             Token from your Livebook Teams organization
  --teams-key             Teams key from your Teams workspace
  --deployment-group-id   The ID of the deployment group you want to deploy to
  --dry-run               Perform a sanity check but do not actually deploy

The --help option can be given to print this notice.

## Examples

Deploys a single notebook:

    livebook deploy --org-token="lb_ot_..." --teams-key="lb_tk_..." --deployment-group-id=123 path/to/app1.livemd

Deploys multiple notebooks:

    livebook deploy --org-token="lb_ot_..." --teams-key="lb_tk_..." --deployment-group-id=123 path/to/*.livemd
选项必填说明
--org-token是Teams 组织令牌(lb_ot_ 前缀)
--teams-key是Teams 工作区密钥(lb_tk_ 前缀)
--deployment-group-id是部署组 ID
--dry-run否只做健康检查不实际部署——无 Teams 环境时可用来校验笔记本可部署性

⚠️ 注意:deploy 的完整流程需要 Livebook Teams 组织与部署组,本文实测环境未接入 Teams,仅验证了帮助与参数语义;三个凭证参数属第三方令牌,写入脚本时建议用环境变量或密钥管理注入,避免明文落盘。

4.4 发行版工具:bin/livebook 十一个子命令

发行版包装脚本覆盖启动、守护、调试、远程运维四类操作。直接调用(或不带已知子命令)会打印清单,此处以 --help 触发:

$RELEASE_ROOT/bin/livebook --help

实测回显(全文照抄,ERROR 行为原样):

Usage: livebook COMMAND [ARGS]

The known commands are:

    start          Starts the system
    start_iex      Starts the system with IEx attached
    daemon         Starts the system as a daemon
    daemon_iex     Starts the system as a daemon with IEx attached
    eval "EXPR"    Executes the given expression on a new, non-booted system
    rpc "EXPR"     Executes the given expression remotely on the running system
    remote         Connects to the running system via a remote shell
    restart        Restarts the running system via a remote command
    stop           Stops the running system via a remote command
    pid            Prints the operating system PID of the running system via a remote command
    version        Prints the release name and version to be booted

ERROR: Unknown command --help

version:打印待启动的发行版名与版本

$RELEASE_ROOT/bin/livebook version

实测回显:

livebook 0.19.10

eval:在全新非启动系统上执行 Elixir 表达式

不连接运行实例,本地拉起一个 clean 系统求值后退出,适合取版本、算配置:

$RELEASE_ROOT/bin/livebook eval "IO.puts \"eval_ok_\" <> to_string(6 * 7)"

实测回显:

eval_ok_42

rpc:对运行中的实例远程求值

表达式在存活节点上执行(表达式为 Elixir 语法):

$RELEASE_ROOT/bin/livebook rpc "IO.puts Node.self() |> to_string()"

实测回显(返回主实例的节点长名):

livebook@127.0.0.1

pid / stop / restart:默认被发行版配置禁用

三个远程命令在官方 0.19.10 发行版默认环境下实测均失败且行为一致:

$RELEASE_ROOT/bin/livebook pid; echo "exit=$?"

实测回显:

--rpc-eval : Cannot run --rpc-eval if the node is not alive (set --name or --sname)
exit=1

stop 回显同一行报错,exit=1;重要的是主实例不受影响(页面持续可访问),即该报错是"连接从未发起",不是"实例被误停"。

根因在发行版自带的 releases/0.19.10/env.sh:只有 rpc 与 remote 两个命令会注入节点分布,其余命令(含 pid/stop/restart)被显式设为无分布 + 一次性随机 cookie(节选原文):

if [ "$RELEASE_COMMAND" = "rpc" ] || [ "$RELEASE_COMMAND" = "remote" ]; then
  export RELEASE_DISTRIBUTION="name"
  if [ ! -z "${LIVEBOOK_NODE}" ]; then export RELEASE_NODE=${LIVEBOOK_NODE}; fi
  if [ ! -z "${LIVEBOOK_COOKIE}" ]; then export RELEASE_COOKIE=${LIVEBOOK_COOKIE}; fi
else
  export RELEASE_DISTRIBUTION="none"
  export RELEASE_COOKIE="${RELEASE_COOKIE:-$(head -c 512 /dev/urandom | ... )}"
fi

这是有意设计:env.sh 注释写明不希望发行版工具从 releases/COOKIE 共享固定 cookie(we don't want to share the same cookie across users)。因此运维停机不应依赖 bin/livebook stop,可用路径有三条:向主进程发 SIGTERM(实测优雅关停,见 4.2);开启 LIVEBOOK_SHUTDOWN_ENABLED=true 后从首页停机按钮关停(见 C1 指南 §5);由部署编排层执行重启(见 B2 指南「常用运维命令」)。

启动类子命令清单

start(前台启动)、start_iex(前台 + 附加 IEx)、daemon(后台守护启动)、daemon_iex(后台守护 + IEx)、remote(附加远程 shell)五个子命令本文未逐个实测——start 即主实例的运行形态(入口 bin/server 内部就是 exec ./livebook start),其余交互型命令需挂终端。另注意 Escript 层没有 daemon 能力:livebook server --daemon 实测直接报错:

1 error found!
--daemon : Unknown option

💡 技术拓展:发行版的 daemon 依赖 Elixir release 的 --detached 机制;Escript 是单文件脚本进程,官方未提供内建守护。服务器上常驻运行 Escript 实例时,推荐前台启动交给 systemd 托管(Restart=on-failure),而非自行 nohup。

五、注意事项

  1. 两层命令不要混用参数:--ip/--port/--name/--cookie 只在 Escript livebook server 上有效;发行版 bin/livebook start 没有任何端口选项,一切配置走 LIVEBOOK_* 环境变量(见 C1 指南参数总览)。
  2. 默认只绑 127.0.0.1:--ip 默认回环地址是官方安全设计,改成对外地址前必须先落实认证(LIVEBOOK_PASSWORD ≥ 12 字符或 token 模式),README「Security considerations」原话:Anyone with access to a Livebook instance will be able to access any file and execute any code in the machine。
  3. token 出现在启动日志里:token 认证模式下带 token 的完整 URL 直接打印在日志(见 4.2 实测),日志收集系统要把该行当作凭据对待。
  4. rpc 表达式是 Elixir 语法:eval/rpc 的引号内表达式由 Elixir 求值器执行,写 Erlang 语法(如 io:format(...))会直接语法报错。
  5. 发行版工具的远程命令依赖 LIVEBOOK_NODE/LIVEBOOK_COOKIE:仅 rpc/remote 生效(见 4.4),给 pid/stop 设同样变量也无法绕过——env.sh 的分支以 RELEASE_COMMAND 判定,与变量无关。
  6. 锁版本安装:hex 不带版本号安装会随最新发布漂移,与既有实例版本错位会造成 .livemd 行为差异;固定版本号安装(本文 0.19.10)是可复现底线。

六、常见问题

Q1:bin/livebook pid/stop/restart 报 "Cannot run --rpc-eval if the node is not alive (set --name or --sname)" 怎么办?

这不是故障,是官方发行版 env.sh 的安全设计:这三个命令被配置为无分布式模式(见四、4.4 根因解析)。停机用 SIGTERM、首页停机按钮或编排层操作;要远程求值用 rpc 命令(它有专门的分支注入节点名与 cookie)。实例确实存活时 rpc 正常返回(实测见 4.4),可用于判断实例健康。

Q2:临时/第二个实例启动失败,日志出现 "port 8081 already in use"?

实测排障记录:只指定 --port 4040 启动第二个实例时,iframe 端口仍默认 8081,与主实例冲突,启动直接失败退出:

[error] Running LivebookWeb.IframeEndpoint with Bandit 1.11.1 at http failed, port 8081 already in use

ERROR!!! [Livebook] shutdown: failed to start child: {Bandit, #Reference<0.1436210281.3234070532.23998>}
    ** (EXIT) shutdown: failed to start child: :listener
        ** (EXIT) :eaddrinuse

解法:同时错开 LIVEBOOK_IFRAME_PORT(如 4041),之后启动即成功(实测见 4.2)。注意 livebook server --help 的 CLI 选项里没有 iframe 端口项,只能用环境变量。

Q3:提示 "Livebook already running on http://localhost:4040"?

CLI 检测到同端口已有实例(实测回显见 4.2)。多实例各自使用独立端口 + 独立 LIVEBOOK_DATA_PATH/LIVEBOOK_HOME,避免配置存储互相覆盖。

Q4:livebook 命令安装后提示找不到?

escript 安装器会输出 PATH 提示(实测见 3.1):把 $MIX_HOME/escripts 追加进 PATH。用 asdf 管理 Elixir 的环境还需按 README 执行 asdf reshim elixir 让 escript 可见。

Q5:livebook server --daemon 为什么报 Unknown option?

Escript 版没有守护进程能力(实测回显见 4.4),daemon/daemon_iex 是发行版包装脚本的子命令。Escript 场景交给 systemd 等进程管理器托管;发行版场景用 bin/livebook daemon。

Q6:主实例的密码认证登录口令是多少?

与部署指南一致:演示实例通过 LIVEBOOK_PASSWORD 注入口令 q1w2e3r4q1w2e3r4(该变量要求 ≥ 12 字符,故为 16 位)。登录页输入该口令即可;CLI 临时实例若不设该变量则走 token 模式,URL 带 token 直接访问。

七、参考链接

Livebook 0.19.10 常用 CLI 命令详解 - Quzuo