d0b20a0e14
新增: - provision_server.py HTTP API 服务 (Bottle, 端口 5566) - 状态持久化 (JSON, 每30秒保存, 1小时内可恢复) - 会议室模式 (开发团队 Inbox 多 AI 路由) - supervisor 托管, SIGTERM 优雅退出 - PUBSUB_TOKEN 三级 fallback 修复: - 所有硬编码凭证清除 (CW_EMAIL/CW_PASSWORD 无 fallback) - 双重 WebSocket 重连 - 内存泄漏 (无界 Set 清理) - INBOX_CONFIG 兜底 (skip+log 不崩溃) - PID 文件竞争, Metrics 热路径优化 - 幂等性正确实现 (存真实响应含 HTTP 状态码) 安全: - 完整数据脱敏 (无 URL/邮箱/密码/token 硬编码) - .env.example / chatwoot_auth.example.json / inboxes.example.json
80 lines
2.1 KiB
Bash
Executable File
80 lines
2.1 KiB
Bash
Executable File
#!/bin/sh
|
|
# Chatwoot WebSocket Agent Control Script
|
|
# Usage: ./chatwoot_ws_ctl.sh {start|stop|restart|status|logs}
|
|
|
|
SCRIPT_DIR="/app/working/workspaces/wordpress/skills/wordpress-cli"
|
|
PIDFILE="/var/run/chatwoot_ws_agent.pid"
|
|
LOGFILE="/var/log/chatwoot_ws_agent.log"
|
|
COMMAND="python3 $SCRIPT_DIR/chatwoot_ws_agent.py"
|
|
|
|
# Helper: check if PID is actually our agent (avoids PID reuse race)
|
|
_pid_is_ours() {
|
|
pid="$1"
|
|
[ -z "$pid" ] && return 1
|
|
# Check PID exists AND its cmdline matches
|
|
if kill -0 "$pid" 2>/dev/null; then
|
|
cmdline=$(cat /proc/$pid/cmdline 2>/dev/null | tr '\0' ' ')
|
|
case "$cmdline" in
|
|
*chatwoot_ws_agent.py*) return 0 ;;
|
|
esac
|
|
fi
|
|
return 1
|
|
}
|
|
|
|
case "$1" in
|
|
start)
|
|
if [ -f "$PIDFILE" ] && _pid_is_ours $(cat "$PIDFILE"); then
|
|
echo "Agent already running (PID $(cat $PIDFILE))"
|
|
exit 1
|
|
fi
|
|
cd "$SCRIPT_DIR"
|
|
python3 -c "
|
|
import subprocess, os
|
|
p = subprocess.Popen(['python3', '$SCRIPT_DIR/chatwoot_ws_agent.py'],
|
|
stdout=open('$LOGFILE','a'), stderr=subprocess.STDOUT,
|
|
cwd='$SCRIPT_DIR', preexec_fn=os.setsid)
|
|
print(p.pid)
|
|
" > "$PIDFILE"
|
|
echo "Agent started (PID $(cat $PIDFILE))"
|
|
;;
|
|
stop)
|
|
if [ -f "$PIDFILE" ]; then
|
|
PID=$(cat "$PIDFILE")
|
|
if _pid_is_ours "$PID"; then
|
|
kill "$PID" 2>/dev/null
|
|
sleep 2
|
|
kill -9 "$PID" 2>/dev/null
|
|
fi
|
|
rm -f "$PIDFILE"
|
|
echo "Agent stopped"
|
|
else
|
|
echo "No PID file found"
|
|
pkill -f "chatwoot_ws_agent.py" 2>/dev/null && echo "Killed all chatwoot_ws_agent processes" || echo "No processes found"
|
|
fi
|
|
;;
|
|
restart)
|
|
$0 stop
|
|
sleep 1
|
|
$0 start
|
|
;;
|
|
status)
|
|
if [ -f "$PIDFILE" ] && _pid_is_ours $(cat "$PIDFILE"); then
|
|
echo "Agent running (PID $(cat $PIDFILE))"
|
|
else
|
|
if pgrep -f "chatwoot_ws_agent.py" >/dev/null 2>&1; then
|
|
echo "Agent running (no PID file)"
|
|
pgrep -f "chatwoot_ws_agent.py"
|
|
else
|
|
echo "Agent not running"
|
|
fi
|
|
fi
|
|
;;
|
|
logs)
|
|
tail -30 "$LOGFILE"
|
|
;;
|
|
*)
|
|
echo "Usage: $0 {start|stop|restart|status|logs}"
|
|
exit 1
|
|
;;
|
|
esac
|