• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[DIY] Do it yourself: OT restarter part one: Linux

dominique120

Science & Reason
Senator
Premium User
Joined
Jun 16, 2013
Messages
3,881
Solutions
3
Reaction score
1,043
Location
Númenor
Hello and welcome to a new tutorial. This simple tutorial will teach you how to make a restarter got your OT server, eliminating the need to download software that may be unsafe. In this first part we will learn how to make one for Linux, in the next one we will learn how to make one for Windows.

Lets get started:


Open up the terminal and go to the directory where you have your tfs executable.
VE4vUtP.png


Then use nano to create a file called restarter.sh
Y4QtG5S.png


Now in nano we will write the following:

bi2WyOZ.png

Code:
while [ 1 ]; do

    ./tfs
done
Before saving it, don't forget to edit the part that says "./tfs". Change it to whatever you use to start your ot, if you use "./theforgottenserver" put that, if its "./otx", use "./otx" instead of "./tfs".

Now save it with "CTRL + O" and exit with "CTRL + X"

Now instead of starting your OT with ./tfs you will use "sh restarter.sh" and there you have it! You have created a restarter for Linux and your OT will restart whenever it crashes or in case you close it or if a globalsave closes it.

If you want to log the TFS console you can add " >> out.log" to the line where tfs is being executed(./tfs) and in the next post I'll show you some more advanced stuff.


Enjoy!
 
Last edited:
In this second part I'll show you some advanced things you could do with the some script we started with.

1. Log date and time when server crashes

Open your restarter and on the first line you will put this:
Code:
d=`date`
Now, after the line that has ./tfs enter this:
Code:
printf "Server restarted on: $d\n" >> ~/restarter_output
printf "\n" >> ~/restarter_output
This will create a file called restarter_output in your home directory and log the date and time every time the server crashes/is restarted



2. Warning, this is for advanced users, proceed with caution.

This script is an example for something very advanced and is what I used for pulling data from a repository for my OT the open source server, Alchera. This script assumes that all the directories are already created(tmp, ot). This script creates a backup for the data folder every time it pulls from the repo. Also, the script has to be configured at the top with the correct info.
Code:
#!/bin/bash

pkill tfs
#config
otname="the name of the folder where you keep your OT server, no spaces, keep it simple"
repo="https://github.com/PrinterLUA/FORGOTTENSERVER-ORTS"
reponame="FORGOTTENSERVER-ORTS"
#config end
while [ 1 ]; do
    #get ready to clone repo and clones it
    cd ~/tmp
    rm -Rf $reponame
    git clone $repo #--quiet
    success=$?
    #Checks to see if the cloning was successful
    if [[ $success -eq 0 ]]; then #if it was it will place the new data folder in the ot folder
        echo "Repository successfully cloned." > ~/$otname/out.txt
        #goes to ot dir and creates a backup
        cd ~/$otname
        rm -Rf data.bak
        mv data data.bak
        #mv or cp your stuff here if you want(maybe you have some stuff that is not in the repo)
        #logs date and time to a file to keep track of success and fails
        echo " " > ~/$otname/out.txt
        date > ~/$otname/out.txt
        echo "Success!" > ~/$otname/out.txt
        : #exits the statement if successful
    else #if it failed, it will tell you and restart the ot
        echo " " > ~/$otname/out.txt
        date > ~/$otname/out.txt
        echo "Something went wrong!" > ~/$otname/out.txt
        :#exit
    fi
    #got to ot dir and start it.
    cd ~/$otname
    ./tfs > ~/$otname/output.log
done

These are just a few examples of things that can be one in bash before or after the ot starts.


Enjoy!
 
Last edited:
works perfect!

only date in restarter_output is a date of execute resterter.sh.. any ideas how to print there correct date of crash/ss etc?
 
works perfect!

only date in restarter_output is a date of execute resterter.sh.. any ideas how to print there correct date of crash/ss etc?

Man Thanks a lot for the link to this thread really nice of you :D!

but i still have one question tho (sorry for me being such a noob)
my commands for starting the server are.

cd /home/otmanager

screen -A -S otserv

./build/tfs
I understand that i need to get it like this but....
  1. while [ 1 ]; do

  2. ./build/tfs
  3. done

how can i get to where my excecutable is. (my exe is at cd /home/otmanager/build)
so
1.-I type that cd /home/otmanager/build
2.-Do i need to type screen-A-S otserv? or do i only need to type "nano restarter.sh" then enter?
3.-
copy and paste
  • while [ 1 ]; do
  • ./build/tfs
  • done

4.- Win?
Im so sorry to bother you guys. is that im such a big noob with linux. sorry
and thanks in advance :D!
 
Back
Top