175 lines
5.2 KiB
Markdown
175 lines
5.2 KiB
Markdown
---
|
||
description: Delete a Gitea runner configuration (interactive)
|
||
agent: general
|
||
subtask: true
|
||
---
|
||
|
||
Delete Gitea runner configuration with interactive selection. This command requires multiple user interactions.
|
||
|
||
**Important:** This is an interactive command. Wait for user input at each step before proceeding.
|
||
|
||
## 工作目录
|
||
|
||
**macOS / Linux:**
|
||
```
|
||
~/.config/gitea/
|
||
```
|
||
|
||
**Windows:**
|
||
```
|
||
%USERPROFILE%\.config\gitea\
|
||
```
|
||
|
||
所有 Runner 配置、进程管理都基于此目录。
|
||
|
||
Please perform the following steps:
|
||
|
||
## Step 1: Load Configuration and Fetch Runners
|
||
|
||
1. **Load Gitea configuration:**
|
||
|
||
**macOS / Linux:**
|
||
```bash
|
||
source ~/.config/gitea/config.env
|
||
```
|
||
|
||
**Windows PowerShell:**
|
||
```powershell
|
||
Get-Content "$env:USERPROFILE\.config\gitea\config.env" | ForEach-Object {
|
||
if ($_ -match '^([^=]+)=(.*)$') {
|
||
[Environment]::SetEnvironmentVariable($matches[1], $matches[2], 'Process')
|
||
}
|
||
}
|
||
```
|
||
|
||
- Validate `GITEA_URL` and `GITEA_TOKEN` exist
|
||
|
||
2. **Fetch global runners from Gitea server:**
|
||
- API: `GET ${GITEA_URL}/api/v1/admin/actions/runners`
|
||
- Requires admin permissions
|
||
- If fails: show error and check token permissions
|
||
|
||
3. **Display runners list in Chinese:**
|
||
```
|
||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||
Gitea 全局 Runners (共 N 个)
|
||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||
|
||
1. [runner-name] [ID: XX] 🟢 在线/🔴 离线
|
||
2. [runner-name] [ID: XX] 🟢 在线/🔴 离线
|
||
...
|
||
|
||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||
选择要删除的 Runner
|
||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||
|
||
输入序号: 删除单个 runner
|
||
输入 'all': 删除所有 runners
|
||
输入 'q' 或 'quit': 取消
|
||
```
|
||
|
||
4. **Wait for user selection** → Do NOT proceed until user responds
|
||
|
||
## Step 2: Process User Selection
|
||
|
||
Based on user input:
|
||
- If `q` or `quit`: Cancel and exit
|
||
- If `all`: Prepare to delete all runners
|
||
- If number: Validate and prepare to delete that runner
|
||
|
||
## Step 3: Display Warning and Wait for Confirmation
|
||
|
||
Display deletion warning in Chinese:
|
||
```
|
||
⚠️ 警告: 此操作将执行以下操作:
|
||
- 从 Gitea 服务器注销 runner
|
||
- 停止本地运行的 runner 进程
|
||
- 删除 runner 配置文件
|
||
- 删除 cache 和 workspace 目录
|
||
- 删除所有相关数据
|
||
|
||
将删除以下 runners:
|
||
- [list of runners to be deleted]
|
||
|
||
确认删除? 输入 'yes' 继续:
|
||
```
|
||
|
||
**Wait for user confirmation** → Do NOT proceed until user types 'yes'
|
||
|
||
## Step 4: Execute Deletion
|
||
|
||
If user confirmed with 'yes', for each selected runner:
|
||
|
||
### 4.1 Unregister from Gitea Server
|
||
```bash
|
||
DELETE ${GITEA_URL}/api/v1/admin/actions/runners/${runner_id}
|
||
```
|
||
- Expected: HTTP 204
|
||
- Show: "✓ 已从服务器注销" or "⚠️ 注销失败"
|
||
|
||
### 4.2 Stop Local Process
|
||
1. Find local runner directory by matching ID in `.runner` file
|
||
2. Check if process is running: `pgrep -f "act_runner daemon --config ..."`
|
||
3. If running:
|
||
- Check if runner is busy (executing jobs) via API
|
||
- **If busy, wait for user choice:**
|
||
```
|
||
⚠️ 警告: Runner 正在执行 job!
|
||
选项:
|
||
1. 等待 job 完成后再停止(推荐)
|
||
2. 强制立即停止
|
||
```
|
||
- **Wait for user input** → Proceed based on choice
|
||
- If waiting: Poll status every 10 seconds, max 5 minutes
|
||
- Stop process: `kill $pid` (graceful), then `kill -9 $pid` if needed (force)
|
||
|
||
### 4.3 Delete Local Directory
|
||
|
||
**macOS / Linux:**
|
||
```bash
|
||
rm -rf ~/.config/gitea/runners/[runner_name]
|
||
```
|
||
|
||
**Windows PowerShell:**
|
||
```powershell
|
||
Remove-Item -Path "$env:USERPROFILE\.config\gitea\runners\[runner_name]" -Recurse -Force
|
||
```
|
||
|
||
## Step 5: Display Result
|
||
|
||
Show completion summary in Chinese:
|
||
```
|
||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||
删除完成
|
||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||
|
||
成功: N 个
|
||
失败: M 个 (if any)
|
||
|
||
管理命令:
|
||
查看剩余 runners: /gitea-list-runners
|
||
创建新 runner: /gitea-create-runner
|
||
```
|
||
|
||
---
|
||
|
||
## Key Points
|
||
|
||
**Interactive checkpoints (wait for user input):**
|
||
1. Step 1: After displaying runners list → Wait for selection
|
||
2. Step 3: After displaying warning → Wait for confirmation ('yes')
|
||
3. Step 4.2: If runner is busy → Wait for stop choice (1 or 2)
|
||
|
||
**Safety features:**
|
||
- Double confirmation required
|
||
- Busy status detection
|
||
- Graceful stop before force kill
|
||
- Three-step deletion process
|
||
- Clear status reporting
|
||
|
||
**Technical notes:**
|
||
- Requires `jq` for JSON parsing
|
||
- Requires admin token for global runners
|
||
- Uses temporary file `/tmp/gitea_runners.txt` for data passing
|
||
- Cleanup temp file after completion
|