Auto Restart Screen Processes

Some services are meant to interact with the screen. The minecraft server comes to mind. You can send it's output to null, but you may want to interact with the server console. To do this you want to
 - launch it in a detached screen
- check it every so often and relauch it if crashed

So adapt this script to the process you need, and toss it in cron.whatever.

#!/bin/bash
LOCATION=/srv/minecraft/tland
SERVER=minecraft_server.1.8.jar

cd $LOCATION

ps -ef  | grep -v grep | grep "SCREEN.*tland" > /dev/null

if [ $? -eq 0 ]; then
    exit
else
    screen -d -m -S tland java -server -Xmx1024M -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=2 -XX:+AggressiveOpts -jar $LOCATION/$SERVER nogui
fi

http://stackoverflow.com/questions/9117507/linux-unix-command-to-determine-if-process-is-running
Comments