StackStorm 快速入门与实战示例
StackStorm 3.9.0 快速入门与实战示例:CLI 登录与动作库初识、demo 内容包从零创建(脚本动作)、Orquesta 两步工作流、CronTimer 定时规则与触发验证、Datastore 数据存储读写加密,含参数校验、cron 写法、工作流文件位置等真实排障案例
StackStorm 快速入门与实战示例
目标:在一台已完成 StackStorm 3.9.0 部署的服务器上,从零走通「脚本动作 → Orquesta 工作流 → 定时规则 → 数据存储」最小闭环:创建自己的 demo 内容包、注册、执行、验证定时触发,并沉淀四个真实踩坑案例(参数校验、cron 写法、工作流文件位置、input 段缺失)。本文全部命令与输出均在 Ubuntu 22.04 + StackStorm 3.9.0 环境逐条实测(实测日期 2026-10-19)。部署过程见《StackStorm Docker Compose 部署指南》,命令全量参考见《StackStorm st2 CLI 命令与工具详解》。
一、环境信息
| 项目 | 值 |
|---|---|
| 服务器 IP | 192.168.146.128 |
| 操作系统 | Ubuntu 22.04.4 LTS |
| StackStorm | 3.9.0(已部署并可登录,前置见《StackStorm Docker Compose 部署指南》) |
| 登录账号 | st2admin / q1w2e3r4 |
| 内容包开发目录 | /opt/stackstorm/packs.dev/demo/ |
| 实测日期 | 2026-10-19 |
登录确认(st2 3.9.0,Python 3.10.12):
st2 --version
实测回显:
st2 3.9.0, on Python 3.10.12
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 whoami
实测回显:
Currently logged in as "st2admin".
Authentication method: authentication token
Authentication token expire time: 2026-10-20T10:41:58Z
RBAC:
- Enabled: False
- Roles:
二、初识动作库与第一次执行
2.1 浏览内置动作
StackStorm 自带 core 内容包,含本地/远程命令执行、HTTP 调用等通用动作。按包过滤查看:
st2 action list --pack=core
实测回显(节选头部):
+---------------------+------+----------------------------------------------------+
| ref | pack | description |
+---------------------+------+----------------------------------------------------+
| core.announcement | core | Action that broadcasts the announcement to all |
| | | stream consumers. |
| core.ask | core | Action for initiating an Inquiry (usually in a |
| | | workflow) |
| core.echo | core | Action that executes the Linux echo command on the |
| | | localhost. |
| core.error | core | Action that executes the Linux echo command (to |
+---------------------+------+----------------------------------------------------+
💡 技术拓展:动作引用(ref)格式固定为
包名.动作名(如 core.local)。core.local 在本机执行命令,core.remote 经 SSH 在远端执行(需配好免密登录),两者都用--分隔动作参数与被执行命令,也支持cmd="..."参数传整条命令。
2.2 第一次执行
st2 run core.local -- date -R
实测回显:
.
id: 6ad5f8bd5da20c42c4c374e7
action.ref: core.local
context.user: st2admin
parameters:
cmd: date -R
status: succeeded
start_timestamp: Mon, 19 Oct 2026 11:02:21 UTC
end_timestamp: Mon, 19 Oct 2026 11:02:21 UTC
result:
failed: false
return_code: 0
stderr: ''
stdout: Mon, 19 Oct 2026 11:02:21 +0000
succeeded: true
关注四个字段:id 是本次执行的唯一 ID(可用 st2 execution get <id> 回查);context.user 是触发者;status 是执行状态;result.stdout 是命令真实输出。
三、第一个脚本动作
在 /opt/stackstorm/packs.dev/ 下创建自己的 demo 内容包。packs.dev 是 StackStorm 约定的本地开发包目录,与从官方索引安装到 /opt/stackstorm/packs/ 的包互不干扰。
3.1 创建包描述 pack.yaml
mkdir -p /opt/stackstorm/packs.dev/demo/actions/scripts \
/opt/stackstorm/packs.dev/demo/actions/workflows \
/opt/stackstorm/packs.dev/demo/rules
cat > /opt/stackstorm/packs.dev/demo/pack.yaml <<'EOF'
---
name: demo
description: 入门示例 pack:脚本动作、Orquesta 工作流与定时规则
version: 1.0.0
author: admin
email: admin@example.com
EOF
3.2 动作元数据 greet.meta.yaml
每个动作由「元数据文件 + 可执行内容」组成。元数据声明 runner_type(执行器类型)、入口文件与参数:
cat > /opt/stackstorm/packs.dev/demo/actions/greet.meta.yaml <<'EOF'
---
name: greet
runner_type: local-shell-script
entry_point: scripts/greet.sh
description: 问候指定对象(第一个入门脚本动作)
enabled: true
parameters:
name:
type: string
description: 要问候的名字
required: true
position: 0
EOF
cat > /opt/stackstorm/packs.dev/demo/actions/scripts/greet.sh <<'EOF'
#!/usr/bin/env bash
# 第一个入门动作:接收 name 参数并输出问候语
echo "Hello, ${1}! Welcome to StackStorm."
EOF
chmod +x /opt/stackstorm/packs.dev/demo/actions/scripts/greet.sh
💡 技术拓展:runner_type 决定动作怎么被执行。local-shell-script 在 st2 所在服务器本地跑脚本;remote-shell-script 经 SSH 到目标机跑;orquesta 表示本动作是一个工作流定义;python-script 会在该包的 Python 虚拟环境中运行。
position: 0声明 name 可以作为第 0 个位置参数传入。
3.3 注册内容包
文件就绪后向平台注册(注册会把包内内容同步进数据库):
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 |
+--------------+-------+
说明:actions 计数包含本包新注册的动作;runners 14 是平台注册的执行器类型总数(含 core/local/orquesta 等),首次注册时会一并同步。
3.4 查询与执行
st2 action get demo.greet
实测回显:
+---------------+--------------------------------------------------------------+
| Property | Value |
+---------------+--------------------------------------------------------------+
| id | 6ad5f505c9f37d18c953cb2b |
| uid | action:demo:greet |
| ref | demo.greet |
| pack | demo |
| name | greet |
| description | 问候指定对象(第一个入门脚本动作) |
| enabled | True |
| entry_point | scripts/greet.sh |
| runner_type | local-shell-script |
| parameters | { |
| | "name": { |
| | "type": "string", |
| | "description": |
| | "\u8981\u95ee\u5019\u7684\u540d\u5b57", |
| | "required": true, |
| | "position": 0 |
| | } |
| | } |
| metadata_file | actions/greet.meta.yaml |
| notify | |
| output_schema | |
| tags | |
+---------------+--------------------------------------------------------------+
执行(用命名参数传值):
st2 run demo.greet name=StackStorm
实测回显:
.
id: 6ad5f753c9f37d18c953cb42
action.ref: demo.greet
context.user: st2admin
parameters:
name: StackStorm
status: succeeded
start_timestamp: Mon, 19 Oct 2026 10:56:19 UTC
end_timestamp: Mon, 19 Oct 2026 10:56:19 UTC
result:
failed: false
return_code: 0
stderr: ''
stdout: Hello, StackStorm! Welcome to StackStorm.
succeeded: true
3.5 两种参数报错(排障)
报错一:必填参数缺失。 不带参数执行:
st2 run demo.greet
实测回显:
ERROR: 400 Client Error: Bad Request
MESSAGE: 'name' is a required property for url: http://st2api:9101/executions
报错二:位置参数被当作未知参数。 尽管元数据里写了 position: 0,直接把值跟在动作名后面仍会报错:
st2 run demo.greet StackStorm
实测回显:
ERROR: 400 Client Error: Bad Request
MESSAGE: Additional properties are not allowed ('cmd' was unexpected) for url: http://st2api:9101/executions
原因:CLI 把位置值解析成了执行器参数 cmd,而 demo.greet 的参数 schema 里没有 cmd,服务端直接拒绝。结论:st2 run 一律用 参数名=值 的命名写法;-- 后接子命令的写法只适用于 core.local/core.remote 这类以 cmd 为参数的执行器动作。
四、Orquesta 两步工作流
4.1 工作流元数据与定义
工作流也是一种动作:元数据 runner_type 为 orquesta,entry_point 指向工作流定义文件。注意 entry_point 相对 actions/ 目录解析,工作流文件必须放在 actions/workflows/ 子目录:
cat > /opt/stackstorm/packs.dev/demo/actions/roll_call.meta.yaml <<'EOF'
---
name: roll_call
runner_type: orquesta
entry_point: workflows/roll_call.yaml
description: 两步 Orquesta 工作流:先广播、再问候
enabled: true
parameters:
name:
type: string
description: 要点名的对象
required: true
default: StackStorm
EOF
cat > /opt/stackstorm/packs.dev/demo/actions/workflows/roll_call.yaml <<'EOF'
---
version: '1.0'
description: 先用 core.echo 广播,再调用 demo.greet 问候
input:
- name
tasks:
announce:
action: core.echo
input:
message: "{{ ctx().name }}"
next:
- when: <% succeeded() %>
do: greet
greet:
action: demo.greet
input:
name: "{{ ctx().name }}"
EOF
定义要点:
input:段显式声明工作流入参(- name),任务里用{{ ctx().name }}(Jinja)或<% ctx().name %>(YAQL)引用;next:的when: <% succeeded() %>表示上一任务成功才进入下一任务,实现 announce → greet 的顺序依赖。
💡 技术拓展:Orquesta 是 StackStorm 3.x 的默认工作流引擎,表达式混用 Jinja(
{{ }},用于值替换)与 YAQL(<% %>,用于条件与查询)两种语法。st2 workflow inspect --file <定义文件>可在工作流上线前做静态检查,逐条列出表达式错误。
4.2 注册与执行
st2 pack register demo
st2 run demo.roll_call name=运维组
实测回显(注册表见 3.3 节格式;执行输出如下):
.
.
.
id: 6ad5f8c65da20c42c4c374ea
action.ref: demo.roll_call
parameters:
name: "\u8FD0\u7EF4\u7EC4"
status: succeeded
start_timestamp: Mon, 19 Oct 2026 11:02:30 UTC
end_timestamp: Mon, 19 Oct 2026 11:02:31 UTC
log:
- status: requested
timestamp: '2026-10-19T11:02:30.656000Z'
- status: scheduled
timestamp: '2026-10-19T11:02:30.734000Z'
- status: running
timestamp: '2026-10-19T11:02:30.747000Z'
- status: succeeded
timestamp: '2026-10-19T11:02:31.253000Z'
result:
output: null
+--------------------------+------------------------+----------+------------+--------------------------+
| id | status | task | action | start_timestamp |
+--------------------------+------------------------+----------+------------+--------------------------+
| 6ad5f8c61e3dafdb18e8085b | succeeded (0s elapsed) | announce | core.echo | Mon, 19 Oct 2026 |
| | | | | 11:02:30 UTC |
| 6ad5f8c71e3dafdb18e8086b | succeeded (0s elapsed) | greet | demo.greet | Mon, 19 Oct 2026 |
| | | | | 11:02:31 UTC |
+--------------------------+------------------------+----------+------------+--------------------------+
输出底部的任务表按顺序列出 announce(core.echo)与 greet(demo.greet)两个任务的执行状态与耗时,说明工作流按定义成功串行。
4.3 工作流静态检查
st2 workflow inspect --file /opt/stackstorm/packs.dev/demo/actions/workflows/roll_call.yaml
实测回显:
No errors found in workflow definition.
⚠️
st2 workflow inspect --action demo.roll_call形式要求工作流文件位于 /opt/stackstorm/packs/ 之下(从索引安装的包),对放在 packs.dev 的本地包会报File "/opt/stackstorm/packs/demo/actions/workflows/roll_call.yaml" does not exist on local system.,此时改用--file传绝对路径即可。
4.4 排障一:工作流文件放错目录
把 roll_call.yaml 放到包根的 workflows/ 目录(而非 actions/workflows/),执行时报错:
status: failed
error: [Errno 2] No such file or directory: '/opt/stackstorm/packs.dev/demo/actions/workflows/_tmp_wf.yaml'
原因:meta 的 entry_point 相对 actions/ 目录解析,workflows/xxx.yaml 实际指向 actions/workflows/xxx.yaml。包根下的 workflows/ 目录不会被找到。修复:把工作流文件移入 actions/workflows/ 后重新 st2 pack register demo。
4.5 排障二:省略 input 段
任务里引用了 {{ ctx().name }} 但定义里没有 input: 段时,执行失败:
st2 run demo._tmp_noinput
实测回显(节选关键部分):
status: failed
result:
errors:
- expression: '{{ ctx().name }}'
language: jinja
message: Variable "name" is referenced before assignment.
schema_path: properties.tasks.patternProperties.^\w+$.properties.input
spec_path: tasks.announce.input
type: context
原因:Orquesta 静态分析发现变量 name 在赋值前被引用。修复:在定义里补上 input: 段并列出所有被引用的入参。YAQL 写法(<% ctx().name %>)同样受此约束。
五、规则与定时触发
5.1 定义定时规则
规则把「触发器 → 动作」连接起来。CronTimer 是内置定时触发器,每 2 分钟问候一次:
cat > /opt/stackstorm/packs.dev/demo/rules/timer_greet.yaml <<'EOF'
---
name: timer_greet
pack: demo
description: 每 2 分钟由 CronTimer 定时触发 demo.greet
enabled: true
trigger:
type: core.st2.CronTimer
parameters:
minute: "*/2"
timezone: UTC
criteria: {}
action:
ref: demo.greet
parameters:
name: 定时问候
EOF
5.2 创建规则
st2 rule create /opt/stackstorm/packs.dev/demo/rules/timer_greet.yaml
实测回显:
+---------------+--------------------------------------------------------+
| Property | Value |
+---------------+--------------------------------------------------------+
| id | 6ad5f8e95da20c42c4c374ed |
| name | timer_greet |
| pack | demo |
| description | 每 2 分钟由 CronTimer 定时触发 demo.greet |
| action | { |
| | "ref": "demo.greet", |
| | "parameters": { |
| | "name": "\u5b9a\u65f6\u95ee\u5019" |
| | } |
| | } |
| context | { |
| | "user": "st2admin" |
| | } |
| criteria | |
| enabled | True |
| metadata_file | |
| ref | demo.timer_greet |
| tags | |
| trigger | { |
| | "type": "core.st2.CronTimer", |
| | "parameters": { |
| | "minute": "*/2", |
| | "timezone": "UTC" |
| | }, |
| | "ref": "core.ae7e44d2-093e-4626-8478-85683493dd4b" |
| | } |
| type | { |
| | "ref": "standard", |
| | "parameters": {} |
| | } |
| uid | rule:demo:timer_greet |
+---------------+--------------------------------------------------------+
规则创建即生效(rule create 直接写库,无需再 register)。查看平台侧注册的定时器:
st2 timer list
实测回显:
+--------------------------+----------------------+------+----------------------+--------------------+----------------------+
| id | uid | pack | name | type | parameters |
+--------------------------+----------------------+------+----------------------+--------------------+--------------------+
| 6ad5f8e95da20c42c4c374ec | trigger:core:ae7e44d | core | ae7e44d2-093e-4626- | core.st2.CronTimer | {'minute': '*/2', |
| | 2-093e-4626-8478- | | 8478-85683493dd4b | | 'timezone': 'UTC'} |
| | 85683493dd4b:9d34000 | | | | |
| | 4768c18bcdb48d74ae2a | | | | |
| | b0e32 | | | | |
+--------------------------+----------------------+------+----------------------+--------------------+----------------------+
5.3 CronTimer 参数写法(排障)
CronTimer 的参数是分字段结构,不是整串 cron 表达式。写成 cron: "*/2 * * * *" 会被参数 schema 直接拒绝:
st2 rule create /tmp/bad_timer.yaml # trigger.parameters 写成 cron: "*/2 * * * *"
实测回显(schema 关键部分):
ERROR: 400 Client Error: Bad Request
MESSAGE: Additional properties are not allowed ('cron' was unexpected)
Failed validating 'additionalProperties' in schema:
{'additionalProperties': False,
'properties': {'day': {'anyOf': [{'type': 'string'},
{'type': 'integer'},
{'type': 'null'}],
'maximum': 31,
'minimum': 1},
'day_of_week': {'anyOf': [{'type': 'string'},
{'type': 'integer'},
{'type': 'null'}],
'maximum': 6,
'minimum': 0},
'hour': {'anyOf': [{'type': 'string'},
{'type': 'integer'},
{'type': 'null'}],
'maximum': 23,
'minimum': 0},
'minute': {'anyOf': [{'type': 'string'},
{'type': 'integer'},
{'type': 'null'}],
'maximum': 59,
'minimum': 0},
'month': {'anyOf': [{'type': 'string'},
{'type': 'integer'},
{'type': 'null'}],
'maximum': 12,
'minimum': 1},
'second': {'anyOf': [{'type': 'string'},
{'type': 'integer'},
{'type': 'null'}],
'maximum': 59,
'minimum': 0},
'timezone': {'type': ['string', 'null']},
'week': {'anyOf': [{'type': 'string'},
{'type': 'integer'},
{'type': 'null'}],
'maximum': 53,
'minimum': 1},
'year': {'anyOf': [{'type': 'string'},
{'type': 'integer'},
{'type': 'null'}]}},
'type': 'object'}
On instance:
{'cron': '*/2 * * * *'} for url: http://st2api:9101/rules
从 schema 可见合法字段共九个:second、minute、hour、day、month、week、year、day_of_week、timezone(各字段取值范围见上)。想要「每 2 分钟」,写 minute: "*/2" 即可;每天 03:30 写 hour: 3, minute: 30。 timezone 决定字段按哪个时区解释。
💡 技术拓展:除了 CronTimer,平台还内置 core.st2.IntervalTimer(固定间隔,参数 unit/minutes)与 core.st2.DateTimer(一次性指定日期),三者都由 st2timersengine 服务统一调度,定时器实例可用
st2 timer list/st2 timer get <id>查看。
5.4 观察定时触发
等一个触发周期后查看执行历史(底部为最新记录):
st2 execution list -n 10
实测回显:
+--------------------------+-------------------+--------------+------------------------+----------------------+------------------+
| id | action.ref | context.user | status | start_timestamp | end_timestamp |
+--------------------------+-------------------+--------------+------------------------+----------------------+------------------+
| 6ad5f7406e49959886a55c05 | demo.greet | stanley | succeeded (0s elapsed) | Mon, 19 Oct 2026 | Mon, 19 Oct 2026 |
| | | | | 10:56:00 UTC | 10:56:00 UTC |
| 6ad5f753c9f37d18c953cb42 | demo.greet | st2admin | succeeded (0s elapsed) | Mon, 19 Oct 2026 | Mon, 19 Oct 2026 |
| | | | | 10:56:19 UTC | 10:56:19 UTC |
| 6ad5f7b86e49959886a55c0c | demo.greet | stanley | succeeded (0s elapsed) | Mon, 19 Oct 2026 | Mon, 19 Oct 2026 |
| | | | | 10:58:00 UTC | 10:58:00 UTC |
| 6ad5f8a89fab15a925cf571c | demo.greet | stanley | succeeded (0s elapsed) | Mon, 19 Oct 2026 | Mon, 19 Oct 2026 |
| | | | | 11:02:00 UTC | 11:02:00 UTC |
| 6ad5f8bd5da20c42c4c374e7 | core.local | st2admin | succeeded (0s elapsed) | Mon, 19 Oct 2026 | Mon, 19 Oct 2026 |
| | | | | 11:02:21 UTC | 11:02:21 UTC |
| 6ad5f8c65da20c42c4c374ea | demo.roll_call | st2admin | succeeded (1s elapsed) | Mon, 19 Oct 2026 | Mon, 19 Oct 2026 |
| | | | | 11:02:30 UTC | 11:02:31 UTC |
| 6ad5f9209fab15a925cf572e | demo.greet | stanley | succeeded (0s elapsed) | Mon, 19 Oct 2026 | Mon, 19 Oct 2026 |
| | | | | 11:04:00 UTC | 11:04:00 UTC |
+--------------------------+-------------------+--------------+------------------------+----------------------+------------------+
判读方法:手动执行 context.user 是 st2admin;定时规则触发的执行 context.user 是 stanley(平台系统账号),且时间戳整齐落在整分边界(10:56:00、10:58:00、11:02:00、11:04:00),与 minute: "*/2" 完全吻合。取一条定时执行看详情:
st2 execution get 6ad5f9209fab15a925cf572e
实测回显:
id: 6ad5f9209fab15a925cf572e
action.ref: demo.greet
context.user: stanley
parameters:
name: "定时问候"
status: succeeded (0s elapsed)
start_timestamp: Mon, 19 Oct 2026 11:04:00 UTC
end_timestamp: Mon, 19 Oct 2026 11:04:00 UTC
log:
- status: requested
timestamp: '2026-10-19T11:04:00.039000Z'
- status: scheduled
timestamp: '2026-10-19T11:04:00.124000Z'
- status: running
timestamp: '2026-10-19T11:04:00.142000Z'
- status: succeeded
timestamp: '2026-10-19T11:04:00.192000Z'
result:
failed: false
return_code: 0
stderr: ''
stdout: "Hello, 定时问候! Welcome to StackStorm."
succeeded: true
六、Datastore 数据存储
Datastore 是平台级键值存储,供动作、规则、工作流引用公共配置。写入与读取:
st2 key set demo.welcome 你好数据存储
实测回显:
+------------------+--------------+
| Property | Value |
+------------------+--------------+
| name | demo.welcome |
| value | 你好数据存储 |
| scope | st2kv.system |
| expire_timestamp | |
+------------------+--------------+
st2 key get demo.welcome
实测回显:
+------------------+--------------+
| Property | Value |
+------------------+--------------+
| name | demo.welcome |
| value | 你好数据存储 |
| secret | False |
| encrypted | False |
| scope | st2kv.system |
| expire_timestamp | |
+------------------+--------------+
按前缀过滤列表(演示两个键并存):
st2 key list --prefix demo.
实测回显:
+-------------------+-----------------------+--------+-----------+--------------+------+------------------+
| name | value | secret | encrypted | scope | user | expire_timestamp |
+-------------------+-----------------------+--------+-----------+--------------+------+------------------+
| demo.cipher | 3030303030F76EDC699E0 | True | True | st2kv.system | | |
| | 21C638A34FA6EB4C29624 | | | | | |
| | DDDC08EF274D3F9F9E355 | | | | | |
| | 171B675F85E9D4E8F9115 | | | | | |
| | 536B44D516E40A9EF5C23 | | | | | |
| | A70F65F4F | | | | | |
| demo.welcome | 你好数据存储 | False | False | st2kv.system | | |
+-------------------+-----------------------+--------+-----------+--------------+------+------------------+
敏感值加 --encrypt 落库即密文(依赖部署时初始化的数据存储加密密钥):
st2 key set --encrypt demo.cipher s3cr3t-999
st2 key get demo.cipher
实测回显(value 为密文形态,secret/encrypted 标记为 True):
+------------------+--------------------------------------------------------------+
| Property | Value |
+------------------+--------------------------------------------------------------+
| name | demo.cipher |
| value | 3030303030F76EDC699E021C638A34FA6EB4C29624DDDC08EF274D3F9F9E |
| | 355171B675F85E9D4E8F9115536B44D516E40A9EF5C23A70F65F4F |
| secret | True |
| encrypted | True |
| scope | st2kv.system |
| expire_timestamp | |
+------------------+--------------------------------------------------------------+
💡 技术拓展:规则/工作流/动作里用
{{st2kv.system.demo_welcome}}直接引用系统域的键;带--encrypt的密钥在动作执行时才解密,配合secret: True可避免明文出现在 Web UI。用户域键(--scope user)按用户隔离,适合存个人偏好配置。
删除演示键收尾:
st2 key delete demo.welcome
st2 key delete demo.cipher
实测回显:
Resource with id "demo.welcome" has been successfully deleted.
Resource with id "demo.cipher" has been successfully deleted.
七、常见问题
Q1:st2 pack register 支持 --pack 选项吗?
不支持,3.9.0 里 st2 pack register --pack demo 直接报 st2: error: unrecognized arguments: --pack。用位置参数:st2 pack register demo。
Q2:st2 key list 支持 -p 按前缀过滤吗?
不支持,st2 key list -p demo 报 st2: error: unrecognized arguments: -p demo。正确选项是 --prefix:st2 key list --prefix demo.。
Q3:怎么判断一条 demo.greet 执行是定时触发还是人工触发?
看 st2 execution list 的 context.user 列:stanley 是平台定时触发(或规则链路触发),st2admin 等真实账号是人工 CLI/API 触发。
Q4:规则文件改动后要重新注册吗?
用 st2 rule create <文件> 创建的规则已直接入库,改文件后需 st2 rule update 或删了重建;走 st2 pack register demo 重新同步的是磁盘文件与库的差异。验证当前生效配置用 st2 rule get demo.timer_greet。
Q5:定时任务没有触发?
按链路排查:st2 rule get demo.timer_greet 确认 enabled: True 且 trigger.type 为 core.st2.CronTimer → st2 timer list 确认定时器已注册(rule create 后即时生效)→ st2 execution list 看是否有 stanley 的记录。若规则创建于两次整分之间,最长要等到下一个触发边界。
八、参考链接
- 官方 Quick Start:https://docs.stackstorm.com/quickstart.html
- Actions:https://docs.stackstorm.com/actions.html
- Rules:https://docs.stackstorm.com/rules.html
- Workflows(Orquesta):https://docs.stackstorm.com/orquesta.html
- Timers:https://docs.stackstorm.com/timers.html
- Datastore:https://docs.stackstorm.com/datastore.html
- Packs:https://docs.stackstorm.com/packs.html
- 前置部署篇:《StackStorm Docker Compose 部署指南》
- 命令全量参考:《StackStorm st2 CLI 命令与工具详解》
- 版本与选型背景:《StackStorm 3.9.0 介绍与选型指南》