Skip to content

Commit

Permalink
Merge pull request #28 from cfortier2/fix/docker-cleanup
Browse files Browse the repository at this point in the history
Convert docker-cleanup to a script for easier maintainability
  • Loading branch information
cfortier2 committed Jul 30, 2015
2 parents 1b610cd + a4374dd commit 7196c98
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
12 changes: 1 addition & 11 deletions v1/fleet_units/docker-cleanup.service
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,7 @@ User=core
Restart=on-failure
RestartSec=20
TimeoutStartSec=0
ExecStart=/usr/bin/sh -c ' \
if [[ $(/usr/bin/docker ps -a | grep Exited | awk \'{print $1 "\\t" $7 "\\t" $10}\' | grep week | wc -l) -ne 0 ]]; \
then \
echo "Starting docker cleanup with a max of: $MAX_DOCKER"; \
/usr/bin/docker ps -a | grep Exited | awk \'{print $1 "\\t" $7 "\\t" $10}\' | grep week | awk \'{print $1}\' | head -n $MAX_DOCKER | xargs /usr/bin/docker rm -v ; \
/usr/bin/docker images -a | grep none | awk \'{print $3}\' | xargs /usr/bin/docker rmi ; \
echo "cleanup complete"; \
else \
echo "nothing to cleanup"; \
fi
sudo free -h'
ExecStart=/usr/bin/bash -c '/usr/bin/wget -O /home/core/docker-cleanup.sh https://raw.githubusercontent.com/behance/mesos-systemd/fix/docker-cleanup/v1/fleet_units/docker-cleanup.sh && /usr/bin/bash /home/core/docker-cleanup.sh'

[X-Fleet]
Global=true
Expand Down
14 changes: 14 additions & 0 deletions v1/fleet_units/docker-cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# this exists because trying to escape bash commands in a sytemd unit is super sadtimes

if [[ $(/usr/bin/docker ps -a | grep Exited | awk '{print $1 "\\t" $7 "\\t" $10}' | grep week | wc -l) -ne 0 ]]
then
echo "Starting docker cleanup with a max of: $MAX_DOCKER"
/usr/bin/docker ps -a | grep Exited | awk '{print $1 "\\t" $7 "\\t" $10}' | grep week | awk '{print $1}' | head -n $MAX_DOCKER | xargs /usr/bin/docker rm -v
/usr/bin/docker images -a | grep none | awk '{print $3}' | xargs /usr/bin/docker rmi
echo "cleanup complete"
else
echo "nothing to cleanup"
fi
sudo free -h

0 comments on commit 7196c98

Please sign in to comment.