Port Manager Skill
Intelligently manage system port usage and avoid conflicts.
Features
1. Record Port (--record)
Record a port when starting a service:
CODEBLOCK0
2. Query Port (--query)
Check usage of a specific port:
CODEBLOCK1
3. List All Ports (--list)
Show all recorded services and ports:
CODEBLOCK2
4. Free Port (--free)
Release an occupied port (terminate the process):
CODEBLOCK3
5. Check and Resolve Conflicts (--check)
Check if a port is occupied, and ask user if they want to free it:
CODEBLOCK4
6. Auto Port Allocation (--allocate)
When port is occupied, automatically allocate an available port:
CODEBLOCK5
File Location
- - Port records: INLINECODE0
Usage Scenarios
- 1. Check before installing software
- Check port 5432 before installing PostgreSQL
- If occupied, ask user whether to free it
- 2. Service startup recording
- Record ports like 2375, 5432 when starting Docker
- Quickly see which services should run after restart
- 3. Port conflict resolution
- Two services fighting for the same port
- Auto-assign new port or free old port
Command Examples
CODEBLOCK6
Implementation
Use lsof and netstat to check ports:
CODEBLOCK7
端口管理器技能
智能管理系统端口使用并避免冲突。
功能特性
1. 记录端口 (--record)
启动服务时记录端口:
端口记录 <服务名称> <端口>
示例:端口记录 postgres 5432
2. 查询端口 (--query)
检查特定端口的使用情况:
端口查询 5432
3. 列出所有端口 (--list)
显示所有已记录的服务和端口:
端口列表
4. 释放端口 (--free)
释放被占用的端口(终止进程):
端口释放 5432
5. 检查并解决冲突 (--check)
检查端口是否被占用,并询问用户是否释放:
端口检查 5432
6. 自动分配端口 (--allocate)
当端口被占用时,自动分配可用端口:
端口分配 <服务名称> [首选端口]
文件位置
- - 端口记录:~/.openclaw/workspace/.port-manager/ports.json
使用场景
- 1. 安装软件前检查
- 安装 PostgreSQL 前检查端口 5432
- 如果被占用,询问用户是否释放
- 2. 服务启动记录
- 启动 Docker 时记录 2375、5432 等端口
- 重启后快速查看应运行哪些服务
- 3. 端口冲突解决
- 两个服务争用同一端口
- 自动分配新端口或释放旧端口
命令示例
bash
记录端口
端口记录 mysql 3306
端口记录 redis 6379
端口记录 postgres 5432
列出所有
端口列表
检查端口
端口检查 8080
释放端口
端口释放 5432
自动分配
端口分配 nginx 80
实现方式
使用 lsof 和 netstat 检查端口:
bash
检查端口使用情况
lsof -i :5432
终止进程
kill $(lsof -t -i :5432)