From 2a176d2d12077b0160ff3b963b233b38336b3398 Mon Sep 17 00:00:00 2001 From: Gerrit Gogel Date: Wed, 14 Feb 2024 11:05:59 +0100 Subject: [PATCH] seafile-server: improved lifecycle management and scheduled gc Exits container if seafile-server or socat exits. Exits the container after scheduled garbage collection. These changes allow a clean restart with deterministic behaviour. It is recommended to set the restart policy for the container to "unless-stopped". --- seafile-server/scripts/gc.sh | 8 ++++---- seafile-server/scripts/start.sh | 13 +++++++++++-- seafile-server/scripts/utils.sh | 6 ------ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/seafile-server/scripts/gc.sh b/seafile-server/scripts/gc.sh index 92fc02d..df3d4a7 100644 --- a/seafile-server/scripts/gc.sh +++ b/seafile-server/scripts/gc.sh @@ -3,6 +3,7 @@ source /scripts/utils.sh SEAFILE_DIR=/opt/seafile/seafile-server-latest if [[ $SEAFILE_SERVER != *"pro"* ]]; then + touch /tmp/gc_active echo "Seafile CE: Stop Seafile to perform offline garbage collection." stop_socat $SEAFILE_DIR/seafile.sh stop @@ -17,8 +18,7 @@ fi $SEAFILE_DIR/seaf-gc.sh "$@" if [[ $SEAFILE_SERVER != *"pro"* ]]; then - echo "Seafile CE: Offline garbage collection completed. Starting Seafile." - sleep 3 - $SEAFILE_DIR/seafile.sh start - start_socat & + echo "Seafile CE: Offline garbage collection completed. Exiting..." + echo "Set the restart policy of this container to unless-stopped to restart it automatically after garbage collection." + rm -f /tmp/gc_active fi diff --git a/seafile-server/scripts/start.sh b/seafile-server/scripts/start.sh index 561be8e..e3d2ee5 100644 --- a/seafile-server/scripts/start.sh +++ b/seafile-server/scripts/start.sh @@ -3,8 +3,17 @@ source /scripts/utils.sh trap 'sigterm' SIGTERM -gc_cron & +rm -f /tmp/gc_active + +gc_cron start_server & start_socat & logger & -keep_running \ No newline at end of file + +wait -n + +while [ -f /tmp/gc_active ]; do + sleep 10 +done + +exit $? \ No newline at end of file diff --git a/seafile-server/scripts/utils.sh b/seafile-server/scripts/utils.sh index 6099fc0..41c4d31 100644 --- a/seafile-server/scripts/utils.sh +++ b/seafile-server/scripts/utils.sh @@ -47,12 +47,6 @@ function logger { tail -f /opt/seafile/logs/common.log | tee } -function keep_running { - while true; do - tail -f /dev/null & wait ${!} - done -} - function sig_kill_all () { pkill -SIGKILL -f "seaf-server -c ${default_ccnet_conf_dir}" pkill -SIGKILL -f "fileserver -c ${default_ccnet_conf_dir}"