-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshutdown
executable file
·67 lines (53 loc) · 1.47 KB
/
shutdown
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env bash
set -e
ENVFILE="$(dirname $(realpath $0))/setenv"
if [[ -f $ENVFILE ]]; then
. $ENVFILE
fi
VERBOSE=false
usage() { echo "$0 usage: $0 [-c] [-v] [-h] [GROUP NAME]"; }
usage_long() {
echo " -c clean up everything, including images and networks"
echo " -v enable verbose output"
echo " -h show this help"
}
while getopts ':hcv' OPTION; do
case "$OPTION" in
c)
CLEAN=1
;;
v)
VERBOSE=true
;;
h)
usage
usage_long
exit 0
;;
?)
usage
usage_long
exit 1
;;
esac
done
if ! [ -x "$(command -v podman)" ]; then
echo "podman is not installed" >&2
exit 1
fi
RUNNING_PODS=$(podman ps -a --filter=label=$LABEL.version --format {{.ID}})
if [[ -n $RUNNING_PODS ]]; then
$VERBOSE && echo -n "Stopping containers... "
MSG=$(podman rm -f $RUNNING_PODS)
[[ $? -eq 0 ]] && $VERBOSE && echo OK || echo $MSG
fi
if [[ -n $CLEAN ]]; then
if [[ -n $(podman network ls -f "name=$NETWORK" --format {{.ID}}) ]]; then
$VERBOSE && echo -n "Removing network... "
podman network rm $NETWORK > /dev/null
[[ $? -eq 0 ]] && $VERBOSE && echo OK
fi
$VERBOSE && echo -n "Removing image... "
podman image rm $(podman image list --filter label=$LABEL.version=$VERSION --format {{.ID}}) > /dev/null
[[ $? -eq 0 ]] && $VERBOSE && echo OK
fi