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".
This commit is contained in:
Gerrit Gogel 2024-02-14 10:59:03 +01:00
parent 94d3ed3e9e
commit bfeaa2188f

View file

@ -23,30 +23,36 @@ function start_socat {
function watch_server { function watch_server {
while true; do while true; do
sleep 2 sleep 1
if ! nc -z ${SEAFILE_SERVER_HOSTNAME} 8082 2>/dev/null; then 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 /opt/seafile/seafile-server-latest/seahub.sh stop
while ! nc -z ${SEAFILE_SERVER_HOSTNAME} 8082 2>/dev/null; do fi
sleep 1 done
done }
start_seahub &
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 fi
done done
} }
function logger { 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 { init_seahub
while true; do start_seahub
tail -f /dev/null & wait ${!}
done
}
start_socat & start_socat &
init_seahub
start_seahub &
watch_server & watch_server &
logger watch_seahub &
keep_running logger &
wait -n
exit $?