• 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

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
I'm getting this error

Code:
-bash: ./restart.sh: /bin/bash^M: bad interpreter: No such file or directory
 
Bash:
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'"

  

  

    sleep 1

    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 10 SECONDS, PRESS CTRL+C TO TURN OFF RESTARTER

    #copy latest binary before running

# Calculate checksums for comparison

NEW_BINARY_CHECKSUM=$(crc32 /home/ots/build/tfs)

CURRENT_BINARY_CHECKSUM=$(crc32 /home/ots/tfs)



if [ "$NEW_BINARY_CHECKSUM" != "$CURRENT_BINARY_CHECKSUM" ]; then

    echo COPYING TFS BINARY

    cp /home/ots/build/tfs /home/ots

else

    echo BINARY NOT CHANGED, SKIPPING COPY

fi

    sleep 10

    echo END SLEEP



done
you can compile on production and if you do that then this way you can easily take latest build while server saving :) it will checksum the server files and if the one in /build is newer then it will take that.
(i build manually but im sure someone can explore it and add automatic build)
 
Back
Top