Skip to content

Commit 879ce17

Browse files
committed
added automatic docker clean-up
1 parent cb0aa67 commit 879ce17

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

docker/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ COPY docker/redis.conf /etc/redis/redis.conf
5959
COPY docker/kvrocks.conf /etc/kvrocks/kvrocks.conf
6060
COPY docker/bob.json /app/bob.json
6161
COPY docker/entrypoint.sh /app/entrypoint.sh
62-
RUN chmod +x /app/entrypoint.sh
62+
COPY docker/cleanup.sh /app/cleanup.sh
63+
RUN chmod +x /app/entrypoint.sh /app/cleanup.sh
6364

6465
# Expose ports
6566
# 21842 - bob server port

docker/cleanup.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
# Cleanup old snapshot files, bootstrap zips, and rotated logs.
3+
# Keeps only the 2 most recent files of each type to allow safe rollback.
4+
# Runs periodically via supervisord.
5+
6+
DATA_DIR="/data/bob"
7+
INTERVAL=3600 # check every hour
8+
9+
while true; do
10+
# Keep the 2 most recent spectrum files (by modification time), delete the rest
11+
SPECTRUM_COUNT=$(ls -t "$DATA_DIR"/spectrum.* 2>/dev/null | wc -l)
12+
if [ "$SPECTRUM_COUNT" -gt 2 ]; then
13+
ls -t "$DATA_DIR"/spectrum.* | tail -n +3 | xargs rm -f
14+
echo "$(date -u '+%Y-%m-%d %H:%M:%S') Cleaned old spectrum files (kept 2 of $SPECTRUM_COUNT)"
15+
fi
16+
17+
# Keep the 2 most recent universe files, delete the rest
18+
UNIVERSE_COUNT=$(ls -t "$DATA_DIR"/universe.* 2>/dev/null | wc -l)
19+
if [ "$UNIVERSE_COUNT" -gt 2 ]; then
20+
ls -t "$DATA_DIR"/universe.* | tail -n +3 | xargs rm -f
21+
echo "$(date -u '+%Y-%m-%d %H:%M:%S') Cleaned old universe files (kept 2 of $UNIVERSE_COUNT)"
22+
fi
23+
24+
# Remove all bootstrap zip files (only needed for initial setup)
25+
ZIP_COUNT=$(ls "$DATA_DIR"/ep*.zip 2>/dev/null | wc -l)
26+
if [ "$ZIP_COUNT" -gt 0 ]; then
27+
rm -f "$DATA_DIR"/ep*.zip
28+
echo "$(date -u '+%Y-%m-%d %H:%M:%S') Removed $ZIP_COUNT bootstrap zip(s)"
29+
fi
30+
31+
# Remove rotated log files (bob.1.log, bob.2.log, etc.) - keep only the active bob.log
32+
ROTATED_LOGS=$(ls "$DATA_DIR"/bob.[0-9]*.log 2>/dev/null | wc -l)
33+
if [ "$ROTATED_LOGS" -gt 0 ]; then
34+
rm -f "$DATA_DIR"/bob.[0-9]*.log
35+
echo "$(date -u '+%Y-%m-%d %H:%M:%S') Removed $ROTATED_LOGS rotated bob log(s)"
36+
fi
37+
38+
sleep "$INTERVAL"
39+
done

docker/supervisord.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ stderr_logfile_maxbytes=0
3232
priority=10
3333
startsecs=5
3434
startretries=10
35+
36+
[program:cleanup]
37+
command=/app/cleanup.sh
38+
autostart=true
39+
autorestart=true
40+
stdout_logfile=/app/logs/cleanup.log
41+
stderr_logfile=/app/logs/cleanup-error.log
42+
priority=20

0 commit comments

Comments
 (0)