• 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!

Linux OTS Restarter

Gesior.pl

Mega Noob&LOL 2012
Senator
Joined
Sep 18, 2007
Messages
2,955
Solutions
98
Reaction score
3,351
Location
Poland
GitHub
gesior
There are some similar threads. I've decided to release my version.
Features:
  • MySQL backup every restart
  • after crash copy core file and tfs binary into crashlog directory
  • log all TFS console output to file console.log, every restart move console.log content into directory console into file with date in name
  • add date with miliseconds to every line in TFS console output [usefull for old engines that do not print date in console]

Put it in restart.sh and run it on screen:
Bash:
#!/bin/bash

# to get 'ts' command: sudo apt install moreutils
# to get 'crc32' command: sudo apt install libarchive-zip-perl

BINARY_NAME=tfs
MYSQL_USER=root
MYSQL_PASS=YourSecretPass
MYSQL_DATABASE=forgottenserver

mkdir console
mkdir crashlog
mkdir mysql_backup

ulimit -c unlimited

while true; do

    # database backup, it's best moment to make database copy, OTS is offline for sure, so there can't be any item clones
    mysqldump -u $MYSQL_USER -p$MYSQL_PASS $MYSQL_DATABASE > mysql_backup/`date '+%Y-%m-%d_%H-%M'`.sql

    # gzip older than 3 days
    find console/ -name '*.log' -mtime +3 -print -exec gzip -f {} \;
    find crashlog/ -name '*.bin' -mtime +3  -print -exec gzip -f {} \;
    find crashlog/ -name '*.core' -mtime +3  -print -exec gzip -f {} \;
    find mysql_backup/ -name '*.sql' -mtime +3  -print -exec gzip -f {} \;

    BINARY_WITH_HASH=`date '+%Y-%m-%d_%H-%M'`_`crc32 $BINARY_NAME`
    # copy current binary file, you need binary from moment of crash to run it in gdb
    cp $BINARY_NAME crashlog/$BINARY_WITH_HASH.bin

    # start server
    # if your server already prints date with every line in console, you can remove "| ts '%Y-%m-%d_%H-%M-%.S'"
    stdbuf -o 0 ./$BINARY_NAME 2>&1 | ts '%Y-%m-%d_%H-%M-%.S' | tee 'console.log'

    cat 'console.log' >> 'console/console_'`date '+%Y-%m-%d'`'.log';
    mv core crashlog/$BINARY_WITH_HASH.core

    echo START SLEEP FOR 3 SECONDS, PRESS CTRL+C TO TURN OFF RESTARTER
    sleep 3
    echo END SLEEP

done
 
Last edited:
There should be also core file: 2022-07-30_15-57_e409ef81.core[B][/B]
If there is no core file, it means that server did not crash or your Linux is not configured to generate core file on application crash.
If there is core file, you got to run gdb 2022-07-30_15-57_e409ef81.bin 2022-07-30_15-57_e409ef81.core and then bt full to get crash report.
 
@Gesior.pl
Trying to run this script for TFS 0.3.6. I have Ubuntu 20 but also I have the following errors.

Code:
ubuntu@minecraftserver:~/rts036$ bash ./restart.sh
./restart.sh: line 2: $'\r': command not found
./restart.sh: line 5: $'\r': command not found
./restart.sh: line 10: $'\r': command not found
mkdir: cannot create directory ‘console\r’: File exists
mkdir: cannot create directory ‘crashlog\r’: File exists
mkdir: cannot create directory ‘mysql_backup\r’: File exists
./restart.sh: line 14: $'\r': command not found
: invalid numberne 15: ulimit: unlimited
./restart.sh: line 16: $'\r': command not found
./restart.sh: line 44: syntax error: unexpected end of file

This bash script created strange folder names:
eCnRE7x.png
 
Last edited:
@Gesior.pl
Trying to run this script for TFS 0.3.6. I have Ubuntu 20 but also I have the following errors.

Code:
ubuntu@minecraftserver:~/rts036$ bash ./restart.sh
./restart.sh: line 2: $'\r': command not found
./restart.sh: line 5: $'\r': command not found
./restart.sh: line 10: $'\r': command not found
mkdir: cannot create directory ‘console\r’: File exists
mkdir: cannot create directory ‘crashlog\r’: File exists
mkdir: cannot create directory ‘mysql_backup\r’: File exists
./restart.sh: line 14: $'\r': command not found
: invalid numberne 15: ulimit: unlimited
./restart.sh: line 16: $'\r': command not found
./restart.sh: line 44: syntax error: unexpected end of file

This bash script created strange folder names:
eCnRE7x.png
sudo apt install dos2unix -y
dos2unix restart.sh
./restart.sh
 
Is there any way of making something similar but on Windows?
 
1. auto-restart: yes [ OpenTibia - [TSM] The Simplest Restarter v1 (https://otland.net/threads/tsm-the-simplest-restarter-v1.169821/) ]
2. log output to files: probably yes [ in restarter above is code that should log output to file restarter.log, but it's probably deleted every server restart ]
3. store crash logs in folder: no
4. MySQL backup on restart: probably yes
The most important is storing crash since there is no way right now to actually know what is crashing a server unless u debug it on MSV and so on and so on.
 
The most important is storing crash since there is no way right now to actually know what is crashing a server unless u debug it on MSV and so on and so on.
As I always say: it's easier to learn Linux, than to fix all problems on Windows.

Anyway, I found some tutorial how to make Windows save 'dmp' files (like core on linux) for every crashed app:
Looks like it's not configured per application, but on system level for all apps.
 
Gesior thanks for continuing to bring good and usefull content to the community!
 
@Gesior.pl - i have problem with this restarter.
In my www/... restarter create new folders, but engine not start.

JavaScript:
ubuntu@minecraftserver:~/rts036$ bash ./restart.sh
./restart.sh: line 2: $'\r': command not found
./restart.sh: line 5: $'\r': command not found
./restart.sh: line 10: $'\r': command not found
mkdir: cannot create directory ‘console\r’: File exists
mkdir: cannot create directory ‘crashlog\r’: File exists
mkdir: cannot create directory ‘mysql_backup\r’: File exists
./restart.sh: line 14: $'\r': command not found
: invalid numberne 15: ulimit: unlimited
./restart.sh: line 16: $'\r': command not found
./restart.sh: line 44: syntax error: unexpected end of file
 
@Gesior.pl - i have problem with this restarter.
In my www/... restarter create new folders, but engine not start.

JavaScript:
ubuntu@minecraftserver:~/rts036$ bash ./restart.sh
./restart.sh: line 2: $'\r': command not found
./restart.sh: line 5: $'\r': command not found
./restart.sh: line 10: $'\r': command not found
mkdir: cannot create directory ‘console\r’: File exists
mkdir: cannot create directory ‘crashlog\r’: File exists
mkdir: cannot create directory ‘mysql_backup\r’: File exists
./restart.sh: line 14: $'\r': command not found
: invalid numberne 15: ulimit: unlimited
./restart.sh: line 16: $'\r': command not found
./restart.sh: line 44: syntax error: unexpected end of file
You've uploaded file from Windows with 'windows new line', which is 2 characters: \r\n.
Linux expects files in Linux format (Unix format) with new line \n (without \r).

You can change line endings in file using any IDE (Visual Studio, PHPStorm, CLion, IDEA) or in Notepad++.
Ex. in Notepad++:
1672155823759.png
 
Last edited:
You've uploaded file from Windows with 'windows new line', which is 2 characters: \r\n.
Linux expects files in Linux format (Unix format) with new line \n (without \r).

You can change line endings in file using any IDE (Visual Studio, PHPStorm, CLion, IDEA) or in Notepad++.
Ex. in Notepad++:
View attachment 72493
Perfect working! Thank you Gesior.pl !!!
 
You've uploaded file from Windows with 'windows new line', which is 2 characters: \r\n.
Linux expects files in Linux format (Unix format) with new line \n (without \r).

You can change line endings in file using any IDE (Visual Studio, PHPStorm, CLion, IDEA) or in Notepad++.
Ex. in Notepad++:
View attachment 72493

One more problem. My data base no save. No have others data (error log etc.) Why ?
 
One more problem. My data base no save. No have others data (error log etc.) Why ?
Same problem here.
There should be also core file: 2022-07-30_15-57_e409ef81.core[B][/B]
If there is no core file, it means that server did not crash or your Linux is not configured to generate core file on application crash.
If there is core file, you got to run gdb 2022-07-30_15-57_e409ef81.bin 2022-07-30_15-57_e409ef81.core and then bt full to get crash report.
hmm do you know maybe how to configure linux to generate core files?
 
hmm do you know maybe how to configure linux to generate core files?
You can check where core file is saved:
Code:
cat /proc/sys/kernel/core_pattern
If it shows something about 'apport', you must disable it:
Code:
systemctl stop apport
systemctl disable apport
Then:
Code:
cat /proc/sys/kernel/core_pattern
should return single word core - core file will be saved in same directory as app that crashed.

You can test-crash your TFS with command:
Code:
killall -11 tfs
It will shutdown server and make linux handle it as server crash.
 
Hi sorry for double post. I have question. When you run server as a root TFS will say you warning to consider running server as not root. But when you run server as not root then this restarter not work. Or Am i wrong?
 
Back
Top