- cpulimit now reapplies when aot process restarts
- reduce resolution to 640x480 (to reduce CPU usage) - renamed restart-aot-crash.sh to aot-monitor.sh - added new env variable RESOLUTION for setting x11 and AgeOfTime game resolution on container startup (so it's easy to change) - updated readme
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
#!/bin/bash
|
||||
# the purpose of this script is to run in the background and check if
|
||||
# winedbg "Program Error" window popped up and if so kill AgeOfTime.exe and winedbg
|
||||
# so supervisor will restart it
|
||||
|
||||
# this file also applies cpulimit to the AgeOfTime.exe process by monitoring
|
||||
# a $CPU_LIMIT_FILE file and applying cpulimit whenever this value changes
|
||||
# if the value changes to zero then the cpulimit process is removed
|
||||
# entirely (or never started if initial value is zero)
|
||||
|
||||
export DISPLAY=":0.0"
|
||||
CPU_LIMIT_FILE="$AOTDIR/aot_cpu_limit"
|
||||
CURRENT_LIMIT=0
|
||||
|
||||
# Initialize the CPU limit file with AOT_CPU_LIMIT if it's set
|
||||
if [ ! -z "$AOT_CPU_LIMIT" ]; then
|
||||
echo "$AOT_CPU_LIMIT" > "$CPU_LIMIT_FILE"
|
||||
fi
|
||||
|
||||
# give the x server time to start
|
||||
sleep 5;
|
||||
|
||||
while true; do
|
||||
AOT_PID=$(pidof AgeOfTime.exe)
|
||||
|
||||
# if "Program Error" dialog found kill aot and winedbg
|
||||
# as supervisor thinks it's still running
|
||||
if wmctrl -l | awk '{$3=""; $2=""; $1=""; print $0}' | grep '^\s*Program Error$'; then
|
||||
kill $AOT_PID
|
||||
kill $(pidof winedbg)
|
||||
sleep 2
|
||||
continue
|
||||
fi
|
||||
|
||||
# wait AgeOfTime.exe is not running
|
||||
if [ -z "$AOT_PID" ]; then
|
||||
CURRENT_LIMIT=0
|
||||
sleep 1
|
||||
continue
|
||||
fi
|
||||
|
||||
# if our $CPU_LIMIT_FILE exists..
|
||||
if [ -f "$CPU_LIMIT_FILE" ]; then
|
||||
NEW_LIMIT=$(cat "$CPU_LIMIT_FILE")
|
||||
|
||||
# Check if cpulimit is not running
|
||||
CPULIMIT_PID=$(pgrep -fl "cpulimit.*\-p $(pidof AgeOfTime.exe)" | awk '{print $1}')
|
||||
if [ -z "$CPULIMIT_PID" ]; then
|
||||
CURRENT_LIMIT=0
|
||||
fi
|
||||
|
||||
# Validate NEW_LIMIT is a number greater than zero
|
||||
if [[ "$NEW_LIMIT" =~ ^[0-9]+$ ]]; then
|
||||
# Check if the limit has changed
|
||||
if [ "$NEW_LIMIT" -ne "$CURRENT_LIMIT" ]; then
|
||||
# If so, update CURRENT_LIMIT
|
||||
CURRENT_LIMIT="$NEW_LIMIT"
|
||||
# Kill existing cpulimit process if any
|
||||
if [ ! -z "$CPULIMIT_PID" ]; then
|
||||
echo "Killing cpulimit process $CPULIMIT_PID"
|
||||
kill "$CPULIMIT_PID"
|
||||
fi
|
||||
# Apply new cpulimit if >= 0
|
||||
if [ ! -z "$AOT_PID" ] && [ "$NEW_LIMIT" -gt 0 ]; then
|
||||
echo "Creating cpulimit process (limit=$NEW_LIMIT)"
|
||||
cpulimit -p "$AOT_PID" -l "$NEW_LIMIT" -b &
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
done
|
||||
Reference in New Issue
Block a user