-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstop.sh
executable file
·46 lines (37 loc) · 1003 Bytes
/
stop.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
if ! type realpath > /dev/null 2>&1; then
echo "Requires realpath to be installed, which is part of coreutils"
exit 1
fi
SCRIPTPATH=$(realpath "$(dirname "$0")")
if [ -e "${SCRIPTPATH}/config" ]; then
# shellcheck source=config
. "${SCRIPTPATH}/config"
fi
# Number of VMs
NODE_COUNT=${NODE_COUNT:-3}
# Path to VM artifacts
RUN_DIR="${RUN_DIR:-${SCRIPTPATH}/.run}"
# First argument can be the VM index number to work with
if [ -n "${1:-}" ]; then
if [ "${1}" -ge 0 ] && [ "${1}" -lt ${NODE_COUNT} ]; then
START_COUNT=${1}
END_COUNT=${1}
else
echo "Specified VM ${1} isn't within the configured number of VMs"
exit 1
fi
else
START_COUNT=0
END_COUNT=$((NODE_COUNT-1))
fi
SIGNAL=${2:-15}
for i in $(seq "${START_COUNT}" "${END_COUNT}"); do
if [ -e "$RUN_DIR/vms/$i/pid" ]; then
PID="$(cat "$RUN_DIR/vms/$i/pid")"
sudo kill -"${SIGNAL}" "$PID" || echo "Signal $SIGNAL to $PID failed..."
fi
done