-
Notifications
You must be signed in to change notification settings - Fork 7
Introduce a scheduler job to delete old files that may accumulate over time #510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
d14c99e
8a590a5
354e74c
2d198e8
84b0ef6
796766e
d39494c
1059ffe
6b5483e
fa3e1c2
f0192f4
fe202df
4eff78d
26e0595
7585d55
03d5963
90bd59f
279b841
f36262f
af633e4
2e4dd81
e61d833
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,12 @@ export THREDDS_DATASET_DATASETSCAN_BODY=' | |
| </filter> | ||
| ' | ||
|
|
||
| export THREDDS_DELETE_FILES_OLDER_THAN_DAYS= | ||
| export SCHEDULER_JOB_CLEAN_OLD_FILES_OPTIONS=" | ||
| ${SCHEDULER_JOB_CLEAN_OLD_FILES_OPTIONS} | ||
| \$([ -n \"\${THREDDS_DELETE_FILES_OLDER_THAN_DAYS}\" ] && echo \"thredds_persistence:/thredds|/thredds/logs/threddsServlet.*.log|\${THREDDS_DELETE_FILES_OLDER_THAN_DAYS}\") | ||
|
||
| " | ||
|
|
||
| # add any new variables not already in 'VARS' or 'OPTIONAL_VARS' that must be replaced in templates here | ||
| VARS=" | ||
| $VARS | ||
|
|
||
mishaschwartz marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| config.yml |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/bin/sh | ||
|
|
||
| ################################################################ | ||
| # Deletes old files as determined by the CLEAN_OLD_FILES_OPTIONS | ||
| # environment variable. | ||
| # | ||
| # This variable contains space delimited fields, each | ||
| # representing a group of files to be deleted. | ||
| # The format of these fields are as follows: | ||
| # | ||
| # <docker-volume-mounts>|<find-location>|<age-in-days> | ||
| # | ||
| # - docker-volume-mounts is not used by this script | ||
| # - find-location is an argument passed to `find` which will | ||
| # recursively search for files to delete based on that argument | ||
| # - age-in-days is an integer that represents a number of days, | ||
| # all files found by `find` that were modified more than this | ||
| # number of days ago will be deleted | ||
| # | ||
| # Example call to delete all files in /tmp older than 20 days and | ||
| # all files in /var/log older than 90 days: | ||
| # | ||
| # $ export CLEAN_OLD_FILES_OPTIONS='xxx|/tmp|20 yyy|/var/log|90' | ||
| # $ sh clean-old-files.sh | ||
| ################################################################## | ||
|
|
||
|
|
||
| for opt in ${CLEAN_OLD_FILES_OPTIONS}; do | ||
| loc="$(echo $opt | cut -d\| -f 2)" | ||
| age="$(echo $opt | cut -d\| -f 3)" | ||
| echo "Removing files in ${loc} that have not been modified in ${age} days" | ||
| [ -n "$loc" ] && [ -n "$age" ] && find ${loc} -type f -mtime +"${age}" -print -delete | ||
| done |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| - name: clean_old_files | ||
| comment: clean old files generated by the stack | ||
| schedule: '${SCHEDULER_JOB_CLEAN_OLD_FILES_FREQUENCY}' | ||
| command: 'bash /clean-old-files.sh' | ||
| dockerargs: >- | ||
| --rm --name scheduler-job-clean_old_files | ||
| --volume ${COMPOSE_DIR}/optional-components/scheduler-job-clean_old_files/clean-old-files.sh:/clean-old-files.sh:ro | ||
| --env CLEAN_OLD_FILES_OPTIONS="${SCHEDULER_JOB_CLEAN_OLD_FILES_OPTIONS}" ${SCHEDULER_JOB_CLEAN_OLD_FILES_VOLUMES} | ||
| image: '${SCHEDULER_JOB_CLEAN_OLD_FILES_IMAGE}' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| services: | ||
| scheduler: | ||
| volumes: | ||
| - ./optional-components/scheduler-job-clean_old_files/config.yml:/scheduler-job-configs/clean_old_files.yml:ro |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| export SCHEDULER_JOB_CLEAN_OLD_FILES_IMAGE='${BASH_IMAGE}' | ||
|
|
||
| export SCHEDULER_JOB_CLEAN_OLD_FILES_FREQUENCY="5 2 * * 0" # weekly on Sunday at 2:05 | ||
|
|
||
| export SCHEDULER_JOB_CLEAN_OLD_FILES_VOLUMES='$(for opt in ${SCHEDULER_JOB_CLEAN_OLD_FILES_OPTIONS}; do printf " --volume %s:rw " "$(echo $opt | cut -d\| -f 1)"; done)' | ||
|
||
|
|
||
| export DELAYED_EVAL=" | ||
| $DELAYED_EVAL | ||
| SCHEDULER_JOB_CLEAN_OLD_FILES_IMAGE | ||
| SCHEDULER_JOB_CLEAN_OLD_FILES_OPTIONS | ||
| SCHEDULER_JOB_CLEAN_OLD_FILES_VOLUMES | ||
| " | ||
|
|
||
| OPTIONAL_VARS=" | ||
| $OPTIONAL_VARS | ||
| \$SCHEDULER_JOB_CLEAN_OLD_FILES_OPTIONS | ||
| \$SCHEDULER_JOB_CLEAN_OLD_FILES_VOLUMES | ||
| " | ||
|
|
||
| VARS=" | ||
| $VARS | ||
| \$SCHEDULER_JOB_CLEAN_OLD_FILES_IMAGE | ||
| \$SCHEDULER_JOB_CLEAN_OLD_FILES_FREQUENCY | ||
| " | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| if [ -z "$SCHEDULER_JOB_CLEAN_OLD_FILES_OPTIONS" ]; then | ||
| log WARN 'The scheduler-job-clean_old_files component is enabled but no files are scheduled to be deleted. Please reconfigure this component or disable it.' | ||
| fi |
Uh oh!
There was an error while loading. Please reload this page.