Seahub throttles anonymous API calls, which includes logging in, to 60 per minute. When cmd/bisync and backend/seafile ran concurrently they exceeded this and every new remote failed with "failed to authenticate" until the end of the retries.
99 lines
3.1 KiB
Bash
Executable File
99 lines
3.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
# environment variables passed on docker-compose
|
|
export NAME=seafile7
|
|
export MYSQL_ROOT_PASSWORD=pixenij4zacoguq0kopamid6
|
|
export SEAFILE_ADMIN_EMAIL=seafile@rclone.org
|
|
export SEAFILE_ADMIN_PASSWORD=pixenij4zacoguq0kopamid6
|
|
export SEAFILE_IP=127.0.0.1
|
|
export SEAFILE_PORT=8087
|
|
export SEAFILE_TEST_DATA=${SEAFILE_TEST_DATA:-/tmp/seafile-test-data}
|
|
export SEAFILE_VERSION=latest
|
|
|
|
# make sure the data directory exists
|
|
mkdir -p ${SEAFILE_TEST_DATA}/${NAME}
|
|
|
|
# docker-compose project directory
|
|
COMPOSE_DIR=$(dirname "$0")/seafile
|
|
|
|
wait_for_seafile() {
|
|
seafile_endpoint="http://${SEAFILE_IP}:${SEAFILE_PORT}/"
|
|
wait_seconds=1
|
|
echo -n "Waiting for Seafile server to start"
|
|
for iterations in `seq 1 60`;
|
|
do
|
|
http_code=$(curl -s -o /dev/null -L -w '%{http_code}' "$seafile_endpoint" || true;)
|
|
if [ "$http_code" -eq 200 ]; then
|
|
echo
|
|
break
|
|
fi
|
|
echo -n "."
|
|
sleep $wait_seconds
|
|
done
|
|
}
|
|
|
|
start() {
|
|
docker-compose --project-directory ${COMPOSE_DIR} --project-name ${NAME} --file ${COMPOSE_DIR}/docker-compose.yml up -d
|
|
|
|
wait_for_seafile
|
|
|
|
# Seahub throttles anonymous API calls, which includes logging in,
|
|
# to 60/minute. Concurrent test runs exceed that so raise it.
|
|
# seahub_settings.py is only created on first start.
|
|
settings=/shared/seafile/conf/seahub_settings.py
|
|
if ! docker exec ${NAME}_seafile_1 grep -q DEFAULT_THROTTLE_RATES $settings; then
|
|
docker exec -i ${NAME}_seafile_1 sh -c "cat >> $settings" <<'EOF'
|
|
REST_FRAMEWORK = {
|
|
'DEFAULT_RENDERER_CLASSES': [
|
|
'rest_framework.renderers.JSONRenderer',
|
|
],
|
|
'DEFAULT_THROTTLE_RATES': {
|
|
'ping': '3000/minute',
|
|
'anon': '100000/minute',
|
|
'user': '100000/minute',
|
|
'share_link_zip_task': '10/minute'
|
|
},
|
|
'UNICODE_JSON': False,
|
|
}
|
|
EOF
|
|
docker exec ${NAME}_seafile_1 /opt/seafile/seafile-server-latest/seahub.sh restart >/dev/null
|
|
wait_for_seafile
|
|
fi
|
|
|
|
# authentication token answer should be like: {"token":"dbf58423f1632b5b679a13b0929f1d0751d9250c"}
|
|
TOKEN=`curl --silent \
|
|
--data-urlencode username=${SEAFILE_ADMIN_EMAIL} -d password=${SEAFILE_ADMIN_PASSWORD} \
|
|
http://${SEAFILE_IP}:${SEAFILE_PORT}/api2/auth-token/ \
|
|
| sed 's/^{"token":"\(.*\)"}$/\1/'`
|
|
|
|
# create default library
|
|
curl --silent -o /dev/null -X POST -H "Authorization: Token ${TOKEN}" "http://${SEAFILE_IP}:${SEAFILE_PORT}/api2/default-repo/"
|
|
|
|
echo _connect=${SEAFILE_IP}:${SEAFILE_PORT}
|
|
echo type=seafile
|
|
echo url=http://${SEAFILE_IP}:${SEAFILE_PORT}/
|
|
echo user=${SEAFILE_ADMIN_EMAIL}
|
|
echo pass=$(rclone obscure ${SEAFILE_ADMIN_PASSWORD})
|
|
echo library=My Library
|
|
}
|
|
|
|
stop() {
|
|
if status ; then
|
|
docker-compose --project-directory ${COMPOSE_DIR} --project-name ${NAME} --file ${COMPOSE_DIR}/docker-compose.yml down
|
|
fi
|
|
}
|
|
|
|
status() {
|
|
if docker ps --format "{{.Names}}" | grep ^${NAME}_seafile_1$ >/dev/null ; then
|
|
echo "$NAME running"
|
|
else
|
|
echo "$NAME not running"
|
|
return 1
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
. $(dirname "$0")/run.bash
|