Files
proxmox-task/README.md

88 lines
2.0 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.
# Proxmox VM 任务控制器
一个Python脚本用于自动化控制Proxmox虚拟机执行任务。小主机平时待机监听接受命令后启动VM执行任务完成后关闭VM。
## 功能特点
- **待机监听**:持续监控命令目录,平时保持低功耗状态
- **自动启停**:按需启动/关闭Proxmox虚拟机
- **任务执行**通过SSH在VM内执行命令
- **状态汇报**:实时记录任务执行状态和结果
- **错误处理**:完善的错误处理和超时机制
## 快速开始
### 环境要求
- Python 3.8+
- Proxmox VE 6.x+
- SSH访问权限
### 安装配置
1. 克隆仓库
```bash
git clone http://124.223.26.33:3000/xiaji/proxmox-task.git
cd proxmox-task
```
2. 设置环境变量
```bash
export PROXMOX_HOST="your-proxmox-host"
export PROXMOX_USER="root@pam"
export PROXMOX_TOKEN="your-api-token"
export VM_ID="100"
export SSH_USER="ubuntu"
export SSH_KEY_PATH="/path/to/ssh/key"
```
3. 运行脚本
```bash
python3 proxmox_task_controller.py
```
### 使用示例
1. 创建任务命令文件 `/var/task-commands/task-001.json`:
```json
{
"task_id": "task-001",
"command": "cd /opt/myapp && python3 run_task.py"
}
```
2. 查看状态文件 `/var/task-status/task-001.json`:
```json
{
"task_id": "task-001",
"status": "success",
"message": "任务执行成功",
"output": "Task completed successfully...",
"timestamp": 1234567890
}
```
## 配置选项
| 变量名 | 说明 | 默认值 |
|--------|------|--------|
| PROXMOX_HOST | Proxmox主机地址 | localhost |
| PROXMOX_USER | API用户 | root@pam |
| PROXMOX_TOKEN | API Token | (必需) |
| VM_ID | 虚拟机ID | 100 |
| SSH_USER | SSH用户名 | ubuntu |
| SSH_KEY_PATH | SSH私钥路径 | ~/.ssh/id_rsa |
| COMMAND_DIR | 命令目录 | /var/task-commands |
| STATUS_DIR | 状态目录 | /var/task-status |
| CHECK_INTERVAL | 检查间隔(秒) | 10 |
## 安全建议
- 使用Proxmox API Token而非密码
- 限制API Token权限
- 使用SSH密钥认证
- 在受信任网络中运行
## 许可证
MIT License