Skip to content

Instantly share code, notes, and snippets.

@seakintruth
Last active April 5, 2020 17:27
Show Gist options
  • Save seakintruth/1c909de1ac72302fdee784c9a6fe5a39 to your computer and use it in GitHub Desktop.
Save seakintruth/1c909de1ac72302fdee784c9a6fe5a39 to your computer and use it in GitHub Desktop.
Run minecraft server, restart every 10 minutes if java isn't running
#!/usr/bin/env bash
while true
do
if pgrep -x java >/dev/null
then
echo "Java is running, assuming minecraft is running: $(date)"
else
echo "Java not running, Starting minecraft server... $(date)"
# screen doesn't allways cleanup properly
# see: https://superuser.com/a/1284329
sudo -S mkdir -p ~/.screen && chmod 700 ~/.screen
export SCREENDIR=$HOME/.screen
sudo -S screen -d -m java -Xmx5G -Xms2G -jar /home/minecraft/Server/server.jar nogui
fi
sleep 600
done
@seakintruth
Copy link
Author

may need to update this script to look for minecraft not just java, look at https://askubuntu.com/questions/912286/shell-know-if-minecraft-is-running-or-not
pgrep -f minecraft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment