So originally I wanted to do something nice and simple, that makes use of some of the native functions of Linux for just such situations as this. A simple 4 line script.
until StarMade-dedicated-server-linux.sh; do
echo \"StarMade crashed with exit code $?. Respawning..\" >&2
sleep 1
done
However from what I can gather, when StarMade crashes, it doesn\'t *really* crash. At least not as the OS sees it. See, StarMade crashes gracefully (at least every time I\'ve seen) and actually saves its state and shuts down properly. This means that it sends a termination code of 0, and thus this script does not run. It looks at the shutdown and says \"Oh, no, you meant to do that. Guess I don\'t need to do anything.\" So while I am glad that StarMade even manages to crash reasonably gracefully, it does cause a problem here. That script does not work.
After some minor frustrations that are typical of toying with scripting languages you don\'t use much, I got the below script put together and working. It checks for instances of StarMade.jar in the processes list and starts the server if they\'re not located. This does have to be put into crontab, unless you have another way to make the thing keep checking. Mine is set to check every 5 minutes, I figure that\'s probably fine. Hopefully this helps people some.
EDIT: I found a better way to set the script up that doesn\'t require cron. In hindsight, I feel silly for not realizing this previously but oh well. I\'ve been running this script for a few days now and it seems to work well. You can change the sleep time to whatever you want it to be.
#!/bin/bash
while :
do
if [ \"$(pgrep -f StarMade.jar)\" ]
then
echo “$(date “+%m%d%y %T”) : StarMade is running already”
else
echo “$(date “+%m%d%y %T”) : StarMade not running, launching…”
cd “$(dirname “$0?)”
/opt/java/bin/java -Xms512m -Xmx4G -jar StarMade.jar -server
fi
sleep 2m
done