Last active
April 20, 2024 13:52
-
-
Save victornpb/e283c4f30c93ba7f8e087d1d978e44f0 to your computer and use it in GitHub Desktop.
Bash script to start Minecraft server and keep it running if it crashes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Config | |
WINDOW_TITLE="Minecraft Server" | |
ONLINE_AUTH=true | |
RAM_INITIAL=512M | |
RAM_MAX=4G | |
RESTART_DELAY=10 | |
################################################################################ | |
cd "$(dirname "$0")" | |
while true | |
do | |
# Find jar file | |
jarfile=$(ls | grep -i -e "\.jar$" | head -1) | |
if [ -e $jarfile ]; then | |
echo " STARTING SERVER..." | |
echo "===============================================================================" | |
echo -n -e "\033]0;[RUNNING] $WINDOW_TITLE\007" | |
java -Xms$RAM_INITIAL -Xmx$RAM_MAX -jar "$jarfile" -o $ONLINE_AUTH nogui > /dev/null | |
echo -n -e "\033]0;[STOPPED!] $WINDOW_TITLE\007" | |
echo "###############################################################################" | |
echo " [$(date)] SERVER STOPPED!" | |
else | |
echo "Could not find the server jar file." | |
fi | |
echo " Rebooting in $RESTART_DELAY seconds... (Press CTRL-C to kill process)" | |
sleep $RESTART_DELAY | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment