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

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

v97

File size: 2.9 KB
RevLine 
[17]1#!/bin/bash
2
[258]3# Copyright 2016 Christian 'Alloc' Illy
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17
[17]18# Tries to start the 7dtd instance.
19
20sdtdCommandStart() {
21 if [ "$1" = "!" ]; then
22 echo "Starting all instances:"
23 for I in $(getInstanceList); do
24 printf "%-*s: " 10 "$I"
25 sdtdCommandStart $I
26 done
27 echo "All done"
28 return
29 fi
30
31 if [ $(isValidInstance $1) -eq 0 ]; then
32 echo "No instance given or not a valid instance!"
33 return
34 fi
35
36 if [ $(isRunning $1) -eq 0 ]; then
[66]37 # Kill monitor if it is still running
38 if [ -f "$(getInstancePath $1)/monitor.pid" ]; then
39 $PKILL -TERM -P $(cat $(getInstancePath $1)/monitor.pid)
40 rm $(getInstancePath $1)/monitor.pid
41 fi
42
[67]43 if [ ! -d "$(getInstancePath $1)/logs" ]; then
44 mkdir "$(getInstancePath $1)/logs"
45 fi
[70]46 chown $SDTD_USER.$SDTD_GROUP "$(getInstancePath $1)/logs"
[67]47 rm -f $(getInstancePath $1)/logs/output_log.txt
[17]48
[259]49 for H in $(getHooksFor serverPreStart $1); do
[204]50 $H $1
[20]51 done
52
[240]53 LOGTIMESTAMP=$(date '+%Y-%m-%d_%H-%M-%S')
54 LOG=$(getInstancePath $1)/logs/${LOGTIMESTAMP}_output_log.txt
[17]55 SSD_PID="--pidfile $(getInstancePath $1)/7dtd.pid --make-pidfile"
56 SSD_DAEMON="--background --no-close"
57 SSD_USER="--chuid $SDTD_USER:$SDTD_GROUP --user $SDTD_USER"
[219]58 OPTS="-logfile $LOG -configfile=$(getInstancePath $1)/config.xml"
[17]59
[261]60 if [ "$(uname -m)" = "x86_64" ]; then
61 SERVER_EXE="7DaysToDieServer.x86_64"
62 else
[259]63 SERVER_EXE="7DaysToDieServer.x86"
[261]64 fi
[259]65
66
67 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/$SERVER_EXE -- $OPTS > $(getInstancePath $1)/logs/stdout.log 2>&1
[17]68 sleep 1
[20]69
[259]70 for H in $(getHooksFor serverPostStart $1); do
[204]71 $H $1
[20]72 done
73
[17]74 if [ $(isRunning $1) -eq 1 ]; then
75 SSD_MONITOR_PID="--pidfile $(getInstancePath $1)/monitor.pid --make-pidfile"
76 SSD_MONITOR_DAEMON="--background"
[240]77 $SSD --start $SSD_MONITOR_PID $SSD_MONITOR_DAEMON --exec "/usr/local/lib/7dtd/monitor-log.sh" -- "$1" "$LOGTIMESTAMP"
[17]78 echo "Done!"
79 else
80 echo "Failed!"
81 rm -f $(getInstancePath $1)/7dtd.pid
82 fi
83 else
84 echo "Instance $1 is already running"
85 fi
86}
87
88sdtdCommandStartHelp() {
89 echo "Usage: $(basename $0) start <instance>"
90 echo
91 echo "Starts the given instance."
92 echo "If <instance> is \"!\" all defined instances are started."
93}
94
95sdtdCommandStartDescription() {
96 echo "Start the given instance"
97}
98
99sdtdCommandStartExpects() {
100 case $1 in
101 2)
102 echo "! $(getInstanceList)"
103 ;;
104 esac
105}
106
Note: See TracBrowser for help on using the repository browser.