2021-01-22 21:22:53 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-01-31 13:50:13 +00:00
|
|
|
function init_seahub {
|
2021-01-27 23:39:18 +00:00
|
|
|
/scripts/create_data_links.sh
|
2021-01-31 13:56:03 +00:00
|
|
|
echo "{ \"email\": \"${SEAFILE_ADMIN_EMAIL}\",\"password\": \"${SEAFILE_ADMIN_PASSWORD}\"}" >/opt/seafile/conf/admin.txt
|
2021-02-03 23:11:54 +00:00
|
|
|
sed -i 's@bind =.*@bind = "0.0.0.0:8000"@' /opt/seafile/conf/gunicorn.conf.py
|
2021-01-31 13:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function start_seahub {
|
2021-02-03 23:12:52 +00:00
|
|
|
/opt/seafile/seafile-server-latest/seahub.sh start
|
2021-01-27 23:39:18 +00:00
|
|
|
}
|
2021-01-22 21:22:53 +00:00
|
|
|
|
2021-01-27 23:39:18 +00:00
|
|
|
function start_socat {
|
|
|
|
mkdir -p /opt/seafile/seafile-server-latest/runtime
|
2021-02-01 23:31:01 +00:00
|
|
|
while true; do
|
2023-10-23 18:00:57 +00:00
|
|
|
while ! nc -z ${SEAFILE_SERVER_HOSTNAME} 8001 2>/dev/null; do
|
2021-02-01 23:31:01 +00:00
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
echo "Starting socat..."
|
2023-10-23 18:00:57 +00:00
|
|
|
socat -d -d UNIX-LISTEN:/opt/seafile/seafile-server-latest/runtime/seafile.sock,fork,unlink-early TCP:${SEAFILE_SERVER_HOSTNAME}:8001,forever,keepalive,keepidle=10,keepintvl=10,keepcnt=2
|
2021-01-31 13:50:13 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function watch_server {
|
|
|
|
while true; do
|
2024-02-14 09:59:03 +00:00
|
|
|
sleep 1
|
2023-10-23 18:00:57 +00:00
|
|
|
if ! nc -z ${SEAFILE_SERVER_HOSTNAME} 8082 2>/dev/null; then
|
2024-02-14 09:59:03 +00:00
|
|
|
echo "Lost connection to seafiler-server. Stopping seahub..."
|
2021-02-03 23:12:52 +00:00
|
|
|
/opt/seafile/seafile-server-latest/seahub.sh stop
|
2021-01-31 13:50:13 +00:00
|
|
|
fi
|
|
|
|
done
|
2021-01-27 23:39:18 +00:00
|
|
|
}
|
2021-01-22 21:22:53 +00:00
|
|
|
|
2024-02-14 09:59:03 +00:00
|
|
|
function watch_seahub {
|
2021-01-27 23:39:18 +00:00
|
|
|
while true; do
|
2024-02-14 09:59:03 +00:00
|
|
|
sleep 1
|
|
|
|
if ! pgrep -f "seahub.wsgi:application" >/dev/null; then
|
|
|
|
echo "Seahub process was stopped. Exiting container..."
|
|
|
|
break
|
|
|
|
fi
|
2021-01-27 23:39:18 +00:00
|
|
|
done
|
|
|
|
}
|
2021-01-22 21:22:53 +00:00
|
|
|
|
2024-02-14 09:59:03 +00:00
|
|
|
function logger {
|
|
|
|
tail -f /opt/seafile/logs/seahub.log | tee
|
|
|
|
}
|
|
|
|
|
2021-01-31 13:50:13 +00:00
|
|
|
init_seahub
|
2024-02-14 09:59:03 +00:00
|
|
|
start_seahub
|
|
|
|
|
|
|
|
start_socat &
|
2021-01-31 13:50:13 +00:00
|
|
|
watch_server &
|
2024-02-14 09:59:03 +00:00
|
|
|
watch_seahub &
|
|
|
|
logger &
|
|
|
|
|
|
|
|
wait -n
|
|
|
|
|
|
|
|
exit $?
|