source: scripts/usr/local/lib/7dtd/commands/start.sh@ 231

Last change on this file since 231 was 219, checked in by alloc, 10 years ago

scripts 71

File size: 2.2 KB
RevLine 
[17]1#!/bin/bash
2
3# Tries to start the 7dtd instance.
4
5sdtdCommandStart() {
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
[204]35 $H $1
[20]36 done
37
[219]38 LOG=$(getInstancePath $1)/logs/$(date '+%Y-%m-%d_%H-%M-%S')_output_log.txt
[17]39 SSD_PID="--pidfile $(getInstancePath $1)/7dtd.pid --make-pidfile"
40 SSD_DAEMON="--background --no-close"
41 SSD_USER="--chuid $SDTD_USER:$SDTD_GROUP --user $SDTD_USER"
[219]42 OPTS="-logfile $LOG -configfile=$(getInstancePath $1)/config.xml"
[17]43
[207]44 LC_ALL=C LD_LIBRARY_PATH=$SDTD_BASE/engine $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]45 sleep 1
[20]46
47 for H in $(getHooksFor serverPostStart); do
[204]48 $H $1
[20]49 done
50
[17]51 if [ $(isRunning $1) -eq 1 ]; then
52 SSD_MONITOR_PID="--pidfile $(getInstancePath $1)/monitor.pid --make-pidfile"
53 SSD_MONITOR_DAEMON="--background"
[219]54 $SSD --start $SSD_MONITOR_PID $SSD_MONITOR_DAEMON --exec "/usr/local/lib/7dtd/monitor-log.sh" -- "$1" "$LOG"
[17]55 echo "Done!"
56 else
57 echo "Failed!"
58 rm -f $(getInstancePath $1)/7dtd.pid
59 fi
60 else
61 echo "Instance $1 is already running"
62 fi
63}
64
65sdtdCommandStartHelp() {
66 echo "Usage: $(basename $0) start <instance>"
67 echo
68 echo "Starts the given instance."
69 echo "If <instance> is \"!\" all defined instances are started."
70}
71
72sdtdCommandStartDescription() {
73 echo "Start the given instance"
74}
75
76sdtdCommandStartExpects() {
77 case $1 in
78 2)
79 echo "! $(getInstanceList)"
80 ;;
81 esac
82}
83
Note: See TracBrowser for help on using the repository browser.