Changeset 14 for scripts/usr/local/bin


Ignore:
Timestamp:
May 17, 2014, 6:01:31 PM (11 years ago)
Author:
alloc
Message:

More instance validation, switch to XMLStarlet, config.xml instead of serverconfig.xml, admins.xml instead of serveradmin.xml

Location:
scripts/usr/local/bin
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • scripts/usr/local/bin/7dtd-backup.sh

    r10 r14  
    11#!/bin/bash
    2 # Version 1
     2# Version 3
    33. /etc/7dtd.conf
    44
  • scripts/usr/local/bin/7dtd-common.sh

    r13 r14  
    11#!/bin/bash
    2 # Version 2
     2# Version 3
    33
    44# Provides common functions for 7dtd-scripts. Not intended to be run directly.
     
    2323
    2424# Check if the given instance name is an existing instance
    25 # On failure exit the script!
    2625# Params:
    2726#   1: Instance name
    28 checkInstance() {
     27# Returns:
     28#   0/1 instance not valid/valid
     29isValidInstance() {
    2930        if [ -z $1 ]; then
    30                 echo "No instance given!"
    31                 exit 2
     31                echo 0
     32        else
     33                if [ ! -d $(getInstancePath $1) ]; then
     34                        echo 0
     35                else
     36                        if [ ! -f $(getInstancePath $1)/config.xml ]; then
     37                                echo 0
     38                        else
     39                                echo 1
     40                        fi
     41                fi
    3242        fi
    33         if [ ! -d $(getInstancePath $1) ]; then
    34                 echo "Instance $1 does not exist!"
    35                 exit 3
     43}
     44
     45# Check if the given instance is valid, exit the script otherwise
     46# Params:
     47#   1: instance name
     48checkInstanceValid() {
     49        if [ -z $1 ]; then
     50                echo "Missing parameter <instance>"
     51                exit 1
     52        fi
     53        if [ $(isValidInstance $1) -eq 0 ]; then
     54                echo "'$1' is not a valid instance"
     55                exit 1
    3656        fi
    3757}
     
    5070                echo 0
    5171        fi
     72}
     73
     74# Get list of defined instances
     75# Returns:
     76#   List of instances
     77getInstanceList() {
     78        for IF in $SDTD_BASE/instances/*; do
     79                I=`basename $IF`
     80                if [ $(isValidInstance $I) -eq 1 ]; then
     81                        echo $I
     82                fi
     83        done
    5284}
    5385
     
    74106#   Property value
    75107getConfigValue() {
    76         CONF=$(getInstancePath $1)/serverconfig.xml
    77         xmllint --xpath "string(/ServerSettings/property[@name='$2']/@value)" $CONF
     108        CONF=$(getInstancePath $1)/config.xml
     109        xmlstarlet sel -t -v "/ServerSettings/property[@name='$2']/@value" $CONF
    78110}
    79111
  • scripts/usr/local/bin/7dtd-instances.sh

    r13 r14  
    11#!/bin/bash
    2 # Version 2
     2# Version 3
    33
    44# Lists available 7dtd instances.
     
    1313        printf -v line "%*s-+-%*s-+-%*s-+-%*s\n" 20 " " 8 " " 7 " " 5 " "
    1414        echo ${line// /-}
    15         for I in $SDTD_BASE/instances/*; do
    16                 ins=`basename $I`
    17                 run=$(isRunning $ins)
     15        for I in $(getInstanceList); do
     16                run=$(isRunning $I)
    1817                if [ $run -eq 1 ]; then
    1918                        run="yes"
    20                         tel=$(telnetCommand $ins lp)
     19                        tel=$(telnetCommand $I lp)
    2120                        cur=`echo $tel | sed "s/\r/\n/g" | sed "s/^ //g" | grep "Total of " | cut -d\  -f 3`
    2221                else
    2322                        run="no"
    24                         cur=0
     23                        cur="-"
    2524                fi
    2625
    27                 max=$(getConfigValue $ins ServerMaxPlayerCount)
    28                 port=$(getConfigValue $ins ServerPort)
     26                max=$(getConfigValue $I ServerMaxPlayerCount)
     27                port=$(getConfigValue $I ServerPort)
    2928
    30                 printf "%-*s | %*s |   %2d/%2d | %5d\n" 20 "$ins" 8 "$run" $cur $max $port
     29                printf "%-*s | %*s |   %2s/%2d | %5d\n" 20 "$I" 8 "$run" $cur $max $port
    3130        done
    3231        exit 0
     
    3433
    3534showInfo() {
    36         if [ -z $1 ]; then
    37                 echo "Missing parameter <instance>"
    38                 exit 1
    39         fi
    40         checkInstance $1
     35        checkInstanceValid $1
    4136
    4237        line() {
  • scripts/usr/local/bin/7dtd-kill.sh

    r11 r14  
    11#!/bin/bash
    2 # Version 1
     2# Version 3
    33
    44# Tries to stop the 7dtd instance given as first parameter.
     
    1212checkRootLoadConf
    1313
    14 checkInstance $1
     14checkInstanceValid $1
    1515
    1616res=$(isRunning $1)
    1717if [ $res -eq 1 ]; then
    18         telnetCommand $1 shutdown
    19         sleep 1
    20         res=$(isRunning $1)
    21         if [ $res -eq 1 ]; then
     18        echo "Trying to gracefully shutdown..."
     19        tmp=$(telnetCommand $1 shutdown)
     20        echo "Waiting for server to shut down..."
     21       
     22        waittime=0
     23        maxwait=5
     24        until [ $(isRunning $1) -eq 0 ] || [ $waittime -eq $maxwait ]; do
     25                (( waittime++ ))
     26                sleep 1
     27                echo $waittime/$maxwait
     28        done
     29       
     30        if [ $(isRunning $1) -eq 1 ]; then
     31                echo "Failed, force closing server..."
    2232                start-stop-daemon --stop --pidfile $(getInstancePath $1)/7dtd.pid
    2333        fi
  • scripts/usr/local/bin/7dtd-running.sh

    r10 r14  
    11#!/bin/bash
    2 # Version 1
     2# Version 3
    33
    44# Checks if the 7dtd instance given as first parameter is running.
     
    1212checkRootLoadConf
    1313
    14 checkInstance $1
     14checkInstanceValid $1
    1515
    1616res=$(isRunning $1)
  • scripts/usr/local/bin/7dtd-start.sh

    r12 r14  
    11#!/bin/bash
    2 # Version 1
     2# Version 3
    33
    44# Tries to start the 7dtd instance given as first parameter.
     
    1313checkRootLoadConf
    1414
    15 checkInstance $1
     15checkInstanceValid $1
    1616
    1717res=$(isRunning $1)
     
    2727        SSD_DAEMON="--background --no-close"
    2828        SSD_USER="--chuid $SDTD_USER:$SDTD_GROUP --user $SDTD_USER"
    29         OPTS="-quit -batchmode -nographics -configfile=$(getInstancePath $1)/serverconfig.xml -dedicated"
     29        OPTS="-quit -batchmode -nographics -configfile=$(getInstancePath $1)/config.xml -dedicated"
    3030       
    3131        start-stop-daemon --start $SSD_PID $SSD_DAEMON $SSD_USER --chdir $SDTD_ROOT --exec $WINE -- $SDTD_ROOT/7DaysToDie.exe $OPTS > $(getInstancePath $1)/stdout.log 2>&1
  • scripts/usr/local/bin/7dtd-update.sh

    r10 r14  
    11#!/bin/bash
    2 # Version 1
     2# Version 3
    33
    44. /usr/local/bin/7dtd-common.sh
Note: See TracChangeset for help on using the changeset viewer.