The easiest way to do this is through nano, the built-in text editor on Raspberry Pi devices.
To do this, type the line:
nano mcstart.sh
Next, enter this code:
#!/bin/bash
cd ~/mcserver
while true
do
java -Xmx1024M -Xms1024M -jar server.jar
sleep 10
done
This snippet of code creates a loop that turns the server on and then if it ever crashes, reboots it after 10 seconds. This ensures you won’t have to continually fiddle with the server if it crashes for any reason.
Next, we will want to make the server executable to all users and make the server instantly boot. Set mcstart.sh to be executable by all users:
Chmod a+x mcstart.sh
Next, set it to automatically boot with:
crontab -e
@reboot /home/pi/mcserver/mcstart.sh
Lastly, restart the Raspberry Pi and see if the installation went smoothly. If all goes well, then you are ready to get the server onto the internet.