Need auto restart script

  • FTB will be shutting down this forum by the end of July. To participate in our community discussions, please join our Discord! https://ftb.team/discord

ficolas

New Member
Jul 29, 2019
55
0
0
I need a script that shuts down the server each hour, and then starts it again, like so the server will have much less lag.
 

xnorius

New Member
Jul 29, 2019
16
0
0
ok, on my linux setup i spawn the minecraft jar inside a tmux session (that is a terminal emulator), (just make sure you have the -nogui flag when executing the jar.) that way i can easily setup cron-jobs to execute commands inside the tmux session, like automatic backups and stuff like that, the same way you can use cron-jobs to execute a server restart, and also give a warning 30sec before the restart, so that people can get ready for the restart. if you would like i can pastebin some scripts for you, but they will be tmux based. i can provide you a: "server start script", "server stop script" and "restart server" cron-job script, that you drop in your "/etc/cron.hourly/" folder in your linux server. does this sound like a good solution for your setup? are you looking for something simpler?
 

xnorius

New Member
Jul 29, 2019
16
0
0
hmm.. i cant help with something simpler. sorry, i dont know java, so cant make a mod for that.

If you want a dirty way, you could always make a custom startup script. eg:
Code:
#!/bin/bash
 
while true; do
  echo "Starting Server"
  java -Xms512M -Xmx1G -jar FTB-Beta-A.jar &>> ./console.log &
  sleep 3600
  echo "Stopping Server"
  ps axa |grep " -jar FTB-Beta-A.jar" | awk '{print $1}' | xargs kill &>/dev/null
  sleep 5
  ps axa |grep " -jar FTB-Beta-A.jar" | awk '{print $1}' | xargs kill -9 &>/dev/null
done

its a very dirty hack, but very simple, just modify the original "Server Start.sh" to contain the "code block section", i do not recommend that solution. as it does not make sure that the server properly save the world. it might corrupt your world.
 
  • Like
Reactions: Infinite Unrest

Bråthen

New Member
Jul 29, 2019
41
0
0
Easiest way is to use screen and just make a shell script telling FTB console in screen to start and restart. Then just add it to your crontab once every hour.

That way you don't need to kill the process in an forced way.

Copy this script and name it what-you-want.sh
Code:
#!/bin/bash
 
# Sends ingame message
screen -S FTB -X stuff "say Server restart in 5 minutes $(printf '\r')"
 
# Waits 300 seconds
sleep 300
 
# Stops the server
screen -S FTB -X stuff "stop $(printf '\r')"
 
# Wait 10 seconds just to give the server time to shut down and save
sleep 10
 
# Starts the server
screen -S FTB -X stuff "./Server Start.sh $(printf '\r')"

What is your linux distro? Depends on how to get screen but as Debiansystem you type:
Code:
apt-get screen

To open a screen session with the name FTB type:
Code:
screen -S FTB

Start your server at the first time and detach the screen session with ctrl+a+d.

Add what-you-wish.sh (the shell script you just created) to your hourly crontab.

And you can just change the value of sleep to increase the time to wait for server restart. Don't forget to change the message also.

Edit: changed start command beginning with ./
 
  • Like
Reactions: Infinite Unrest

Gunner76th

New Member
Jul 29, 2019
13
0
0
Is this dead? I would need an hourly restart script for windows...
to do hourly restarts in windows, just write a batch file to shut down your server, wait, then restart it. Then, tell taskmanager to run that batch file at your chosen time.

Or, install a real OS like Linux and stop trying to run an MC server in faildows...
 

Infinite Unrest

New Member
Jul 29, 2019
14
0
0
Easiest way is to use screen and just make a shell script telling FTB console in screen to start and restart. Then just add it to your crontab once every hour.

That way you don't need to kill the process in an forced way.

Copy this script and name it what-you-want.sh
Code:
#!/bin/bash

# Sends ingame message
screen -S FTB -X stuff "say Server restart in 5 minutes $(printf '\r')"

# Waits 300 seconds
sleep 300

# Stops the server
screen -S FTB -X stuff "stop $(printf '\r')"

# Wait 10 seconds just to give the server time to shut down and save
sleep 10

# Starts the server
screen -S FTB -X stuff "./Server Start.sh $(printf '\r')"

What is your linux distro? Depends on how to get screen but as Debiansystem you type:
Code:
apt-get screen

To open a screen session with the name FTB type:
Code:
screen -S FTB

Start your server at the first time and detach the screen session with ctrl+a+d.

Add what-you-wish.sh (the shell script you just created) to your hourly crontab.

And you can just change the value of sleep to increase the time to wait for server restart. Don't forget to change the message also.

Edit: changed start command beginning with ./

Thanks for this. I'm struggling at the moment. I notice when watching the 'screen' that it enters the lines necessary but won't actually 'enter' / execute them. It just types the line, sleeps, then types the next line.

Any advice?
 

Bråthen

New Member
Jul 29, 2019
41
0
0
Depending on OS "\r" would sometimes interpret different. Try "\n" instead or "\r\n".

Don't know if it helps. Let me know :)