Files
opencode/command/gitea-list-runners.md
Voson 5a05d5ab53 chore: 重构 OpenCode 命令和技能文档体系
- 新增:统一的 git 命令文档(add/commit/push/pull 等)
- 新增:整合的 Gitea 技能文档(API、运行器、工作流等)
- 新增:工作流模板(Android、Go、Node.js 等)
- 移除:已弃用的旧命令脚本和发布脚本
- 改进:.gitignore 添加敏感文件保护规则
- 改进:AGENTS.md 完善了开发规范和示例

此次重组统一了命令和技能的文档结构,便于后续维护和扩展。
2026-01-13 00:27:21 +08:00

203 lines
5.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
description: List all configured Gitea runners and their status
---
# gitea-list-runners
列出所有已配置的 Gitea Runners 及其运行状态。
## Features
- 显示所有已配置的 runner
- 检查 runner 运行状态(运行中/已停止)
- 显示 runner 配置信息labels、capacity 等)
- 显示 runner ID 和名称
- 提供启动命令
## Steps
### 1. Check Configuration
```bash
config_dir="$HOME/.config/gitea"
runners_dir="$config_dir/runners"
if [ ! -d "$runners_dir" ]; then
echo "❌ 未找到 runner 目录"
echo "请先创建 runner"
exit 1
fi
```
### 2. List All Runners
```bash
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Gitea Runners"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
runners=$(ls -1 "$runners_dir" 2>/dev/null)
if [ -z "$runners" ]; then
echo "未配置任何 runner"
echo ""
echo "创建 runner"
echo " /gitea-create-runner"
exit 0
fi
runner_count=$(echo "$runners" | wc -l | tr -d ' ')
echo "总计: $runner_count 个 runner"
echo ""
```
### 3. Display Each Runner's Status
```bash
for runner in $runners; do
runner_dir="$runners_dir/$runner"
config_file="$runner_dir/config.yaml"
echo "[$runner]"
# Check if config exists
if [ ! -f "$config_file" ]; then
echo " ⚠️ 配置文件缺失"
echo ""
continue
fi
# Check if runner process is running
if pgrep -f "act_runner daemon --config $config_file" > /dev/null; then
status="🟢 运行中"
pid=$(pgrep -f "act_runner daemon --config $config_file")
else
status="🔴 已停止"
pid="-"
fi
echo " 状态: $status"
echo " PID: $pid"
# Display configuration info
if command -v yq &> /dev/null; then
# Use yq if available
capacity=$(yq eval '.runner.capacity' "$config_file" 2>/dev/null)
timeout=$(yq eval '.runner.timeout' "$config_file" 2>/dev/null)
else
# Fallback to grep
capacity=$(grep "capacity:" "$config_file" | awk '{print $2}')
timeout=$(grep "timeout:" "$config_file" | awk '{print $2}')
fi
echo " 容量: ${capacity:-N/A}"
echo " 超时: ${timeout:-N/A}"
# Display labels
labels=$(grep -A 10 "labels:" "$config_file" | grep "^ -" | sed 's/^ - "//' | sed 's/"$//' | tr '\n' ',' | sed 's/,$//')
if [ -n "$labels" ]; then
echo " Labels: $labels"
fi
# Display runner info from .runner file
if [ -f "$runner_dir/.runner" ]; then
if command -v jq &> /dev/null; then
runner_id=$(jq -r '.id // "N/A"' "$runner_dir/.runner" 2>/dev/null)
runner_name=$(jq -r '.name // "N/A"' "$runner_dir/.runner" 2>/dev/null)
echo " ID: $runner_id"
echo " 名称: $runner_name"
fi
fi
echo " 路径: $runner_dir"
# Display start command
echo ""
echo " 启动命令:"
echo " act_runner daemon --config $config_file"
# Display background start command
if [ "$status" = "🔴 已停止" ]; then
echo ""
echo " 后台启动:"
echo " nohup act_runner daemon --config $config_file > $runner_dir/runner.log 2>&1 &"
fi
echo ""
done
```
### 4. Display Summary Commands
```bash
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "管理命令"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo " 查看配置: /gitea-config"
echo " 创建 runner: /gitea-create-runner"
echo " 删除 runner: /gitea-delete-runner"
echo ""
```
## Output Example
```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Gitea Runners
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
总计: 2 个 runner
[runner-macbook-pro]
状态: 🟢 运行中
PID: 12345
容量: 2
超时: 3h
Labels: self-hosted:host,macOS:host,ARM64:host,darwin-arm64:host
ID: 42
名称: runner-macbook-pro
路径: /Users/voson/.config/gitea/runners/runner-macbook-pro
启动命令:
act_runner daemon --config /Users/voson/.config/gitea/runners/runner-macbook-pro/config.yaml
[runner-mac-mini]
状态: 🔴 已停止
PID: -
容量: 2
超时: 3h
Labels: self-hosted:host,macOS:host,ARM64:host,darwin-arm64:host
ID: 43
名称: runner-mac-mini
路径: /Users/voson/.config/gitea/runners/runner-mac-mini
启动命令:
act_runner daemon --config /Users/voson/.config/gitea/runners/runner-mac-mini/config.yaml
后台启动:
nohup act_runner daemon --config /Users/voson/.config/gitea/runners/runner-mac-mini/config.yaml > /Users/voson/.config/gitea/runners/runner-mac-mini/runner.log 2>&1 &
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
管理命令
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
查看配置: /gitea-config
创建 runner: /gitea-create-runner
删除 runner: /gitea-delete-runner
```
## Notes
- 使用 `pgrep` 检查进程状态
- 优先使用 `yq` 解析 YAMLfallback 到 `grep`
- 优先使用 `jq` 解析 JSON `.runner` 文件
- Runner 状态图标:
- 🟢 运行中
- 🔴 已停止
- ⚠️ 配置异常
- 显示启动命令方便用户复制执行
- 对已停止的 runner额外显示后台启动命令