Skip to content

Commit 58c8f9e

Browse files
authored
Merge pull request #1792 from Caltech-IPAC/FIREFLY-1778-cleanup-script
FIREFLY-1778: Update the cleanup script so that it only targets its designated work directories
2 parents 0c10faf + 7601706 commit 58c8f9e

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

docker/cleanup.sh

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,19 @@ if ! [[ "${interval}" =~ $allDigitsRE ]] || [ "$mult" -eq 0 ]; then # check fo
3939
fi
4040

4141
cleanupMinutes=$((interval*mult))
42+
logfileMaxAge=$((cleanupMinutes*10+5))
4243

4344
function doCleanup() {
4445
workarea="${1}"
46+
log_dir="${workarea}/cleanup_logs"
47+
mkdir -p "${log_dir}"
48+
49+
# cleanup old log files
50+
${find_cmd} "${log_dir}" -type f -mmin +${logfileMaxAge} -exec /bin/rm '{}' \+
51+
52+
# cleanup old work files
4553
timestamp=$(date +20%y%m%dT%H%M%S)
46-
log_file="${workarea}/cleanup_logs/cleanup.${timestamp}.log"
54+
log_file="${log_dir}/cleanup.${timestamp}.log"
4755
clean_dirs=("${workarea}/temp_files" "${workarea}/visualize/fits-cache" "${workarea}/visualize/users")
4856
dirs_to_clear=("${workarea}/visualize/users" "${workarea}/temp_files")
4957
echo 'Cleanup, log_file: ' "${log_file}"
@@ -64,25 +72,29 @@ function doCleanup() {
6472
} > "${log_file}" 2>&1
6573
}
6674

67-
logfileMaxAge=$((cleanupMinutes*10+5))
6875
sleepTime="$((cleanupMinutes+1))m"
6976
echo "Cleanup: started, interval time:" ${CLEANUP_INTERVAL}, "(${cleanupMinutes} minutes), sleepTime: ${sleepTime}"
7077

78+
# Predefined directories
79+
workarea_dir="/firefly/workarea"
80+
shared_workarea="/firefly/shared-workarea"
81+
7182
while true; do
7283
# Remove temporary products for each Firefly workarea
7384
sleep ${sleepTime}
74-
for workarea_dir in "$@"; do
75-
app_dirs=$(${find_cmd} "${workarea_dir}" -mindepth 1 -type d -prune)
76-
for app_dir in ${app_dirs}; do
77-
log_dir="${app_dir}/cleanup_logs"
78-
if [ ! -d "${log_dir}" ]; then
79-
mkdir -p "${log_dir}"
80-
fi
81-
# Remove old cleanup log files
82-
${find_cmd} "${log_dir}" -type f -mmin +${logfileMaxAge} -exec /bin/rm '{}' \+
83-
if [ -d "${workarea_dir}" ]; then
84-
doCleanup "${app_dir}"
85-
fi
86-
done
85+
86+
# Find app directories (should be only one, but loop for safety)
87+
app_workdirs=$(${find_cmd} "${workarea_dir}" -mindepth 1 -type d -prune)
88+
89+
for work_dir in ${app_workdirs}; do
90+
doCleanup "${work_dir}"
91+
92+
# Handle matching shared-workarea directory, if it exists
93+
app_name="${work_dir#${workarea_dir}/}"
94+
shared_work_dir="${shared_workarea}/${app_name}"
95+
if [ -d "${shared_work_dir}" ]; then
96+
doCleanup "${shared_work_dir}"
97+
fi
98+
8799
done
88100
done

docker/entrypoint.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,7 @@ def main():
360360
dry_run(cmd, webapps)
361361

362362
# Start background cleanup
363-
subprocess.Popen(
364-
[f"{catalina_home}/cleanup.sh", "/firefly/workarea", "/firefly/shared-workarea"]
365-
)
363+
subprocess.Popen([f"{catalina_home}/cleanup.sh"])
366364

367365
# Start Tomcat; Replace the current process with Tomcat
368366
print("Starting Tomcat...")

0 commit comments

Comments
 (0)