Skip to content
Snippets Groups Projects
Commit 0dea5220 authored by David Hoese's avatar David Hoese
Browse files

Merge branch 'feature-tmpwatch' into 'master'

Add tmpwatch-like docker image for clearing out a docker volume

See merge request cspp_geo/cspp-geo-web-viewer!3
parents ae952139 7ddbf50b
No related branches found
No related tags found
No related merge requests found
FROM alpine:latest
WORKDIR "/work"
COPY tmpwatch.sh /work/
RUN apk update && apk upgrade && \
apk add findutils && \
rm -rf /var/cache/apk/*
ENTRYPOINT ["/work/tmpwatch.sh"]
\ No newline at end of file
# tmpwatch
Docker container to mimic tmpwatch-like operations. Note this is using the
alpine linux distribution to reduce the size of the image. This container
is not actually using `tmpwatch` but instead a limited version of the
`find` command.
## Usage
To search for files every 7 days (7d) and delete any files older than
6 days (6) run:
```bash
docker -d -v /path/to/watch:/watch tmpwatch 7d 6 /watch
```
Note that the first argument (7d) is passed to the `sleep` command and allows
for (s)econds, (m)inutes, (h)ours, or (d)ays suffixes. The second argument (6)
is passed to the `find` command's `-mtime` flag and must always be number of
days.
If you would like to use access time instead of modified time you can specify
the environment variable `-e TIME_MODE=atime`.
More than one directory can be listed, but since we are running from a
container they must all be mounted.
\ No newline at end of file
#!/bin/sh
if [ $# -lt 2 ]; then
echo "Usage: ./tmpwatch.sh loop_sleep_seconds mtime dirs ..."
exit 1
fi
TIME_MODE=${TIME_MODE:-"mtime"}
sleep_time=$1
mtime=$2
shift 2
# Just keep going
while true; do
echo "`date +"%Y-%m-%d %H:%M:%S"` : Running tmpwatch to remove files older than $mtime days..."
# mindepth 1: don't include the base directories as things to delete
find "$@" -mindepth 1 -"$TIME_MODE" $mtime -delete
echo "`date +"%Y-%m-%d %H:%M:%S"` : Done"
sleep $sleep_time
done
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment