aot-wine-x11-novnc-docker/restart-aot-crash.sh

36 lines
1.4 KiB
Bash

#!/bin/bash
export DISPLAY=":0.0"
# this script checks for the presence of the wine "Program Error"
# dialog and if it is present it kills AgeOfTime and winedbg
# which causes supervisor to restart it
# This script also applies cpu limits if the env variable AOT_CPU_LIMIT is set
# Check if AOT_CPU_LIMIT is set and not zero
if [ -z "$AOT_CPU_LIMIT" ] || [ "$AOT_CPU_LIMIT" -eq 0 ]; then
SKIP_CPU_LIMIT=true
else
SKIP_CPU_LIMIT=false
fi
while true; do
if wmctrl -l|awk '{$3=""; $2=""; $1=""; print $0}' | grep '^\s*Program Error$'; then
# echo "AOT Program Error detected"
kill $(pidof AgeOfTime.exe)
kill $(pidof winedbg)
elif ! $SKIP_CPU_LIMIT && pidof AgeOfTime.exe >/dev/null; then
# AgeOfTime.exe is running
# Ensure cpulimit is installed and get the PID of AgeOfTime.exe
AOT_PID=$(pidof AgeOfTime.exe)
# Check if cpulimit is already running for AgeOfTime.exe to avoid stacking multiple limits
if ! pgrep -f "cpulimit.*$AOT_PID" > /dev/null; then
# Apply cpulimit to AgeOfTime.exe to limit it to 2 cores and 50% usage
# Note: cpulimit doesn't directly support core limitation, so we adjust the overall CPU percentage assuming 2 cores
# For more precise control, consider taskset or cgroups
cpulimit -p $AOT_PID -l $AOT_CPU_LIMIT
fi
fi
sleep 2
done