StackStorm st2 CLI 命令与工具详解
StackStorm 3.9.0 st2 CLI 命令与工具详解:全局参数逐项说明、26 个子命令族分组详解(run/action/execution/rule/key/pack/timer/workflow/apikey 等)、st2ctl 服务管理与 10 个 st2-* 运维工具逐参数说明,附真实回显与常见选项坑位
StackStorm st2 CLI 命令与工具详解
目标:系统梳理 StackStorm 3.9.0 的命令行工具体系——st2 主命令的全局参数与 26 个子命令族、st2ctl 服务管理命令、随包分发的 10 个 st2-* 运维工具,逐参数给出真实帮助文本与实测回显,作为日常运维与排障的速查手册。全部输出在 Ubuntu 22.04 + StackStorm 3.9.0 环境实测采集(实测日期 2026-10-19);快速入门流程见《StackStorm 快速入门与实战示例》,部署见《StackStorm Docker Compose 部署指南》。
一、环境信息
| 项目 | 值 |
|---|---|
| 服务器 IP | 192.168.146.128 |
| 操作系统 | Ubuntu 22.04.4 LTS |
| StackStorm | 3.9.0 |
| CLI 版本 | st2 3.9.0, on Python 3.10.12 |
| 实测日期 | 2026-10-19 |
st2 --version
实测回显:
st2 3.9.0, on Python 3.10.12
st2 命令随 StackStorm 主程序包分发,二进制族共 12 个(/usr/bin 下实查):
| 二进制 | 用途 |
|---|---|
| st2 | 主命令,REST API 的命令行客户端 |
| st2ctl | 服务管理(启停/状态/内容注册) |
| st2-apply-rbac-definitions | 应用 RBAC 角色定义文件 |
| st2-bootstrap-rmq | 初始化 RabbitMQ 账号/队列 |
| st2-generate-symmetric-crypto-key | 生成数据存储对称加密密钥 |
| st2-register-content | 注册内容(st2ctl reload 的底层实现) |
| st2-rule-tester | 用本地触发器实例样本测试规则 |
| st2-run-pack-tests | 运行 pack 自带测试 |
| st2-self-check | 全平台内容自检 |
| st2-track-result | 跟踪指定动作执行直到结束 |
| st2-trigger-refire | 重发历史触发器实例 |
| st2-validate-pack-config | 校验 pack 配置文件与其 schema |
二、st2 全局参数
st2 --help
实测回显(头部):
usage: st2 [-h] [--version] [--url BASE_URL] [--auth-url AUTH_URL]
[--api-url API_URL] [--stream-url STREAM_URL]
[--api-version API_VERSION] [--cacert CACERT]
[--basic-auth BASIC_AUTH] [--config-file CONFIG_FILE]
[--print-config] [--skip-config] [--debug]
{run,action,action-alias,auth,login,whoami,apikey,execution,inquiry,key,pack,policy,policy-type,rule,webhook,timer,runner,sensor,trace,trigger,trigger-instance,rule-enforcement,workflow,service-registry,role,role-assignment}
...
子命令共 26 个:run、action、action-alias、auth、login、whoami、apikey、execution、inquiry、key、pack、policy、policy-type、rule、webhook、timer、runner、sensor、trace、trigger、trigger-instance、rule-enforcement、workflow、service-registry、role、role-assignment。
全局参数表(均为实测帮助文本,默认值取自参数说明):
| 参数 | 说明 | 默认取值 |
|---|---|---|
| --version | 显示版本号 | — |
| --url BASE_URL | API 基础地址 | 环境变量 ST2_BASE_URL |
| --auth-url AUTH_URL | 认证服务地址 | 环境变量 ST2_AUTH_URL |
| --api-url API_URL | API 服务地址 | 环境变量 ST2_API_URL |
| --stream-url STREAM_URL | 事件流地址 | 环境变量 ST2_STREAM_URL |
| --api-version API_VERSION | API 版本 | 环境变量 ST2_API_VERSION |
| --cacert CACERT | SSL CA 证书路径 | 环境变量 ST2_CACERT;不提供则不校验 SSL 证书 |
| --basic-auth BASIC_AUTH | 额外 basic auth 凭据 | — |
| --config-file CONFIG_FILE | CLI 配置文件路径 | ~/.st2/config |
| --print-config | 解析并打印配置值 | — |
| --skip-config | 不解析 CLI 配置文件 | — |
| --debug | 调试模式 | — |
配置优先级:命令行参数 > 环境变量(ST2_*)> 配置文件。免交互认证依赖配置文件 [credentials] 段(见 3.1 节)。
三、认证与身份
3.1 st2 login
获取令牌并写入 CLI 配置目录:
usage: st2 login [-h] [-j] [-y] [-p PASSWORD] [-l TTL] [-w] username
Authenticate user, acquire access token, and update CLI config directory
positional arguments:
username Name of the user to authenticate.
options:
-h, --help show this help message and exit
-j, --json Print output in JSON format.
-y, --yaml Print output in YAML format.
-p PASSWORD, --password PASSWORD
Password for the user. If password is not provided, it
will be prompted for.
-l TTL, --ttl TTL The life span of the token in seconds. Max TTL
configured by the admin supersedes this.
-w, --write-password Write the password in plain text to the config file
(default is to omit it)
实测回显:
$ st2 login st2admin -p q1w2e3r4
Logged in as st2admin
Note: You didn't use --write-password option so the password hasn't been stored in the client config and you will need to login again in 24 hours when the auth token expires.
As an alternative, you can run st2 login command with the "--write-password" flag, but keep it mind this will cause it to store the password in plain-text in the client config file (~/.st2/config).
免交互登录的配置文件写法(~/.st2/config):
[credentials]
username = st2admin
password = q1w2e3r4
3.2 st2 auth
仅获取令牌不写配置(适合脚本中临时取令牌):
usage: st2 auth [-h] [-j] [-y] [-p PASSWORD] [-l TTL] [-t] username
Authenticate user and acquire access token.
options:
-h, --help show this help message and exit
-j, --json Print output in JSON format.
-y, --yaml Print output in YAML format.
-p PASSWORD, --password PASSWORD
Password for the user. If password is not provided, it
will be prompted for.
-l TTL, --ttl TTL The life span of the token in seconds. Max TTL
configured by the admin supersedes this.
-t, --only-token On successful authentication, print only token to the
console.
3.3 st2 whoami
usage: st2 whoami [-h] [-j] [-y]
Display the currently authenticated user
options:
-h, --help show this help message and exit
-j, --json Print output in JSON format.
-y, --yaml Print output in YAML format.
实测回显:
Currently logged in as "st2admin".
Authentication method: authentication token
Authentication token expire time: 2026-10-20T10:41:58Z
RBAC:
- Enabled: False
- Roles:
四、动作与执行
4.1 st2 run(手动执行动作)
最高频命令。完整帮助:
usage: st2 run [-t TOKEN] [--api-key API_KEY] [-j] [-y] [-h] [--with-schema]
[--raw] [--show-tasks] [--depth DEPTH] [-w WIDTH [WIDTH ...]]
[[--attr ATTR [ATTR ...] | -d | [-k KEY | --delay DELAY |]
--tail | --auto-dict]] [--trace-tag TRACE_TAG]
[--trace-id TRACE_ID] [-a] [-e] [-u USER]
[ref-or-id] [parameters ...]
Invoke an action manually.
positional arguments:
ref-or-id Action reference (pack.action_name) or ID of the
action.
parameters List of keyword args, positional args, and optional
args for the action.
options:
-t TOKEN, --token TOKEN
Access token for user authentication. Get
ST2_AUTH_TOKEN from the environment variables by
default.
--api-key API_KEY Api Key for user authentication. Get ST2_API_KEY from
the environment variables by default.
-j, --json Print output in JSON format.
-y, --yaml Print output in YAML format.
-h, --help Print usage for the given action.
--attr ATTR [ATTR ...]
List of attributes to include in the output. "all" or
unspecified will return all attributes.
-d, --detail Display full detail of the execution in table format.
-k KEY, --key KEY If result is type of JSON, then print specific key-
value pair; dot notation for nested JSON is supported.
--delay DELAY How long (in milliseconds) to delay the execution
before scheduling.
--tail Automatically start tailing new execution.
--auto-dict Automatically convert list items to dictionaries when
colons are detected. (NOTE - this parameter and its
functionality will be deprecated in the next release
in favor of a more robust conversion method)
--trace-tag TRACE_TAG, --trace_tag TRACE_TAG
A trace tag string to track execution later.
--trace-id TRACE_ID Existing trace id for this execution.
-a, --async Do not wait for action to finish.
-e, --inherit-env Pass all the environment variables which are
accessible to the CLI as "env" parameter to the
action. Note: Only works with python, local and remote
runners.
-u USER, --user USER User under which to run the action (admins only).
常用组合实测:
$ st2 run core.local -- date -R
.
id: 6ad5f8bd5da20c42c4c374e7
action.ref: core.local
context.user: st2admin
parameters:
cmd: date -R
status: succeeded
result:
stdout: Mon, 19 Oct 2026 11:02:21 +0000
succeeded: true
$ st2 run -a demo.greet name=ops # -a 异步提交,不等待结果
$ st2 run -j core.http url=https://docs.stackstorm.com method=GET # -j JSON 输出
$ st2 run --tail demo.roll_call name=ops # 提交后自动跟踪工作流输出
要点:参数一律 参数名=值 命名传参;core.local/core.remote 用 -- 分隔被执行命令;-h 后跟动作名可打印该动作的参数 schema(st2 run core.local -h)。
4.2 st2 action
usage: st2 action [-h]
{list,get,create,update,delete,clone,enable,disable,execute}
...
positional arguments:
{list,get,create,update,delete,clone,enable,disable,execute}
List of commands for managing actions.
list Get the list of actions.
get Get individual action.
create Create a new action.
update Updating an existing action.
delete Delete an existing action.
clone Clone a new action.
enable Enable an existing action.
disable Disable an existing action.
execute Invoke an action manually.
常用形态:st2 action list [--pack=core]、st2 action get demo.greet、st2 action disable/enable <ref>。列表输出示例(见《StackStorm 快速入门与实战示例》2.1 节完整表格)。
4.3 st2 execution
执行历史管理:
positional arguments:
{list,get,re-run,cancel,pause,resume,tail}
List of commands for managing action executions.
list Get the list of the 50 most recent action executions.
get Get individual action execution.
re-run Re-run a particular action.
cancel Cancel action executions.
pause Pause action executions (workflow executions only).
resume Resume action executions (workflow executions only).
tail Tail output of a particular execution.
常用形态与实测(-n 取最近 N 条,-n -1 取全量):
$ st2 execution list -n 5 # 最近 5 条
$ st2 execution get 6ad5f9209fab15a925cf572e
$ st2 execution re-run 6ad5f9209fab15a925cf572e
$ st2 execution tail 6ad5f9209fab15a925cf572e
4.4 st2 workflow
工作流静态检查(仅支持 Orquesta):
usage: st2 workflow inspect [-h] [--file FILE | --action ACTION]
Inspect workflow definition and return the list of errors if any.
options:
-h, --help show this help message and exit
--file FILE Local file path to the workflow definition.
--action ACTION Reference name for the registered action. This option works
only if the file referenced by the entry point is installed
locally under /opt/stackstorm/packs.
实测回显:
$ st2 workflow inspect --file /opt/stackstorm/packs.dev/demo/actions/workflows/roll_call.yaml
No errors found in workflow definition.
注意 --file 与 --action 二选一;位置参数传路径会报 st2: error: unrecognized arguments: /path/to/workflow.yaml。--action 仅对装在 /opt/stackstorm/packs 下的包生效,本地开发包(packs.dev)用 --file 传绝对路径。
4.5 st2 inquiry
usage: st2 inquiry [-h] {list,get,respond} ...
Inquiries provide an opportunity to ask a question and wait for a response in
a workflow.
positional arguments:
{list,get,respond} List of commands for managing inquiries.
list Get the list of the 50 most recent inquiries.
get Get individual inquiry.
respond Respond to an inquiry.
inquiry 配合 core.ask 动作在工作流中实现「暂停等人工输入」;respond 提交答案后工作流继续。
五、规则与触发
5.1 st2 rule
positional arguments:
{list,get,create,update,delete,clone,enable,disable}
List of commands for managing rules.
list Get the list of the 50 most recent rules.
get Get individual rule.
create Create a new rule.
update Updating an existing rule.
delete Delete an existing rule.
clone Clone a new rule.
enable Enable an existing rule.
disable Disable an existing rule.
create 直接以 YAML 文件为入参(无需先 register):st2 rule create /path/to/rule.yaml;文件更新后 st2 rule update <ref> <文件>;删除实测回显:
$ st2 rule delete demo.timer_greet
Resource with id "demo.timer_greet" has been successfully deleted.
5.2 st2 timer
usage: st2 timer [-h] {list,get} ...
Timers.
positional arguments:
{list,get} List of commands for managing timers.
list Get the list of timers.
get Get individual timer.
实测回显(CronTimer 规则创建后自动注册的定时器):
+--------------------------+----------------------+------+----------------------+--------------------+----------------------+
| id | uid | pack | name | type | parameters |
+--------------------------+----------------------+------+----------------------+--------------------+----------------------+
| 6ad5f8e95da20c42c4c374ec | trigger:core:ae7e44d | core | ae7e44d2-093e-4626- | core.st2.CronTimer | {'minute': '*/2', |
| | ... | | 8478-85683493dd4b | | 'timezone': 'UTC'} |
+--------------------------+----------------------+------+----------------------+--------------------+----------------------+
5.3 st2 trigger / trigger-instance
usage: st2 trigger [-h] {list,get,create,update,delete,clone,getspecs} ...
list Get the list of triggers.
get Get individual trigger.
create Create a new trigger.
update Updating an existing trigger.
delete Delete an existing trigger.
clone Clone a new trigger.
getspecs Return Trigger Specifications of a Trigger.
usage: st2 trigger-instance [-h] {list,get,re-emit} ...
list Get the list of the 50 most recent triggerinstances.
get Get individual trigger instance.
re-emit Re-emit a particular trigger instance.
trigger 管理触发器类型定义,trigger-instance 是历史触发记录;re-emit 可把某条历史触发重新注入系统(配合 rule-tester 排障很有用)。
5.4 st2 webhook / sensor / runner
usage: st2 webhook [-h] {list,get} ...
list Get the list of webhooks.
get Get individual webhook.
usage: st2 sensor [-h] {list,get,enable,disable} ...
list Get the list of sensortypes.
get Get individual sensor.
enable Enable an existing sensor.
disable Disable an existing sensor.
usage: st2 runner [-h] {list,get,enable,disable} ...
list Get the list of runners.
get Get individual runner.
enable Enable an existing runner.
disable Disable an existing runner.
5.5 st2 rule-enforcement
usage: st2 rule-enforcement [-h] {list,get,create,update,delete,clone} ...
list Get the list of the 50 most recent rule enforcements.
get Get individual rule enforcement.
create Create a new rule enforcement.
update Updating an existing rule enforcement.
delete Delete an existing rule enforcement.
clone Clone a new rule enforcement.
rule-enforcement 记录「哪条规则因何触发器实例被执行了」,是规则链路的审计视图。
六、内容包与配置
6.1 st2 pack
usage: st2 pack [-h] {list,get,show,search,install,remove,register,config} ...
positional arguments:
{list,get,show,search,install,remove,register,config}
List of commands for managing packs.
list Get the list of packs.
get Get information about an installed pack.
show Get information about an available pack from the
index.
search Search the index for a pack with any attribute
matching the query.
install Install new packs.
remove Remove packs.
register Register pack(s): sync all file changes with DB.
config Configure a pack based on config schema.
实测回显(本环境已安装包):
$ st2 pack list
+---------+---------+--------------------------------+---------+------------------+
| ref | name | description | version | author |
+---------+---------+--------------------------------+---------+------------------+
| chatops | chatops | ChatOps integration pack | 3.9.0 | StackStorm, Inc. |
| core | core | Basic core actions. | 3.9.0 | StackStorm, Inc. |
| default | default | Default pack where all | 3.9.0 | StackStorm, Inc. |
| | | resources created using the | | |
| | | API with no pack specified get | | |
| | | saved. | | |
| demo | demo | 入门示例 pack:脚本动作、Orquesta | 1.0.0 | admin |
| | | 工作流与定时规则 | | |
| linux | linux | Generic Linux actions | 3.9.0 | StackStorm, Inc. |
| packs | packs | Pack management functionality. | 3.9.0 | StackStorm, Inc. |
+---------+---------+--------------------------------+---------+------------------+
register 实测回显:
$ st2 pack register demo
+--------------+-------+
| Property | Value |
+--------------+-------+
| actions | 2 |
| aliases | 0 |
| configs | 0 |
| policies | 0 |
| policy_types | 3 |
| rule_types | 2 |
| rules | 0 |
| runners | 14 |
| sensors | 0 |
| triggers | 0 |
+--------------+-------+
⚠️ 3.9.0 的
st2 pack register不支持--pack选项(报st2: error: unrecognized arguments: --pack),用位置参数st2 pack register demo;不带参数则全量注册。从索引安装:st2 pack install <name>;查询:st2 pack search <关键字>。
6.2 st2 key(Datastore)
usage: st2 key [-h] {list,get,delete,clone,set,load,delete_by_prefix} ...
positional arguments:
{list,get,delete,clone,set,load,delete_by_prefix}
List of commands for managing key value pairs.
list Get the list of the 50 most recent key value pairs.
get Get individual key value pair.
delete Delete an existing key value pair.
clone Clone a new key value pair.
set Set an existing key value pair.
load Load a list of key value pairs from file.
delete_by_prefix Delete KeyValue pairs which match the provided prefix
key list 完整选项(逐项实测):
usage: st2 key list [-h] [-t TOKEN] [--api-key API_KEY] [-j] [-y]
[-a ATTR [ATTR ...]] [-w WIDTH [WIDTH ...]]
[--prefix PREFIX] [-d] [-s SCOPE] [-u USER] [-n LAST]
Get the list of the 50 most recent key value pairs.
options:
-h, --help show this help message and exit
-t TOKEN, --token TOKEN
Access token for user authentication. Get
ST2_AUTH_TOKEN from the environment variables by
default.
--api-key API_KEY Api Key for user authentication. Get ST2_API_KEY from
the environment variables by default.
-j, --json Print output in JSON format.
-y, --yaml Print output in YAML format.
-a ATTR [ATTR ...], --attr ATTR [ATTR ...]
List of attributes to include in the output. "all"
will return all attributes.
-w WIDTH [WIDTH ...], --width WIDTH [WIDTH ...]
Set the width of columns in output.
--prefix PREFIX Only return values with names starting with the
provided prefix.
-d, --decrypt Decrypt secrets and displays plain text.
-s SCOPE, --scope SCOPE
Scope item is under. Example: "user".
-u USER, --user USER User for user scoped items (admin only).
-n LAST, --last LAST List N most recent key value pairs. Use -n -1 to fetch
the full result set.
set 写入(--encrypt 落库密文,--expire 支持过期时间)、get 读取、delete 删除的完整实测回显见《StackStorm 快速入门与实战示例》第六节。
6.3 st2 policy / policy-type
usage: st2 policy [-h] {list,get,create,update,delete,clone} ...
list Get the list of policies.
get Get individual policy.
create Create a new policy.
update Updating an existing policy.
delete Delete an existing policy.
clone Clone a new policy.
usage: st2 policy-type [-h] {list,get} ...
list Get the list of policy types.
get Get individual policy type.
实测回显(policy-type list 节选,平台内置两类并发限制策略):
+--------------------------+---------------+------------------+---------------------------------+
| id | resource_type | name | description |
+--------------------------+---------------+------------------+---------------------------------+
| 6ad5f3f7c9f37d18c953cada | action | concurrency | Limits the concurrent |
| | | | executions for the action. |
| 6ad5f3f7c9f37d18c953cadb | action | concurrency.attr | Limits the concurrent |
| | | | executions for the action by |
| | | | attribute(s). |
七、API Key 与 RBAC
7.1 st2 apikey
usage: st2 apikey [-h] {list,get,create,delete,clone,enable,disable,load} ...
list Get the list of api keys.
get Get individual api key.
create Create a new api key.
delete Delete an existing api key.
clone Clone a new api key.
enable Enable an existing api key.
disable Disable an existing api key.
load Load api key from a file.
create 支持 -m 附加元数据,实测回显(密钥明文只在创建时显示一次):
$ st2 apikey create -m '{"description": "D5 文档实测"}'
+------------+--------------------------------------------------------------+
| Property | Value |
+------------+--------------------------------------------------------------+
| id | 6ad5f65bc9f37d18c953cb40 |
| created_at | 2026-10-19T10:52:11.451329Z |
| enabled | True |
| key | YWU3NDM5MTg1OGZkZjc2YWE5OGExNmY1NDJlMTJmMGNhOTgxMDA5ZDhlYmZj |
| | OTJlYzEyOGViZWEwMWVkOTA3Ng |
| metadata | { |
| | "description": "D5 \u6587\u6863\u5b9e\u6d4b" |
| | } |
| uid | api_key:e8c8fc4ce700418aa582b15f4475b3b3a4ca8c8a0b6d6b15fe28 |
| | 6cf6ea51d4f349259aa69c88eabae0922180bf318e27346387a7e1196dab |
| | d15526844b7f7ea2 |
| user | st2admin |
+------------+--------------------------------------------------------------+
$ st2 apikey list
+--------------------------+----------+--------------------------------+
| id | user | metadata |
+--------------------------+----------+--------------------------------+
| 6ad5f65bc9f37d18c953cb40 | st2admin | {'description': 'D5 文档实测'} |
+--------------------------+----------+--------------------------------+
API Key 用法:请求 st2 API 时带 St2-Api-Key 头,或 CLI 里 --api-key 参数,适合对接外部系统(比令牌长期稳定)。
7.2 st2 role / role-assignment / service-registry
usage: st2 role [-h] {list,get} ...
list Get the list of the roles.
get Get individual role.
usage: st2 role-assignment [-h] {list,get} ...
list Get the list of the role assignments.
get Get individual role assignment.
usage: st2 service-registry [-h] {group,member} ...
group Manage service registry groups
member Manage service registry members
实测回显(RBAC 未启用时 role list 仍显示内置角色):
+--------------------------+--------------+--------+--------------+
| id | name | system | description |
+--------------------------+--------------+--------+--------------+
| 6ad5f3f1799beca33fd60325 | admin | True | admin |
+--------------------------+--------------+--------+--------------+
7.3 st2 trace / action-alias
usage: st2 trace [-h] {list,get} ...
list Get the list of the 50 most recent traces.
get Get individual trace.
usage: st2 action-alias [-h]
{list,get,create,update,delete,clone,match,execute,test}
...
list Get the list of action aliases.
get Get individual action alias.
create Create a new action alias.
update Updating an existing action alias.
delete Delete an existing action alias.
clone Clone a new action alias.
match Get the action alias that match the command text.
execute Execute the command text by finding a matching action
alias.
execute/test Execute the command text by finding a matching action
alias and format the result.
trace 把「触发器实例 → 规则 → 执行」串成一条追踪链(st2 run --trace-tag <tag> 打标后可整链回查);action-alias 是 ChatOps 的命令别名层(配合 st2chatops 使用)。
八、st2ctl:服务管理与内容注册
Usage: st2ctl {start, stop, restart, status}
Usage: st2ctl {restart-component}
positional arguments:
component Name of the st2 service to restart.
st2actionrunner st2api st2stream st2auth st2garbagecollector st2notifier st2rulesengine st2sensorcontainer st2chatops st2timersengine st2workflowengine st2scheduler
Usage: st2ctl {reopen-log-files}
positional arguments:
component Name of the st2 service to reopen the log files for.
(组件清单同上)
Usage: st2ctl {reload, clean}
optional arguments:
--register-all Register all.
--register-triggers Register all triggers.
--register-sensors Register all sensors.
--register-rules Register all rules.
--register-runners Register all runners.
--register-actions Register all actions.
--register-aliases Register all aliases.
--register-policies Register all policies.
--register-configs Register all configuration files.
--register-setup-virtualenvs Create Python virtual environments for all the registered packs.
--register-recreate-virtualenvs (Delete and re-)create Python virtual environments for all the registered packs.
status 实测回显(st2client 环境):
##### st2 components status #####
st2actionrunner is not running.
st2api is not running.
st2stream is not running.
st2auth is not running.
st2garbagecollector is not running.
st2notifier is not running.
st2rulesengine is not running.
⚠️ st2ctl status 显示全部 not running 不一定是故障:st2ctl 查询的是本机 supervisor 托管的进程。在包安装的参考部署中各服务由 systemd/supervisor 托管在本机,输出正常;而在多服务分体部署(如 compose 形态各组件独立运行)中,st2ctl 所在环境并不承载这些进程,status 自然全为 not running。此时判断服务健康应改用 API 探活或平台命令(如
st2 --version能返回即说明 API 链路可用)。
常用运维组合:
st2ctl reload --register-all # 等价于全量内容注册(底层调 st2-register-content)
st2ctl restart st2api # 重启单个组件
st2ctl status # 组件状态
九、st2-* 工具族
9.1 st2-generate-symmetric-crypto-key
usage: st2-generate-symmetric-crypto-key [-h] -k KEY_PATH [-f]
Tool for crypto key generation.
options:
-h, --help show this help message and exit
-k KEY_PATH, --key-path KEY_PATH
Path to file to write key to. Secure permissions of
file so only admin can read the crypto key.
-f, --force Force rewrite the key file if already exists.
数据存储加密密钥的生成工具(compose 形态由 st2makesecrets 作业自动调用;包安装形态在启用 --encrypt 前手动生成到 /etc/st2/keys/datastore_key.json)。换钥即旧密文不可解,-f 覆盖前务必备份旧钥。
9.2 st2-register-content
内容注册底层工具(st2ctl reload 与 st2 pack register 的实现),常用选项:
--register-all Register all.
--register-actions 注册动作
--register-aliases 注册别名
--register-configs 注册配置
--register-policies 注册策略
--register-rules 注册规则
--register-runners 注册执行器
--register-sensors 注册传感器
--register-notriggers 排除触发器
--register-pack REGISTER_PACK 仅注册指定 pack
--register-fail-on-failure 注册失败即退出非零
--register-setup-virtualenvs 为 pack 创建 Python 虚拟环境
--register-recreate-virtualenvs 删除并重建虚拟环境
9.3 st2-rule-tester
usage: st2-rule-tester [-h] [--config-dir DIR] [--config-file PATH] [--debug]
... [--offline] [--rule RULE] [--rule-ref RULE_REF]
[--trigger-instance TRIGGER_INSTANCE]
[--trigger-instance-id TRIGGER_INSTANCE_ID] ...
options:
--rule RULE 本地规则文件路径
--rule-ref RULE_REF 已注册规则的 ref
--trigger-instance TRIGGER_INSTANCE
本地触发器实例样本文件(JSON/YAML)
--trigger-instance-id TRIGGER_INSTANCE_ID
用历史触发器实例 ID 测试
--offline 离线模式(不连数据库)
用法:把一条真实触发器负载喂给规则定义,验证 criteria 匹配结果,上线前验证规则正确性。
9.4 st2-trigger-refire
usage: st2-trigger-refire [-h] ... [--trigger-instance-id TRIGGER_INSTANCE_ID]
...
按 --trigger-instance-id 把历史触发器实例重新注入平台,重新走一遍规则匹配(排障与重放利器)。
9.5 st2-track-result
usage: st2-track-result [-h] [--config-dir DIR] [--config-file PATH] [--debug]
[--delete] ... id
positional arguments:
id ID of the action execution.
options:
--delete 跟踪结束后删除跟踪记录
阻塞式跟踪一条执行直到终态,适合脚本里等待工作流完成。
9.6 st2-validate-pack-config
usage: st2-validate-pack-config [-h] ... [--config-path CONFIG_PATH]
[--schema-path SCHEMA_PATH] ...
options:
--config-path CONFIG_PATH
Path to the config file to validate.
--schema-path SCHEMA_PATH
Path to the config schema to use for validation.
按 pack 的 config.schema.yaml 校验 config.yaml,提交配置前先过一遍。
9.7 st2-apply-rbac-definitions / st2-bootstrap-rmq
usage: st2-apply-rbac-definitions [-h] [--config-dir DIR] [--config-file PATH] [--debug] ...
# 把 /opt/stackstorm/rbac/ 下的角色/赋权 YAML 应用到系统(RBAC 启用后每次修改定义后执行)
usage: st2-bootstrap-rmq [-h] [--config-dir DIR] [--config-file PATH] [--debug] ...
# 初始化 RabbitMQ:创建 st2 专用账号与消息队列拓扑(部署初始化用,日常不重复执行)
9.8 st2-self-check / st2-run-pack-tests
$ st2-self-check -h
Usage: /usr/bin/st2-self-check
Options:
-o Skip Orquesta tests
-w Run Windows tests
-b Which branch of st2tests to use (defaults to master)
$ st2-run-pack-tests -h
# 在 pack 目录内运行其自带测试套件(pytest 封装,配合 st2tests 测试内容包)
st2-self-check 会对全平台内容(动作/规则/传感器)做一致性自检,升级后跑一遍可快速发现注册异常。
十、常见问题
Q1:st2 pack register --pack demo 报错?
3.9.0 不支持 --pack 选项,实测报 st2: error: unrecognized arguments: --pack。改用位置参数:st2 pack register demo。
Q2:st2 key list -p demo 报错?
key list 没有 -p 选项,实测报 st2: error: unrecognized arguments: -p demo。前缀过滤用 --prefix:st2 key list --prefix demo.。
Q3:st2ctl status 全部 not running 是不是服务挂了?
不一定。st2ctl 只看本机 supervisor 进程;分体部署中各服务不在 st2ctl 所在环境运行。用 API 探活判断真实健康状态(如 st2 --version、st2 execution list 能正常返回即链路可用)。
Q4:st2 workflow inspect <路径> 报 unrecognized arguments?
inspect 只接受 --file <路径> 或 --action <ref> 选项,不接受位置参数。另外 --action 仅对 /opt/stackstorm/packs 下的包有效,packs.dev 本地包用 --file。
Q5:apikey 创建后 list 里看不到 key 值? 正常。密钥明文只在 create 时回显一次,list 只显示 id/user/metadata。丢失时 delete 后重建。
Q6:st2 run demo.greet StackStorm 这类位置传参报 400?
CLI 会把裸位置值解析为执行器的 cmd 参数导致 schema 校验失败(Additional properties are not allowed ('cmd' was unexpected))。统一改用命名参数 st2 run demo.greet name=StackStorm。
十一、参考链接
- 官方 CLI 参考:https://docs.stackstorm.com/reference/cli.html
- st2client 源码:https://github.com/StackStorm/st2/tree/master/st2client
- st2ctl 文档:https://docs.stackstorm.com/reference/pack_mgmt.html 与 https://docs.stackstorm.com/administration/admin_cmds.html
- RBAC:https://docs.stackstorm.com/rbac.html
- Datastore:https://docs.stackstorm.com/datastore.html
- 相关篇目:《StackStorm 快速入门与实战示例》《StackStorm Docker Compose 部署指南》《StackStorm 3.9.0 介绍与选型指南》