Skip to content

Commit

Permalink
handling a pid so that docker-gc will run only once at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
theonlydoo committed Aug 7, 2015
1 parent 2cf984e commit 7fc4110
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docker-gc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ set -o errexit
GRACE_PERIOD_SECONDS=${GRACE_PERIOD_SECONDS:=3600}
STATE_DIR=${STATE_DIR:=/var/lib/docker-gc}
DOCKER=${DOCKER:=docker}
PID_DIR=${PID_DIR:=/var/run}

for pid in $(pidof -x docker-gc); do
if [[ $pid != $$ ]]; then
echo "[$(date)] : docker-gc : Process is already running with PID $pid"
exit 1
fi
done

trap "rm -f -- '$PID_DIR/dockergc'" EXIT

echo $$ > $PID_DIR/dockergc


EXCLUDE_FROM_GC=${EXCLUDE_FROM_GC:=/etc/docker-gc-exclude}
if [ ! -f "$EXCLUDE_FROM_GC" ]
Expand Down

0 comments on commit 7fc4110

Please sign in to comment.