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

Last change on this file since 249 was 240, checked in by alloc, 9 years ago

Scripts 91

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