[Linux] Server auto-restart

These scripts are intended for use on Linux servers, however can be used on the desktop version as well. Because it's intended for Linux servers, we will be using a program called "Screen" to background our Minecraft server. For this example, I will be using Spigot as my server, but this would work with any Minecraft edition [Bukkit, Vanilla, Spigot, Tekkit...].

 

Instructions:

1. Open your terminal (via ssh,  or otherwise).

2. Check to see if "Screen" is already installed.

which screen

 

3. If a path is returned, example: "/usr/bin/screen", then Screen is installed. Skip to #5.

4. Install Screen by typing

Ubuntu:
sudo apt-get update sudo apt-get install screen
CentOS, RHEL:
yum install screen

5. Now that Screen is installed, download the two .sh files I've provided, and place them in your Minecraft's working directory. For this example, I will be using "/root/minecraft/" as my working directory. (This should be the same place you have your Minecraft servername.jar file stored. Example:

root folder

 

7. Now, edit them using the "vi" editor by typing

vi MCServerResetCheck.sh

8. Then edit the lines, highlighted below, to reflect your file path. You may also choose to change the "MCServerRestartLog.txt" to a different file name:

replace these lines

 

9. Save this file by typing "[ESC] :wq", which writes and quits the vi editor. Now, do the same with "start.sh". This time, only changing the lines highlighted below to reflect the startup of your server.jar file. In the image below I use the string "java -Xmx1g -Xms1g -jar spigot-1.11.2.jar".

change java startup

 

10. Now that we've configured all of this, we're going to set up a cronjob to execute every 30 seconds, making sure your server will restart itself if it crashes. Do this by typing:

service cron stop
crontab -e

11. This is your crontab. In your crontab file, enter these lines (change the path to your working directory):

* * * * * /root/minecraft/MCServerResetCheck.sh
* * * * * ( sleep 30 ; /root/minecraft/MCServerResetCheck.sh)

12. If you wish to not run this test so often (it's not CPU intensive, I promise), you can do so by removing one of the two lines above from your code, making the cronjob run once every minute. If you wish it to run every two minutes, change the asterisks from "* * * * *" to "*/2 * * * *". If you wish to have it run every three minutes, change it to "*/3 * * * *". This process can be repeated up to "*/59". For 59 minutes.

 

13. Now, restart cronjob by running:

service cron start

14. Yay! Your minecraft server should start itself automatically now! To make sure it's working, and to get back into the Minecraft console at any time, simply time "screen -r" to resume the screen session. To exit the screen session, type "[CTRL] + a" and then "d".

Download

File Name Status Version Downloads Date
Shell Scripts R 1.11.2 +52 1,851 20/03/2017
[Linux] Server auto-restart 1.20.2 Updating 1.20.2 Updating Updating
[Linux] Server auto-restart 1.20.1 Updating 1.20.1 Updating Updating
[Linux] Server auto-restart 1.20 Updating 1.20 Updating Updating
[Linux] Server auto-restart 1.19.2 Updating 1.19.2 Updating Updating
[Linux] Server auto-restart 1.19.1 Updating 1.19.1 Updating Updating
[Linux] Server auto-restart 1.19 Updating 1.19 Updating Updating
[Linux] Server auto-restart 1.18 Updating 1.18 Updating Updating
[Linux] Server auto-restart 1.17.1 Updating 1.17.1 Updating Updating
[Linux] Server auto-restart Forge Updating Forge Updating Updating
[Linux] Server auto-restart Fabric Updating Fabric Updating Updating
[Linux] Server auto-restart
[Linux] Server auto-restart

Dear youtuber!
Have you a channel youtube and want to bring your Video to quality visitors?
Do you want your video to appear on our website?
Do you want to become partner with us?
Just 3 steps to become our partner:
Step 1: Make video review for mods, addons, plugins, ... which you like
Step 2: Upload this video to youtube and our link to your video description
Step 3: Send the youtube video link via message to http://fb.com/9lifehack or leave a comment in the post. We will add your video in the our post, it will help you have more view.
JOIN to get more youtube view with us!!!!

Related Posts

Smarty Productivity Happiness

9LifeHack.com - make things smart