#!/bin/bash # Watchdog to kill stuck MetaEditor processes while true; do # Find MetaEditor processes running for more than 5 minutes with high CPU docker exec mt5 sh -c ' ps aux | grep metaeditor64 | grep -v grep | while read line; do pid=$(echo $line | awk "{print \$2}") cpu=$(echo $line | awk "{print \$3}") time=$(echo $line | awk "{print \$10}") # Kill if running more than 5 mins or using >50% CPU for >2 mins if echo "$time" | grep -qE "[5-9]:[0-9]{2}|[0-9]{2,}:"; then echo "Killing long-running MetaEditor: $pid (time: $time)" kill -9 $pid 2>/dev/null elif [ "${cpu%.*}" -gt 50 ] 2>/dev/null; then echo "Killing high-CPU MetaEditor: $pid (CPU: $cpu%)" kill -9 $pid 2>/dev/null fi done ' 2>/dev/null sleep 60 done