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

Last change on this file since 22 was 20, checked in by alloc, 11 years ago

Version 5. Fixes #9, #11

File size: 1.6 KB
RevLine 
[17]1#!/bin/bash
[20]2# Version 5
[17]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
[20]30 for H in $(getHooksFor serverPreStop); do
31 $H $INSTANCE
32 done
33
[17]34 echo "Trying to gracefully shutdown..."
35 tmp=$(telnetCommand $1 shutdown)
36 echo "Waiting for server to shut down..."
37
38 waittime=0
39 maxwait=5
40 until [ $(isRunning $1) -eq 0 ] || [ $waittime -eq $maxwait ]; do
41 (( waittime++ ))
42 sleep 1
43 echo $waittime/$maxwait
44 done
45
46 if [ $(isRunning $1) -eq 1 ]; then
47 echo "Failed, force closing server..."
48 start-stop-daemon --stop --pidfile $(getInstancePath $1)/7dtd.pid
49 fi
50
[18]51 $PKILL -TERM -P $(cat $(getInstancePath $1)/monitor.pid)
[17]52 rm $(getInstancePath $1)/monitor.pid
53 setAllPlayersOffline $1
54
55 rm $(getInstancePath $1)/7dtd.pid
[20]56
57 for H in $(getHooksFor serverPostStop); do
58 $H $INSTANCE
59 done
60
[17]61 echo "Done"
62 else
63 echo "Instance $1 is NOT running"
64 fi
65}
66
67sdtdCommandKillHelp() {
68 echo "Usage: $(basename $0) kill <instance>"
69 echo
70 echo "Stops the given instance."
71 echo "If <instance> is \"!\" all defined instances are stopped."
72}
73
74sdtdCommandKillDescription() {
75 echo "Stop the given instance"
76}
77
78sdtdCommandKillExpects() {
79 case $1 in
80 2)
81 echo "! $(getInstanceList)"
82 ;;
83 esac
84}
85
Note: See TracBrowser for help on using the repository browser.