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

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

Scripts: License

File size: 2.8 KB
Line 
1#!/bin/bash
2
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
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
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
43 if [ ! -d "$(getInstancePath $1)/logs" ]; then
44 mkdir "$(getInstancePath $1)/logs"
45 fi
46 chown $SDTD_USER.$SDTD_GROUP "$(getInstancePath $1)/logs"
47 rm -f $(getInstancePath $1)/logs/output_log.txt
48
49 for H in $(getHooksFor serverPreStart); do
50 $H $1
51 done
52
53 LOGTIMESTAMP=$(date '+%Y-%m-%d_%H-%M-%S')
54 LOG=$(getInstancePath $1)/logs/${LOGTIMESTAMP}_output_log.txt
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"
58 OPTS="-logfile $LOG -configfile=$(getInstancePath $1)/config.xml"
59
60 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
61 sleep 1
62
63 for H in $(getHooksFor serverPostStart); do
64 $H $1
65 done
66
67 if [ $(isRunning $1) -eq 1 ]; then
68 SSD_MONITOR_PID="--pidfile $(getInstancePath $1)/monitor.pid --make-pidfile"
69 SSD_MONITOR_DAEMON="--background"
70 $SSD --start $SSD_MONITOR_PID $SSD_MONITOR_DAEMON --exec "/usr/local/lib/7dtd/monitor-log.sh" -- "$1" "$LOGTIMESTAMP"
71 echo "Done!"
72 else
73 echo "Failed!"
74 rm -f $(getInstancePath $1)/7dtd.pid
75 fi
76 else
77 echo "Instance $1 is already running"
78 fi
79}
80
81sdtdCommandStartHelp() {
82 echo "Usage: $(basename $0) start <instance>"
83 echo
84 echo "Starts the given instance."
85 echo "If <instance> is \"!\" all defined instances are started."
86}
87
88sdtdCommandStartDescription() {
89 echo "Start the given instance"
90}
91
92sdtdCommandStartExpects() {
93 case $1 in
94 2)
95 echo "! $(getInstanceList)"
96 ;;
97 esac
98}
99
Note: See TracBrowser for help on using the repository browser.