source: scripts/usr/local/lib/7dtd/commands/stop.sh@ 501

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

v96

File size: 2.2 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 stop the 7dtd instance given as first parameter.
19# Returns:
20# 0 : Done
21# 1 : Was not running
22# 2 : No instance name given
23# 3 : No such instance
24
25sdtdCommandKill() {
26 if [ "$1" = "!" ]; then
27 echo "Stopping all instances:"
28 for I in $(getInstanceList); do
29 printf "%s:\n" "$I"
30 sdtdCommandKill $I
31 echo
32 done
33 echo "All done"
34 return
35 fi
36
37 if [ $(isValidInstance $1) -eq 0 ]; then
38 echo "No instance given or not a valid instance!"
39 return
40 fi
41
42 res=$(isRunning $1)
43 if [ $res -eq 1 ]; then
[259]44 for H in $(getHooksFor serverPreStop $1); do
[204]45 $H $1
[20]46 done
47
[17]48 echo "Trying to gracefully shutdown..."
[46]49 tmp=$(telnetCommand $1 shutdown "0.5")
[17]50 echo "Waiting for server to shut down..."
51
52 waittime=0
[169]53 maxwait=${STOP_WAIT:-5}
[17]54 until [ $(isRunning $1) -eq 0 ] || [ $waittime -eq $maxwait ]; do
55 (( waittime++ ))
56 sleep 1
57 echo $waittime/$maxwait
58 done
59
60 if [ $(isRunning $1) -eq 1 ]; then
61 echo "Failed, force closing server..."
[248]62 $SSD --stop --signal KILL --pidfile $(getInstancePath $1)/7dtd.pid
[17]63 fi
64
[18]65 $PKILL -TERM -P $(cat $(getInstancePath $1)/monitor.pid)
[17]66 rm $(getInstancePath $1)/monitor.pid
67
68 rm $(getInstancePath $1)/7dtd.pid
[20]69
[259]70 for H in $(getHooksFor serverPostStop $1); do
[204]71 $H $1
[20]72 done
73
[17]74 echo "Done"
75 else
76 echo "Instance $1 is NOT running"
77 fi
78}
79
80sdtdCommandKillHelp() {
81 echo "Usage: $(basename $0) kill <instance>"
82 echo
83 echo "Stops the given instance."
84 echo "If <instance> is \"!\" all defined instances are stopped."
85}
86
87sdtdCommandKillDescription() {
88 echo "Stop the given instance"
89}
90
91sdtdCommandKillExpects() {
92 case $1 in
93 2)
94 echo "! $(getInstanceList)"
95 ;;
96 esac
97}
98
Note: See TracBrowser for help on using the repository browser.