[Script,Linux] Auto-Start FTB Server on Crash + Automatic Backups

  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

ncreen_same

New Member
Jul 29, 2019
37
0
0
This script has 'killall screen' multiple times in it, killing every running instance of screen is not cool.
 

Eremite

New Member
Jul 29, 2019
12
0
0
@ncreen_same: Good point, the server I'm running only runs FTB so that's the only thing that is ever running in screen. I'll poke through and find a way to kill only the screen that has the previous instance of FTB opened in it.

@gustav9797 : How are you downloading/running that? According to the error message, line 4 that it's erroring out on has <!DOCTYPE html> in it, which shouldn't be anywhere in the script. ;p
Are you grabbing the script with wget? You'd want to get it like so:
$ wget http://raw.github.com/Sindern/rtb/master/rtb.sh
Also, for some reason that drives me crazy, all my github downloads come out in DOS linebreak format, so you'd need to convert it to unix linebreak format. I use dos2unix for it.


-edit-
Got it where it should only kill inotifywait or screen if it's related to the FTB server in question:
Code:
  kill $(ps faux | grep "${server_start}" | grep -i screen | awk '{print $2}') 2> /dev/null
  kill $(ps faux | grep inotifywait | grep $server_path | awk '{print $2}') 2> /dev/null
Not pretty, but it seems to work so far.
 

ncreen_same

New Member
Jul 29, 2019
37
0
0
@ncreen_same: Good point, the server I'm running only runs FTB so that's the only thing that is ever running in screen. I'll poke through and find a way to kill only the screen that has the previous instance of FTB opened in it.

@gustav9797 : How are you downloading/running that? According to the error message, line 4 that it's erroring out on has <!DOCTYPE html> in it, which shouldn't be anywhere in the script. ;p
Are you grabbing the script with wget? You'd want to get it like so:
$ wget http://raw.github.com/Sindern/rtb/master/rtb.sh
Also, for some reason that drives me crazy, all my github downloads come out in DOS linebreak format, so you'd need to convert it to unix linebreak format. I use dos2unix for it.


-edit-
Got it where it should only kill inotifywait or screen if it's related to the FTB server in question:
Code:
  kill $(ps faux | grep "${server_start}" | grep -i screen | awk '{print $2}') 2> /dev/null
  kill $(ps faux | grep inotifywait | grep $server_path | awk '{print $2}') 2> /dev/null
Not pretty, but it seems to work so far.
Instead of picking on how things are done, I should help out some. I'll fork her and see what I can come up with
 

NooBxGockeL

New Member
Jul 29, 2019
93
0
0
Its not very good that you grep java with hardcoded parameters.
Not every Server has exactly the parameter you are using...
 

glasspelican

New Member
Jul 29, 2019
187
0
0
This is a script not a program

Its common practice in Linux shell scripts to have a section at the top of the script where you set all your variables.
you want to change the paramaters you change the variable in the script.
I dont think you want to pass all your java paramaters in as arguments every time you start your server. That is why everyone starts there servers using bat files

Edit: sorry I see the part you mean now, simple fix, pass the $server_start variable
leaving my error as a reminder to read the entire post

if you download the file using git it fixes the line endings automatically
 

NooBxGockeL

New Member
Jul 29, 2019
93
0
0
@Eremite
Hope you dont mind that i (normally shell scripting noob) forked your starting script.
You can take a look at it and copy stuff over if you want.
 

ryetoc

New Member
Jul 29, 2019
23
0
0
I have forked and and DRYing the script a bit. I also found a bit of info that might help with my current issue (and a few other posts here) where the server stops responding but the thred doesn't die. Once it's tested I will stick in a pull request or two.[DOUBLEPOST=1360552013][/DOUBLEPOST]actually going to do this right and send micro commits. Enjoy the github spam
 

ryetoc

New Member
Jul 29, 2019
23
0
0
This script saves backups way too often. It make 40 Gigs of backups in about 24 hours.[DOUBLEPOST=1360672366][/DOUBLEPOST]Detection of the right process to kill does not work it leave the instance running. This has resulted in about 12 copies of ftbserver.jar running. I think the port scan fix should correct this problem but the pid getting lines are totally borking my server.
 

ryetoc

New Member
Jul 29, 2019
23
0
0
Ok TBH You might not want the modification I have made, but I put in the pull request.

First, backups were not working, and in linux it's generally accepted that a script/program/whatever will do the tiniest job possible. So I commented out backing up
Second, echoing to stdout is just WRONG (for a background process). That is totally annoying, so I striped that out as well and made it output to the log file, which it wasn't previously doing.
Third, with the port scan working there is no reason to check for crash logs. If the port is down, then it doesn't mater if there was a crash. So I removed that and the pid check which wasn't working correctly anyway.
Fourth, separated the config so that it's much eaiser to backup now, moved crash_log var to config.
Fifth, made it SIGKILL java and screen. This is needed to kill hung procs. This is not nice, but it works. This is after a SIGTERM so it should save if it could. timing may need to be adjusted.
Sixth, DRYed things up a lot. This really isn't needed now, but it still looks better. Was more useful when we did 3 server checks.


Notes:
  • This is significantly different from the first rtb, so take what you want, but you may not want much.
  • Backintime is a great backup program use it instead of rtb (specially as it wasn't working)
  • The pid getting lines, I'm not sure they work. Will just have to wait and see.
 

ryetoc

New Member
Jul 29, 2019
23
0
0
the "pid getting lines" do not work. I had to revert back to killall java and killall screen. Not nice, but functions. This is not in the github pull request.
 

ryetoc

New Member
Jul 29, 2019
23
0
0
This script is working 100% now from my fork. (no backups)

Please let me know if anything you found there is useful.
 

SolomonAiel

New Member
Jul 29, 2019
264
0
1
So I'm getting the issue where it won't recognize the detected_crashes.txt file. It will go to the folder but won't find the file. If anyone knows or has a fixed version of this they are willing to give out that'd be great.
 

xGamingDudex

New Member
Jul 29, 2019
1
0
0
I tried to run the scrip and it seams to be unable to take proper backups and seams to try every 10s or so

Also gives and error saying it can't find the detected_crashes.txt

Is this project abandoned since it is so long since any one replied on here, the github was last updated 11 months ago?
 

pherce

New Member
Jul 29, 2019
60
0
0
Why not go with rdiff and then you can back up every... 5 minutes if you want to? You could still tar or zip every X hours for an archive, but full zips every X hours for your primary backup choice eats a lot of disk space and IO.

Code:
#! /bin/bash
#SET THE FOLLOWING VARIABLES!
SERVERDIRECTORY="/home/minecraft/ftb"
SAVETO="/home/minecraft/ftb-backups"
rdiff-backup $SERVERDIRECTORY $SAVETO
exit

Add Screen commands for save-all/off/on as desired (I'm using Mark2).
 
  • Like
Reactions: Francis Baster

Circuitbomb

New Member
Jul 29, 2019
51
0
0
^ the incremental from rdiff is great; then you can tar.gz or zip from the incremental instead of the world folder and avoid touching files being written on by the server.
 

Dan0117

New Member
Jul 29, 2019
5
0
0
Hey, I've reccently started using this and I think this may help some people, this will simply detect if the server is listening/recieving on a port. I had to do this as my server randomly stops, like someone types /stop but I'm not sure why. When this happens RTB does not restart it as the screen is still present, this script *should* close the screen if it detects it's no longer listening. It is a bit slow, takes a few minutes to detect the server has gone down and close the screen, but better than nothing! :) to run this save it to your server somewhere, and run it in a seperate screen (type screen, then sh -x filename.sh then do ctrl+a+d to detach from the screen).

Code:
while true
do
if [[ -n $(netstat -anp | grep :25565) ]]; then
  echo "Up" 
else
  echo "Down"
   for session in $(screen -ls | grep -o '[0-9]*\.Ftb-Server'); do screen -S "${session}" -X quit; done
fi
sleep 25
done

EDIT: This needs netcat to run.

Install Howto
  1. Download the latest epel-release rpm from
    http://dl.fedoraproject.org/pub/epel/5/i386/
  2. Install epel-release rpm:
    # rpm -Uvh epel-release*rpm
  3. Install netstat-nat rpm package:
    # yum install netstat-nat