[17] | 1 | #!/bin/bash
|
---|
| 2 |
|
---|
| 3 | # Tries to start the 7dtd instance.
|
---|
| 4 |
|
---|
| 5 | sdtdCommandStart() {
|
---|
| 6 | if [ "$1" = "!" ]; then
|
---|
| 7 | echo "Starting all instances:"
|
---|
| 8 | for I in $(getInstanceList); do
|
---|
| 9 | printf "%-*s: " 10 "$I"
|
---|
| 10 | sdtdCommandStart $I
|
---|
| 11 | done
|
---|
| 12 | echo "All done"
|
---|
| 13 | return
|
---|
| 14 | fi
|
---|
| 15 |
|
---|
| 16 | if [ $(isValidInstance $1) -eq 0 ]; then
|
---|
| 17 | echo "No instance given or not a valid instance!"
|
---|
| 18 | return
|
---|
| 19 | fi
|
---|
| 20 |
|
---|
| 21 | if [ $(isRunning $1) -eq 0 ]; then
|
---|
[66] | 22 | # Kill monitor if it is still running
|
---|
| 23 | if [ -f "$(getInstancePath $1)/monitor.pid" ]; then
|
---|
| 24 | $PKILL -TERM -P $(cat $(getInstancePath $1)/monitor.pid)
|
---|
| 25 | rm $(getInstancePath $1)/monitor.pid
|
---|
| 26 | fi
|
---|
| 27 |
|
---|
[67] | 28 | if [ ! -d "$(getInstancePath $1)/logs" ]; then
|
---|
| 29 | mkdir "$(getInstancePath $1)/logs"
|
---|
| 30 | fi
|
---|
[70] | 31 | chown $SDTD_USER.$SDTD_GROUP "$(getInstancePath $1)/logs"
|
---|
[67] | 32 | rm -f $(getInstancePath $1)/logs/output_log.txt
|
---|
[17] | 33 |
|
---|
[20] | 34 | for H in $(getHooksFor serverPreStart); do
|
---|
| 35 | $H $INSTANCE
|
---|
| 36 | done
|
---|
| 37 |
|
---|
[17] | 38 | SSD_PID="--pidfile $(getInstancePath $1)/7dtd.pid --make-pidfile"
|
---|
| 39 | SSD_DAEMON="--background --no-close"
|
---|
| 40 | SSD_USER="--chuid $SDTD_USER:$SDTD_GROUP --user $SDTD_USER"
|
---|
[67] | 41 | OPTS="-logfile $(getInstancePath $1)/logs/output_log.txt -configfile=$(getInstancePath $1)/config.xml -dedicated"
|
---|
[17] | 42 |
|
---|
[72] | 43 | LD_LIBRARY_PATH=$SDTD_BASE/linux_files LC_ALL=C $SSD --start $SSD_PID $SSD_DAEMON $SSD_USER --chdir $SDTD_BASE/engine --exec $SDTD_BASE/engine/7DaysToDie.x86 -- $OPTS > $(getInstancePath $1)/logs/stdout.log 2>&1
|
---|
[17] | 44 | sleep 1
|
---|
[20] | 45 |
|
---|
| 46 | for H in $(getHooksFor serverPostStart); do
|
---|
| 47 | $H $INSTANCE
|
---|
| 48 | done
|
---|
| 49 |
|
---|
[17] | 50 | if [ $(isRunning $1) -eq 1 ]; then
|
---|
| 51 | SSD_MONITOR_PID="--pidfile $(getInstancePath $1)/monitor.pid --make-pidfile"
|
---|
| 52 | SSD_MONITOR_DAEMON="--background"
|
---|
[25] | 53 | $SSD --start $SSD_MONITOR_PID $SSD_MONITOR_DAEMON --exec "/usr/local/lib/7dtd/monitor-log.sh" -- "$1"
|
---|
[17] | 54 | echo "Done!"
|
---|
| 55 | else
|
---|
| 56 | echo "Failed!"
|
---|
| 57 | rm -f $(getInstancePath $1)/7dtd.pid
|
---|
| 58 | fi
|
---|
| 59 | else
|
---|
| 60 | echo "Instance $1 is already running"
|
---|
| 61 | fi
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | sdtdCommandStartHelp() {
|
---|
| 65 | echo "Usage: $(basename $0) start <instance>"
|
---|
| 66 | echo
|
---|
| 67 | echo "Starts the given instance."
|
---|
| 68 | echo "If <instance> is \"!\" all defined instances are started."
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | sdtdCommandStartDescription() {
|
---|
| 72 | echo "Start the given instance"
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | sdtdCommandStartExpects() {
|
---|
| 76 | case $1 in
|
---|
| 77 | 2)
|
---|
| 78 | echo "! $(getInstanceList)"
|
---|
| 79 | ;;
|
---|
| 80 | esac
|
---|
| 81 | }
|
---|
| 82 |
|
---|