36 lines
1.6 KiB
Plaintext
Executable File
36 lines
1.6 KiB
Plaintext
Executable File
#!/usr/bin/with-contenv bash
|
|
|
|
if [ -f "/opt/couchdb/data/.init_complete" ]; then
|
|
echo "Couchdb initialization has already completed, skipping"
|
|
else
|
|
# start couchdb as a background process (store PID)
|
|
echo "Couchdb initialization: start couchdb in background mode (non-standard port)"
|
|
# https://linux.die.net/man/1/couchdb
|
|
sed -i -e 's/;port = 5984/port = 5432/g' /opt/couchdb/etc/local.ini
|
|
sed -i -e 's/bind_address = 0.0.0.0/bind_address = 127.0.0.1/g' /opt/couchdb/etc/local.ini
|
|
/opt/couchdb/bin/couchdb -b &
|
|
COUCHDB_PID=$!
|
|
|
|
# wait for couchdb to be ready
|
|
until $(curl --output /dev/null --silent --head --fail http://127.0.0.1:5432/_up); do echo "couchdb not ready" && sleep 5; done
|
|
|
|
# create couch_peruser required system databases manually on startup
|
|
echo "couchdb ready, start creating system databases"
|
|
curl --fail -X PUT -u ${FASTEN_COUCHDB_ADMIN_USERNAME}:${FASTEN_COUCHDB_ADMIN_PASSWORD} http://127.0.0.1:5432/_users
|
|
curl --fail -X PUT -u ${FASTEN_COUCHDB_ADMIN_USERNAME}:${FASTEN_COUCHDB_ADMIN_PASSWORD} http://127.0.0.1:5432/_replicator
|
|
curl --fail -X PUT -u ${FASTEN_COUCHDB_ADMIN_USERNAME}:${FASTEN_COUCHDB_ADMIN_PASSWORD} http://127.0.0.1:5432/_global_changes
|
|
echo "system databases created successfully"
|
|
|
|
# gracefully stop couchdb process
|
|
echo "killing couchdb process"
|
|
/opt/couchdb/bin/couchdb -k
|
|
|
|
sed -i -e 's/port = 5432/;port = 5984/g' /opt/couchdb/etc/local.ini
|
|
sed -i -e 's/bind_address = 127.0.0.1/bind_address = 0.0.0.0/g' /opt/couchdb/etc/local.ini
|
|
|
|
# create the init complete flag
|
|
echo "Couchdb initialization: complete"
|
|
touch /opt/couchdb/data/.init_complete
|
|
|
|
fi
|