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

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

v.26: Fixed stop-script

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