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

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

v24: Kill monitor on start of an instance if it is still running from previous session

File size: 2.0 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
[17]28 setAllPlayersOffline $1
[39]29 rm -f $(getInstancePath $1)/output_log.txt
[17]30
[20]31 for H in $(getHooksFor serverPreStart); do
32 $H $INSTANCE
33 done
34
[17]35 SSD_PID="--pidfile $(getInstancePath $1)/7dtd.pid --make-pidfile"
36 SSD_DAEMON="--background --no-close"
37 SSD_USER="--chuid $SDTD_USER:$SDTD_GROUP --user $SDTD_USER"
[35]38 OPTS="-logfile $(getInstancePath $1)/output_log.txt -configfile=$(getInstancePath $1)/config.xml -dedicated"
[17]39
[36]40 LD_LIBRARY_PATH=$SDTD_BASE/linux_files $SSD --start $SSD_PID $SSD_DAEMON $SSD_USER --chdir $SDTD_BASE/engine --exec $SDTD_BASE/engine/7DaysToDie.x86 -- $OPTS > $(getInstancePath $1)/stdout.log 2>&1
[17]41 sleep 1
[20]42
43 for H in $(getHooksFor serverPostStart); do
44 $H $INSTANCE
45 done
46
[17]47 if [ $(isRunning $1) -eq 1 ]; then
48 SSD_MONITOR_PID="--pidfile $(getInstancePath $1)/monitor.pid --make-pidfile"
49 SSD_MONITOR_DAEMON="--background"
[25]50 $SSD --start $SSD_MONITOR_PID $SSD_MONITOR_DAEMON --exec "/usr/local/lib/7dtd/monitor-log.sh" -- "$1"
[17]51 echo "Done!"
52 else
53 echo "Failed!"
54 rm -f $(getInstancePath $1)/7dtd.pid
55 fi
56 else
57 echo "Instance $1 is already running"
58 fi
59}
60
61sdtdCommandStartHelp() {
62 echo "Usage: $(basename $0) start <instance>"
63 echo
64 echo "Starts the given instance."
65 echo "If <instance> is \"!\" all defined instances are started."
66}
67
68sdtdCommandStartDescription() {
69 echo "Start the given instance"
70}
71
72sdtdCommandStartExpects() {
73 case $1 in
74 2)
75 echo "! $(getInstanceList)"
76 ;;
77 esac
78}
79
Note: See TracBrowser for help on using the repository browser.