Files
remote-host-agent/start.sh
T
hz4th_coder c877b25ff6 v1.0.0 remote-host-agent: 机器B监控/控制轻量方案(HTTP上报+命令长轮询)
- collector.py: 机器A端 FastAPI 服务(16018),token认证 + strict/open 命令白名单 + SQLite存储
- agent.sh: 机器B端轻量agent(仅bash+curl+base64,零安装),采集CPU/内存/磁盘/负载/开机时间 + 长轮询执行命令回传结果
- hostctl.py: 机器A端 CLI(status/hosts/run/history/commands)
- host-agent.service: 机器B端 systemd 服务
- start.sh: collector 启停脚本
2026-08-19 19:08:23 +08:00

44 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# remote-host-agent collector 启停脚本(机器A端)
# ./start.sh 启动 | ./start.sh stop 停止 | ./start.sh restart 重启
cd "$(dirname "$0")"
PY=/home/hz1/miniconda3/envs/openclaw/bin/python3
PORT=${HOST_AGENT_PORT:-16018}
PID_FILE="logs/collector.pid"
mkdir -p logs
case "${1:-start}" in
stop)
if [ -f "$PID_FILE" ]; then
kill "$(cat "$PID_FILE")" 2>/dev/null && echo "已停止 collector (PID $(cat "$PID_FILE"))" || echo "进程不存在"
rm -f "$PID_FILE"
else
echo "未找到 PID 文件"
fi
;;
restart)
"$0" stop; sleep 1; "$0" start
;;
start)
if [ -f "$PID_FILE" ] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then
echo "collector 已在运行 (PID $(cat "$PID_FILE"), 端口 $PORT)"
exit 0
fi
nohup "$PY" collector.py > logs/collector.out 2>&1 &
echo $! > "$PID_FILE"
sleep 2
if kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then
echo "collector 启动成功 (PID $(cat "$PID_FILE"), 端口 $PORT)"
echo "Token 文件: $(pwd)/data/token.txt"
if [ -f data/token.txt ]; then
echo "Token: $(cat data/token.txt)"
fi
else
echo "启动失败,查看 logs/collector.out"; exit 1
fi
;;
*)
echo "用法: $0 [start|stop|restart]"; exit 1
;;
esac