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

Last change on this file since 19 was 18, checked in by alloc, 10 years ago

Version 4

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