Linux Patcher
Automate Linux server patching and Docker container updates across multiple hosts via SSH.
⚠️ Important Disclaimers
Distribution Support Status
Fully Tested:
- - ✅ Ubuntu - Tested end-to-end with real infrastructure
Supported but Untested:
- - ⚠️ Debian GNU/Linux - Commands based on official documentation
- ⚠️ Amazon Linux - Supports both AL2 (yum) and AL2023 (dnf)
- ⚠️ RHEL (Red Hat Enterprise Linux) - Supports RHEL 7 (yum) and 8+ (dnf)
- ⚠️ AlmaLinux - RHEL-compatible, uses dnf
- ⚠️ Rocky Linux - RHEL-compatible, uses dnf
- ⚠️ CentOS - Supports CentOS 7 (yum) and 8+ (dnf)
- ⚠️ SUSE/OpenSUSE - Uses zypper package manager
Testing Recommendation:
Always test untested distributions in a non-production environment first. The script will warn you when running on untested distributions.
Security Notice
This skill requires:
- - Passwordless sudo access - Configured with restricted permissions
- SSH key authentication - No passwords stored or transmitted
- PatchMon credentials - Stored securely in user's home directory
Read SETUP.md for complete security configuration guide.
Quick Start
Automated (Recommended)
Patch all hosts from PatchMon (automatic detection):
CODEBLOCK0
Skip Docker updates (packages only):
CODEBLOCK1
Preview changes (dry-run):
CODEBLOCK2
Manual (Alternative)
Single host - packages only:
CODEBLOCK3
Single host - full update:
CODEBLOCK4
Multiple hosts from config:
CODEBLOCK5
Features
- - PatchMon integration - Automatically detects hosts needing updates
- Smart Docker detection - Auto-detects Docker and Compose paths
- Selective updates - Skip Docker updates with
--skip-docker flag - Passwordless sudo required - Configure with
visudo or /etc/sudoers.d/ files - SSH key authentication - No password prompts
- Parallel execution - Update multiple hosts simultaneously
- Dry-run mode - Preview changes without applying
- Manual override - Run updates on specific hosts without PatchMon
Configuration
Option 1: Automatic via PatchMon (Recommended)
Configure PatchMon credentials for automatic host detection:
CODEBLOCK6
Set your credentials:
CODEBLOCK7
Then simply run:
CODEBLOCK8
The script will:
- 1. Query PatchMon for hosts needing updates
- Auto-detect Docker on each host
- Apply appropriate updates (host-only or full)
Option 2: Single Host (Quick Manual)
Run scripts directly with command-line arguments (no config file needed).
Option 3: Multiple Hosts (Manual Config)
Create a config file based on scripts/patch-hosts-config.example.sh:
CODEBLOCK9
Example config:
CODEBLOCK10
Then run:
CODEBLOCK11
Prerequisites
Required on Control Machine (where OpenClaw runs)
- - [ ] OpenClaw installed and running
- [ ] SSH client installed (
ssh command available) - [ ] Bash 4.0 or higher
- [ ] curl installed (for PatchMon API)
- [ ] jq installed (for JSON parsing)
- [ ] PatchMon installed (required to check which hosts need updating)
- Does NOT need to be on the OpenClaw host
- Can be installed on any server accessible via HTTPS
- Download: https://github.com/PatchMon/PatchMon
Install missing tools:
CODEBLOCK12
Required on Target Hosts
- - [ ] SSH server running and accessible
- [ ] SSH key authentication configured (passwordless login)
- [ ] Passwordless sudo configured for patching commands (see SETUP.md)
- [ ] Docker installed (optional, only for full updates)
- [ ] Docker Compose installed (optional, only for full updates)
- [ ] PatchMon agent installed and reporting (optional but recommended)
PatchMon Setup (Required for Automatic Mode)
PatchMon is required to automatically detect which hosts need patching.
Important: PatchMon does NOT need to be installed on the same server as OpenClaw. Install PatchMon on a separate server (can be any server on your network), and OpenClaw will query it via API.
Download PatchMon:
- - GitHub: https://github.com/PatchMon/PatchMon
- Documentation: https://docs.patchmon.net
What you need:
- - [ ] PatchMon server installed on ANY accessible server (not necessarily the OpenClaw host)
- [ ] PatchMon agents installed on all target hosts you want to patch
- [ ] PatchMon API credentials (username/password)
- [ ] Network connectivity from OpenClaw host to PatchMon server (HTTPS)
Architecture:
CODEBLOCK13
Quick Start:
- 1. Install PatchMon server on a separate server (see GitHub repo)
- Install PatchMon agents on all hosts you want to patch
- Configure OpenClaw to access PatchMon API:
CODEBLOCK14
Detailed setup:
See references/patchmon-setup.md for complete installation guide.
Can I use this skill without PatchMon?
Yes! You can use manual mode to target specific hosts without PatchMon. However, automatic detection of hosts needing updates requires PatchMon.
On Target Hosts
Required:
- - SSH server running
- Passwordless sudo for the SSH user (for
apt and docker commands) - PatchMon agent installed and reporting (for automatic mode)
For full updates:
- - Docker and Docker Compose installed
- Docker Compose files exist at specified paths
Configure Passwordless Sudo
On each target host, create /etc/sudoers.d/patches:
CODEBLOCK15
Replace username with your SSH user. Test with sudo -l to verify.
Update Modes
Host-Only Updates
Updates system packages only:
- - Run
apt update && apt upgrade (or yum update on RHEL) - Remove unused packages (
apt autoremove) - Does NOT touch Docker containers
When to use:
- - Hosts without Docker
- Security patches only
- Minimal downtime required
Full Updates
Complete update cycle:
- - Update system packages
- Clean Docker cache (
docker system prune) - Pull latest Docker images
- Recreate containers with new images
- Causes brief service interruption
When to use:
- - Docker-based infrastructure
- Regular maintenance windows
- Application updates available
Workflow
Automatic Workflow (patch-auto.sh)
- 1. Query PatchMon - Fetch hosts needing updates via API
- For each host:
- SSH into host
- Check if Docker is installed
- Auto-detect Docker Compose path (if not specified)
- Apply host-only OR full update based on Docker detection
- 3. Report results - Summary of successful/failed updates
Host-Only Update Process
- 1. SSH into target host
- Run INLINECODE16
- Run INLINECODE17
- Run INLINECODE18
- Report results
Full Update Process
- 1. SSH into target host
- Run INLINECODE19
- Navigate to Docker Compose directory
- Run
sudo docker system prune -af (cleanup) - Pull all Docker images listed in compose file
- Run INLINECODE21
- Run
sudo docker compose up -d (recreate containers) - Report results
Docker Detection Logic
When using automatic mode:
- - Docker installed + compose file found → Full update
- Docker installed + no compose file → Host-only update
- Docker not installed → Host-only update
- --skip-docker flag set → Host-only update (ignores Docker)
Docker Path Auto-Detection
When Docker path is not specified, the script checks these locations:
- 1. INLINECODE23
- INLINECODE24
- INLINECODE25
- INLINECODE26
- Current directory
Override auto-detection:
CODEBLOCK16
Examples
Example 1: Automatic update via PatchMon (recommended)
CODEBLOCK17
Example 2: Automatic with dry-run
CODEBLOCK18
Example 3: Skip Docker updates
CODEBLOCK19
Example 4: Manual single host, packages only
CODEBLOCK20
Example 5: Manual single host, full update with custom Docker path
CODEBLOCK21
Example 6: Manual multiple hosts from config
CODEBLOCK22
Example 7: Via OpenClaw chat
Simply ask OpenClaw:
- - "Update my servers"
- "Patch all hosts that need updates"
- "Update packages only, skip Docker"
OpenClaw will use the automatic mode and report results.
Troubleshooting
PatchMon Integration Issues
"PatchMon credentials not found"
- - Create credentials file: INLINECODE27
- Edit with your PatchMon URL and credentials
- Or set
PATCHMON_CONFIG environment variable to custom location
"Failed to authenticate with PatchMon"
- - Verify PatchMon URL is correct (without trailing slash)
- Check username and password
- Ensure PatchMon server is accessible: INLINECODE29
- Check firewall rules
"No hosts need updates" but PatchMon shows updates available
- - Verify PatchMon agents are running on target hosts: INLINECODE30
- Check agent reporting intervals: INLINECODE31
- Force agent update: INLINECODE32
System Update Issues
"Permission denied" on apt/docker commands
- - Configure passwordless sudo (see Prerequisites section)
- Test with: INLINECODE33
"Connection refused"
- - Verify SSH access: INLINECODE34
- Check SSH keys are configured
- Verify hostname resolution
Docker Compose not found
- - Specify full path: INLINECODE35
- Or install Docker Compose on target host
- Auto-detection searches:
/home/user/Docker, /opt/docker, INLINECODE38
Containers fail to start after update
- - Check logs: INLINECODE39
- Manually inspect: INLINECODE40
- Rollback if needed: INLINECODE41
PatchMon Integration (Optional)
For dashboard monitoring and scheduled patching, see references/patchmon-setup.md.
PatchMon provides:
- - Web dashboard for update status
- Per-host package tracking
- Security update highlighting
- Update history
Security Considerations
- - Passwordless sudo is required for automation
- Limit to specific commands (
apt,
docker only)
- Use
/etc/sudoers.d/ files (easier to manage)
- - SSH keys should be protected
- Use passphrase-protected keys when possible
- Restrict key permissions:
chmod 600 ~/.ssh/id_rsa
- - Review updates before applying in production
- Use dry-run mode first
- Test on staging environment
- - Schedule updates during maintenance windows
- Use OpenClaw cron jobs for automation
- Coordinate with team for Docker updates (brief downtime)
Best Practices
- 1. Test first - Run dry-run mode before applying changes
- Stagger updates - Don't update all hosts simultaneously (avoid full outage)
- Monitor logs - Check output for errors after updates
- Backup configs - Keep Docker Compose files in version control
- Schedule wisely - Update during low-traffic windows
- Document paths - Maintain config files for infrastructure
- Reboot when needed - Kernel updates require reboots (not automated)
Reboot Management
The scripts do NOT automatically reboot hosts. After updates:
- 1. Check if reboot required: INLINECODE47
- Schedule manual reboots during maintenance windows
- Use PatchMon dashboard to track reboot requirements
Integration with OpenClaw
Run Updates on Schedule
Create a cron job for automatic nightly patching:
CODEBLOCK23
Or packages-only mode:
CODEBLOCK24
Run Updates via Chat
Simply ask OpenClaw natural language commands:
Full updates (packages + Docker containers):
- - "Update my servers" ← Includes Docker by default
- "Patch all hosts that need updates"
- "Update all my infrastructure"
Packages only (exclude Docker):
- - "Update my servers, excluding docker"
- "Update packages only, skip Docker"
- "Patch hosts without touching containers"
Query status:
- - "What servers need patching?"
- "Show me hosts that need updates"
What happens automatically:
When you say "Update my servers":
- 1. ✅ Queries PatchMon for hosts needing updates
- ✅ Detects Docker on each host
- ✅ Updates system packages
- ✅ Pulls Docker images and recreates containers (if Docker detected)
- ✅ Reports results with success/failure count
When you say "Update my servers, excluding docker":
- 1. ✅ Queries PatchMon for hosts needing updates
- ✅ Updates system packages only
- ❌ Skips all Docker operations (containers keep running)
- ✅ Reports results
Important: Docker updates are included by default for maximum automation. Use "excluding docker" to skip container updates.
Manual Override (Specific Hosts)
Target individual hosts without querying PatchMon:
- - "Update webserver.example.com"
- "Patch database.example.com packages only"
- "Update app.example.com with Docker"
OpenClaw will use the manual scripts for targeted updates.
Documentation Files
This skill includes comprehensive documentation:
- - SKILL.md (this file) - Overview and usage guide
- SETUP.md - Complete setup instructions with security best practices
- WORKFLOWS.md - Visual workflow diagrams for all modes
- references/patchmon-setup.md - PatchMon installation and integration
First time setup? Read SETUP.md first - it provides step-by-step instructions for secure configuration.
Want to understand the flow? Check WORKFLOWS.md for visual diagrams of how the skill operates.
Supported Linux Distributions
| Distribution | Package Manager | Tested | Status |
|---|
| Ubuntu | apt | ✅ Yes | Fully supported |
| Debian |
apt | ⚠️ No | Supported (untested) |
| Amazon Linux 2 | yum | ⚠️ No | Supported (untested) |
| Amazon Linux 2023 | dnf | ⚠️ No | Supported (untested) |
| RHEL 7 | yum | ⚠️ No | Supported (untested) |
| RHEL 8+ | dnf | ⚠️ No | Supported (untested) |
| AlmaLinux | dnf | ⚠️ No | Supported (untested) |
| Rocky Linux | dnf | ⚠️ No | Supported (untested) |
| CentOS 7 | yum | ⚠️ No | Supported (untested) |
| CentOS 8+ | dnf | ⚠️ No | Supported (untested) |
| SUSE/OpenSUSE | zypper | ⚠️ No | Supported (untested) |
The skill automatically detects the distribution and selects the appropriate package manager.
Linux Patcher
通过SSH自动完成多台主机的Linux服务器补丁和Docker容器更新。
⚠️ 重要声明
发行版支持状态
已全面测试:
- - ✅ Ubuntu - 已使用真实基础设施进行端到端测试
支持但未经测试:
- - ⚠️ Debian GNU/Linux - 命令基于官方文档
- ⚠️ Amazon Linux - 支持AL2(yum)和AL2023(dnf)
- ⚠️ RHEL(红帽企业Linux) - 支持RHEL 7(yum)和8+(dnf)
- ⚠️ AlmaLinux - 兼容RHEL,使用dnf
- ⚠️ Rocky Linux - 兼容RHEL,使用dnf
- ⚠️ CentOS - 支持CentOS 7(yum)和8+(dnf)
- ⚠️ SUSE/OpenSUSE - 使用zypper包管理器
测试建议:
始终先在非生产环境中测试未经测试的发行版。在未经测试的发行版上运行时,脚本会发出警告。
安全须知
此技能需要:
- - 免密码sudo访问 - 配置有限权限
- SSH密钥认证 - 不存储或传输密码
- PatchMon凭据 - 安全存储在用户主目录中
阅读SETUP.md获取完整的安全配置指南。
快速开始
自动模式(推荐)
从PatchMon修补所有主机(自动检测):
bash
scripts/patch-auto.sh
跳过Docker更新(仅更新软件包):
bash
scripts/patch-auto.sh --skip-docker
预览更改(试运行):
bash
scripts/patch-auto.sh --dry-run
手动模式(备选)
单台主机 - 仅更新软件包:
bash
scripts/patch-host-only.sh user@hostname
单台主机 - 完整更新:
bash
scripts/patch-host-full.sh user@hostname /path/to/docker/compose
从配置文件更新多台主机:
bash
scripts/patch-multiple.sh config-file.conf
功能特性
- - PatchMon集成 - 自动检测需要更新的主机
- 智能Docker检测 - 自动检测Docker和Compose路径
- 选择性更新 - 使用--skip-docker标志跳过Docker更新
- 需要免密码sudo - 使用visudo或/etc/sudoers.d/文件配置
- SSH密钥认证 - 无需密码提示
- 并行执行 - 同时更新多台主机
- 试运行模式 - 预览更改而不实际应用
- 手动覆盖 - 无需PatchMon即可在特定主机上运行更新
配置
选项1:通过PatchMon自动配置(推荐)
配置PatchMon凭据以实现自动主机检测:
bash
cp scripts/patchmon-credentials.example.conf ~/.patchmon-credentials.conf
nano ~/.patchmon-credentials.conf
设置您的凭据:
bash
PATCHMON_URL=https://patchmon.example.com
PATCHMON_USERNAME=your-username
PATCHMON_PASSWORD=your-password
然后直接运行:
bash
scripts/patch-auto.sh
脚本将:
- 1. 查询PatchMon获取需要更新的主机
- 自动检测每台主机上的Docker
- 应用适当的更新(仅主机或完整更新)
选项2:单台主机(快速手动)
直接使用命令行参数运行脚本(无需配置文件)。
选项3:多台主机(手动配置)
基于scripts/patch-hosts-config.example.sh创建配置文件:
bash
cp scripts/patch-hosts-config.example.sh my-servers.conf
nano my-servers.conf
示例配置:
bash
主机定义:主机名,SSH用户,Docker路径
HOSTS=(
webserver.example.com,ubuntu,/opt/docker
database.example.com,root,/home/admin/compose
monitor.example.com,docker,/srv/monitoring
)
更新模式:host-only或full
UPDATE_MODE=full
试运行模式(设置为false以应用更改)
DRY_RUN=true
然后运行:
bash
scripts/patch-multiple.sh my-servers.conf
前提条件
控制机要求(运行OpenClaw的机器)
- - [ ] OpenClaw 已安装并运行
- [ ] SSH客户端 已安装(ssh命令可用)
- [ ] Bash 4.0或更高版本
- [ ] curl 已安装(用于PatchMon API)
- [ ] jq 已安装(用于JSON解析)
- [ ] PatchMon 已安装(用于检查哪些主机需要更新)
- 不需要安装在OpenClaw主机上
- 可以安装在任何可通过HTTPS访问的服务器上
- 下载地址:https://github.com/PatchMon/PatchMon
安装缺失工具:
bash
Ubuntu/Debian
sudo apt install curl jq
RHEL/CentOS/Rocky/Alma
sudo dnf install curl jq
macOS
brew install curl jq
目标主机要求
- - [ ] SSH服务器 正在运行且可访问
- [ ] SSH密钥认证 已配置(免密码登录)
- [ ] 免密码sudo 已为修补命令配置(参见SETUP.md)
- [ ] Docker 已安装(可选,仅用于完整更新)
- [ ] Docker Compose 已安装(可选,仅用于完整更新)
- [ ] PatchMon代理 已安装并上报(可选但推荐)
PatchMon设置(自动模式必需)
PatchMon用于自动检测哪些主机需要修补。
重要提示: PatchMon不需要安装在OpenClaw所在的同一台服务器上。将PatchMon安装在一台单独的服务器上(可以是网络中的任何服务器),OpenClaw将通过API查询它。
下载PatchMon:
- - GitHub: https://github.com/PatchMon/PatchMon
- 文档: https://docs.patchmon.net
您需要:
- - [ ] PatchMon服务器安装在任意可访问的服务器上(不一定是OpenClaw主机)
- [ ] PatchMon代理安装在所有需要修补的目标主机上
- [ ] PatchMon API凭据(用户名/密码)
- [ ] 从OpenClaw主机到PatchMon服务器的网络连接(HTTPS)
架构:
┌─────────────────┐ HTTPS API ┌─────────────────┐
│ OpenClaw主机 │ ──────────────────> │ PatchMon服务器 │
│ (本机) │ 查询更新 │ (独立主机) │
└─────────────────┘ └─────────────────┘
│
│ 上报
▼
┌─────────────────┐
│ 目标主机 │
│ (带代理) │
└─────────────────┘
快速开始:
- 1. 在独立服务器上安装PatchMon服务器(参见GitHub仓库)
- 在所有需要修补的主机上安装PatchMon代理
- 配置OpenClaw以访问PatchMon API:
bash
cp scripts/patchmon-credentials.example.conf ~/.patchmon-credentials.conf
nano ~/.patchmon-credentials.conf # 设置PatchMon服务器URL
chmod 600 ~/.patchmon-credentials.conf
详细设置:
参见references/patchmon-setup.md获取完整安装指南。
没有PatchMon可以使用此技能吗?
可以!您可以使用手动模式定位特定主机,无需PatchMon。但是,自动检测需要更新的主机需要PatchMon。
目标主机要求
必需:
- - SSH服务器正在运行
- SSH用户的免密码sudo(用于apt和docker命令)
- PatchMon代理已安装并上报(用于自动模式)
完整更新需要:
- - Docker和Docker Compose已安装
- Docker Compose文件存在于指定路径
配置免密码sudo
在每台目标主机上,创建/etc/sudoers.d/patches:
bash
对于Ubuntu/Debian系统
username ALL=(ALL) NOPASSWD: /usr/bin/apt, /usr/bin/docker
对于RHEL/CentOS系统
username ALL=(ALL) NOPASSWD: /usr/bin/yum, /usr/bin/docker, /usr/bin/dnf
将username替换为您的SSH用户。使用sudo -l验证。
更新模式
仅主机更新
仅更新系统软件包:
- - 运行apt update && apt upgrade(或RHEL上的yum