Skip to content

Commit

Permalink
Fix an issue where you couldn't run 'all' command because the script …
Browse files Browse the repository at this point in the history
…would stop itself
  • Loading branch information
withinboredom committed Aug 8, 2016
1 parent beb3fe4 commit 5ca2d4a
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions docker-clean
Expand Up @@ -269,6 +269,12 @@ function stop {
else
local count=0
echo "Stopping running containers..."

if [ ! -d /proc/1/cgroup ] ; then
self_id=$(grep 'docker/' < /proc/1/cgroup | tail -1 | sed 's/^.*\///' | cut -c 1-12)
echo "Not stopping self: $self_id"
fi

for i in "${runningContainers[@]}"; do
local output
local status
Expand All @@ -278,16 +284,19 @@ function stop {
name="$(docker inspect -f '{{json .Name}}' "$i")"
path="$(docker inspect -f '{{json .Path}}' "$i")"
args="$(docker inspect -f '{{json .Args}}' "$i")"
docker stop "$i" &>/dev/null
status=$?
if [[ $status -eq 0 ]] ; then
count=$((count+1))
output="STOPPED: ID: $i IMAGE: $path/$args NAME: $name"
echo "$output" | log
else
output="COULD NOT STOP: ID: $i IMAGE: $path/$args NAME: $name"
echo "$output" | log
fi
if [ "$i" != "$self_id" ] ; then
docker stop "$i" &>/dev/null

status=$?
if [[ $status -eq 0 ]] ; then
count=$((count+1))
output="STOPPED: ID: $i IMAGE: $path/$args NAME: $name"
echo "$output" | log
else
output="COULD NOT STOP: ID: $i IMAGE: $path/$args NAME: $name"
echo "$output" | log
fi
fi
done
echo "Containers stopped: $count"
fi
Expand Down

0 comments on commit 5ca2d4a

Please sign in to comment.