From bfeaa2188fc7e8f11d62b79eaff14defb9128cf3 Mon Sep 17 00:00:00 2001 From: Gerrit Gogel Date: Wed, 14 Feb 2024 10:59:03 +0100 Subject: [PATCH] seahub: improved lifecycle management Exits container if seahub or socat exits or if connection to seafile-server is lost. It is recommended to set the restart policy for the container to "unless-stopped". --- seahub/scripts/start.sh | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/seahub/scripts/start.sh b/seahub/scripts/start.sh index 6472be5..5adfc45 100644 --- a/seahub/scripts/start.sh +++ b/seahub/scripts/start.sh @@ -23,30 +23,36 @@ function start_socat { function watch_server { while true; do - sleep 2 + sleep 1 if ! nc -z ${SEAFILE_SERVER_HOSTNAME} 8082 2>/dev/null; then + echo "Lost connection to seafiler-server. Stopping seahub..." /opt/seafile/seafile-server-latest/seahub.sh stop - while ! nc -z ${SEAFILE_SERVER_HOSTNAME} 8082 2>/dev/null; do - sleep 1 - done - start_seahub & + fi + done +} + +function watch_seahub { + while true; do + sleep 1 + if ! pgrep -f "seahub.wsgi:application" >/dev/null; then + echo "Seahub process was stopped. Exiting container..." + break fi done } function logger { - tail -f /opt/seafile/logs/seahub.log | tee /proc/1/fd/1 + tail -f /opt/seafile/logs/seahub.log | tee } -function keep_running { - while true; do - tail -f /dev/null & wait ${!} - done -} +init_seahub +start_seahub start_socat & -init_seahub -start_seahub & watch_server & -logger -keep_running +watch_seahub & +logger & + +wait -n + +exit $? \ No newline at end of file