mirror of
https://github.com/jrasanen/writefreely-docker.git
synced 2025-05-08 23:26:02 +03:00
Improve init checks
This commit is contained in:
parent
974fe17c5a
commit
c67b1f0f75
1 changed files with 26 additions and 2 deletions
|
@ -20,6 +20,8 @@ set -e
|
||||||
cd /data
|
cd /data
|
||||||
|
|
||||||
WRITEFREELY=/writefreely/writefreely
|
WRITEFREELY=/writefreely/writefreely
|
||||||
|
attempts=0
|
||||||
|
max_attempts=5
|
||||||
|
|
||||||
validate_url() {
|
validate_url() {
|
||||||
URL="$1"
|
URL="$1"
|
||||||
|
@ -43,10 +45,23 @@ fi
|
||||||
|
|
||||||
if [ -e ./config.ini ]; then
|
if [ -e ./config.ini ]; then
|
||||||
until ${WRITEFREELY} --init-db; do
|
until ${WRITEFREELY} --init-db; do
|
||||||
echo "Retrying --init-db..."
|
attempts=$((attempts+1))
|
||||||
|
if [ $attempts -ge $max_attempts ]; then
|
||||||
|
echo "Failed to initialize database after $attempts attempts."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Retrying --init-db ($attempts/$max_attempts)..."
|
||||||
sleep 5
|
sleep 5
|
||||||
done
|
done
|
||||||
|
echo "Generating keys..."
|
||||||
${WRITEFREELY} -gen-keys
|
${WRITEFREELY} -gen-keys
|
||||||
|
if [ -n "$WRITEFREELY_ADMIN_USER" ]; then
|
||||||
|
${WRITEFREELY} user create --admin ${WRITEFREELY_ADMIN_USER}:${WRITEFREELY_ADMIN_PASSWORD}
|
||||||
|
echo Created user ${WRITEFREELY_ADMIN_USER}
|
||||||
|
else
|
||||||
|
echo Admin user not defined
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
exec ${WRITEFREELY}
|
exec ${WRITEFREELY}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -165,11 +180,19 @@ EOF
|
||||||
chmod 600 ./config.ini
|
chmod 600 ./config.ini
|
||||||
|
|
||||||
# Retry --init-db until it succeeds
|
# Retry --init-db until it succeeds
|
||||||
|
echo "Initializing database..."
|
||||||
until ${WRITEFREELY} --init-db; do
|
until ${WRITEFREELY} --init-db; do
|
||||||
echo "Retrying --init-db..."
|
attempts=$((attempts+1))
|
||||||
|
if [ $attempts -ge $max_attempts ]; then
|
||||||
|
echo "Failed to initialize database after $attempts attempts."
|
||||||
|
rm ./config.ini
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Retrying --init-db ($attempts/$max_attempts)..."
|
||||||
sleep 5
|
sleep 5
|
||||||
done
|
done
|
||||||
|
|
||||||
|
echo "Generating keys..."
|
||||||
${WRITEFREELY} --gen-keys
|
${WRITEFREELY} --gen-keys
|
||||||
|
|
||||||
if [ -n "$WRITEFREELY_ADMIN_USER" ]; then
|
if [ -n "$WRITEFREELY_ADMIN_USER" ]; then
|
||||||
|
@ -179,6 +202,7 @@ else
|
||||||
echo Admin user not defined
|
echo Admin user not defined
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$WRITEFREELY_WRITER_USER" ]; then
|
if [ -n "$WRITEFREELY_WRITER_USER" ]; then
|
||||||
${WRITEFREELY} user create ${WRITEFREELY_WRITER_USER}:${WRITEFREELY_WRITER_PASSWORD}
|
${WRITEFREELY} user create ${WRITEFREELY_WRITER_USER}:${WRITEFREELY_WRITER_PASSWORD}
|
||||||
echo Created user ${WRITEFREELY_WRITER_USER}
|
echo Created user ${WRITEFREELY_WRITER_USER}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue