• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

Linux OTS Restarter

Gesior.pl

Mega Noob&LOL 2012
Senator
Premium User
Joined
Sep 18, 2007
Messages
2,743
Solutions
86
Reaction score
2,740
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:
OP
OP
Gesior.pl

Gesior.pl

Mega Noob&LOL 2012
Senator
Premium User
Joined
Sep 18, 2007
Messages
2,743
Solutions
86
Reaction score
2,740
Location
Poland
GitHub
gesior
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.
 

Similar threads

Top