There are some similar threads. I've decided to release my version.
Features:
Put it in
Features:
- MySQL backup every restart
- after crash copy
core
file andtfs
binary intocrashlog
directory - log all TFS console output to file
console.log
, every restart moveconsole.log
content into directoryconsole
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: