Rozdíly
Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.
dev:scripty:startup_script [27.10.2013 22:26] ritchie |
dev:scripty:startup_script [31.12.2013 23:34] (aktuální) ritchie redirect stderr to stdout from minetest_mapper |
||
---|---|---|---|
Řádek 1: | Řádek 1: | ||
===== Startup script ===== | ===== Startup script ===== | ||
- | brandonuv [[http://pastebin.com/xE23Kb30|startup script]] je infinite loop: | + | Brandonův [[http://pastebin.com/xE23Kb30|startup script]] je infinite loop: |
while true do blabla done | while true do blabla done | ||
- | proto bude lepsi udelat klasicky startup.sh s podminkama zda mtserver bezi, nic nedelat jinak zalohovat a cronem hlidat ten script\\ | + | proto je lepší udělat klasický skript minetest_start.sh s podmínkami zda mtserver běží, pokud jo, nic nedělat jinak zálohovat a cronem hlídat ten script. |
- | (17:24:24) Pitriss: Ritchie_: BTW v cronu se hodí ěnco ve stylu: \\ | + | |
+ | Do /etc/crontab byl vložen následující řádek: \\ | ||
'' | '' | ||
- | */5 * * * * minetest if [ `ps -e | grep -c minetestserver` = '0' ]; then /usr/local/bin/minetest_start.sh; fi | + | */5 * * * * minetest if [ `ps -e | grep -c minetest` = '0' ]; then /usr/local/bin/minetest_start.sh >> /opt/minetest-data/logs/minetest_start/minetest_start.log; fi |
'' | '' | ||
+ | |||
+ | Skript má v crontabu nastavené přesměrování výstupu do logu. | ||
<file bash minetest_start.sh> | <file bash minetest_start.sh> | ||
Řádek 17: | Řádek 20: | ||
### config section | ### config section | ||
+ | # All patches to directories must have a slash "/" at end! | ||
#patch to world | #patch to world | ||
WORLD="/opt/minetest/world/classic_technic_game/" | WORLD="/opt/minetest/world/classic_technic_game/" | ||
+ | #patch to minetest directory | ||
+ | MINETEST="/opt/minetest/" | ||
#patch to backup directory | #patch to backup directory | ||
BACKUP="/opt/minetest-data/world-backups/" | BACKUP="/opt/minetest-data/world-backups/" | ||
#patch to maps directory | #patch to maps directory | ||
- | MAP="/opt/minetest-data/maps/" | + | MAP_DIR="/opt/minetest-data/maps/" |
+ | #patch to mapper directory | ||
+ | MAPPER="/opt/minetest-git/minetest-mapper-cpp/" | ||
+ | #path to directory with minetestserver logs | ||
+ | LOGS="/opt/minetest-data/logs/" | ||
### end of config section | ### end of config section | ||
Řádek 30: | Řádek 40: | ||
NOW="$(date +%d%m%Y_%T)" | NOW="$(date +%d%m%Y_%T)" | ||
#name of world | #name of world | ||
- | NAME="$(echo "$WORLD" | awk -F/ '{print $(NF-1)}')" | + | NAME="$(echo "$WORLD" | awk 'BEGIN { FS = "/" } {print $(NF-1)}')" |
+ | #patch to minetest/world/ | ||
+ | MT_WORLD="$(echo "$WORLD" | awk 'BEGIN { FS = "/"; OFS = "/" } {$(NF-1)=""; print$0}' | rev | cut -c2- | rev)" | ||
+ | #patch and name of backup file | ||
+ | BACKUP_TGZ="$BACKUP$NAME$NOW.tar.gz" | ||
+ | #name of backup file | ||
+ | TGZ="$NAME$NOW.tar.gz" | ||
+ | #path and name of output map image | ||
+ | MAP_OUT="$MAP_DIR$NAME$NOW.png" | ||
+ | #name of output map image | ||
+ | MAP="$NAME$NOW.png" | ||
+ | #patch and name of logfile | ||
+ | LOGFILE="$LOGS$NAME$NOW.txt" | ||
+ | |||
+ | #debug of variables | ||
+ | #echo WORLD $WORLD | ||
+ | #echo MINETEST $MINETEST | ||
+ | #echo BACKUP $BACKUP | ||
+ | #echo MAP_DIR $MAP_DIR | ||
+ | #echo MAPPER $MAPPER | ||
+ | #echo LOGS $LOGS | ||
+ | #echo NOW $NOW | ||
+ | #echo NAME $NAME | ||
+ | #echo MT_WORLD $MT_WORLD | ||
+ | #echo BACKUP_TGZ $BACKUP_TGZ | ||
+ | #echo TGZ $TGZ | ||
+ | #echo MAP_OUT $MAP_OUT | ||
+ | #echo MAP $MAP | ||
+ | #echo LOGFILE $LOGFILE | ||
+ | |||
+ | #date and time when job started | ||
+ | echo "Script started at time" $NOW | ||
+ | |||
+ | #backup of world to *tar.gz in backup directory | ||
+ | cd $MT_WORLD ; tar cfz $BACKUP_TGZ $NAME ; cd - &> /dev/null | ||
+ | #symbolic link to $BACKUP$NAME-latest.tar.gz | ||
+ | cd $BACKUP ; ln -sf $TGZ $NAME-latest.tar.gz ; cd - &> /dev/null | ||
+ | |||
+ | #check if mapper is ready | ||
+ | if [ -x "$MAPPER/minetest_mapper" ] ; then | ||
+ | #do a map | ||
+ | $MAPPER/minetest_mapper --draworigin --geometry -3000:-3000+6000+6000 -i $WORLD -o $MAP_OUT >> /opt/minetest-data/logs/minetest_start/minetest_start.log 2>&1 | ||
+ | #symbolic link to $MAP_DIR$NAME-latest.png | ||
+ | cd $MAP_DIR ; ln -sf $MAP $NAME-latest.png ; cd - &> /dev/null | ||
+ | |||
+ | else | ||
+ | |||
+ | echo "minetest_mapper is not ready" | ||
+ | |||
+ | fi | ||
+ | |||
+ | #run minetestserver | ||
+ | $MINETEST/bin/minetestserver &> $LOGFILE & | ||
</file> | </file> |