Skip to content

Commit e7e28b7

Browse files
committed
add failure handling to cleaning script
1 parent 8768313 commit e7e28b7

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

clean.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
#!/bin/sh
22

3-
set -e
4-
53
TF_TAG="tinyFaaS"
64
TMP_DIR="tmp"
75

86
# remove old containers, networks and images
97
containers=$(docker ps -a -q --filter label=$TF_TAG)
108

119
if [ -n "$containers" ]; then
12-
docker stop "$containers" > /dev/null
13-
docker rm "$containers" > /dev/null
10+
for container in $containers; do
11+
docker stop "$container" > /dev/null || echo "Failed to stop container $container! Please stop it manually..."
12+
docker rm "$container" > /dev/null || echo "Failed to remove container $container! Please remove it manually..."
13+
done
1414
else
1515
echo "No old containers to remove. Skipping..."
1616
fi
1717

1818
networks=$(docker network ls -q --filter label=$TF_TAG)
1919

2020
if [ -n "$networks" ]; then
21-
docker network rm "$networks" > /dev/null
21+
for network in $networks; do
22+
docker network rm "$network" > /dev/null || echo "Failed to remove network $network! Please remove it manually..."
23+
done
2224
else
2325
echo "No old networks to remove. Skipping..."
2426
fi
@@ -27,17 +29,15 @@ images=$(docker image ls -q --filter label=$TF_TAG)
2729

2830
if [ -n "$images" ]; then
2931
for image in $images; do
30-
docker image rm "$image" > /dev/null
32+
docker image rm "$image" > /dev/null || echo "Failed to remove image $image! Please remove it manually..."
3133
done
3234
else
3335
echo "No old images to remove. Skipping..."
3436
fi
3537

3638
# remove tmp directory
3739
if [ -d "$TMP_DIR" ]; then
38-
rm -rf "$TMP_DIR"
40+
rm -rf "$TMP_DIR" > /dev/null || echo "Failed to remove directory $TMP_DIR ! Please remove it manually..."
3941
else
4042
echo "No tmp directory to remove. Skipping..."
4143
fi
42-
43-
set +e

0 commit comments

Comments
 (0)