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

Last change on this file since 60 was 46, checked in by alloc, 10 years ago

Telnet command fix

File size: 1.6 KB
Line 
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
29 for H in $(getHooksFor serverPreStop); do
30 $H $INSTANCE
31 done
32
33 echo "Trying to gracefully shutdown..."
34 tmp=$(telnetCommand $1 shutdown "0.5")
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..."
47 $SSD --stop --pidfile $(getInstancePath $1)/7dtd.pid
48 fi
49
50 $PKILL -TERM -P $(cat $(getInstancePath $1)/monitor.pid)
51 rm $(getInstancePath $1)/monitor.pid
52 setAllPlayersOffline $1
53
54 rm $(getInstancePath $1)/7dtd.pid
55
56 for H in $(getHooksFor serverPostStop); do
57 $H $INSTANCE
58 done
59
60 echo "Done"
61 else
62 echo "Instance $1 is NOT running"
63 fi
64}
65
66sdtdCommandKillHelp() {
67 echo "Usage: $(basename $0) kill <instance>"
68 echo
69 echo "Stops the given instance."
70 echo "If <instance> is \"!\" all defined instances are stopped."
71}
72
73sdtdCommandKillDescription() {
74 echo "Stop the given instance"
75}
76
77sdtdCommandKillExpects() {
78 case $1 in
79 2)
80 echo "! $(getInstanceList)"
81 ;;
82 esac
83}
84
Note: See TracBrowser for help on using the repository browser.