diff --git a/deploy/docker/fs/opt/appsmith/entrypoint.sh b/deploy/docker/fs/opt/appsmith/entrypoint.sh index 5e42418d92..685c0b8fd0 100644 --- a/deploy/docker/fs/opt/appsmith/entrypoint.sh +++ b/deploy/docker/fs/opt/appsmith/entrypoint.sh @@ -6,6 +6,7 @@ tlog "Running as: $(id)" stacks_path=/appsmith-stacks +export APPSMITH_PG_DATABASE="appsmith" export SUPERVISORD_CONF_TARGET="$TMP/supervisor-conf.d/" # export for use in supervisord.conf export MONGODB_TMP_KEY_PATH="$TMP/mongodb-key" # export for use in supervisor process mongodb.conf @@ -432,6 +433,7 @@ init_postgres() { tlog "Initializing local Postgres data folder" su postgres -c "env PATH='$PATH' initdb -D $POSTGRES_DB_PATH" fi + create_appsmith_pg_db "$POSTGRES_DB_PATH" else runEmbeddedPostgres=0 fi @@ -453,6 +455,33 @@ safe_init_postgres() { fi } +# Method to create a appsmith database in the postgres +# Args: +# POSTGRES_DB_PATH (string): Path to the postgres data directory +# Returns: +# None +# Example: +# create_appsmith_pg_db "/appsmith-stacks/data/postgres/main" +create_appsmith_pg_db() { + POSTGRES_DB_PATH=$1 + # Start the postgres , wait for it to be ready and create a appsmith db + su postgres -c "env PATH='$PATH' pg_ctl -D $POSTGRES_DB_PATH -l $POSTGRES_DB_PATH/logfile start" + echo "Waiting for Postgres to start" + until su postgres -c "env PATH='$PATH' pg_isready -d postgres"; do + tlog "Waiting for Postgres to be ready..." + sleep 1 + done + # Check if the appsmith DB is present + DB_EXISTS=$(su postgres -c "env PATH='$PATH' psql -tAc \"SELECT 1 FROM pg_database WHERE datname='${APPSMITH_PG_DATABASE}'\"") + + if [[ "$DB_EXISTS" != "1" ]]; then + su postgres -c "env PATH='$PATH' psql -c \"CREATE DATABASE ${APPSMITH_PG_DATABASE}\"" + else + echo "Database ${APPSMITH_PG_DATABASE} already exists." + fi + su postgres -c "env PATH='$PATH' pg_ctl -D $POSTGRES_DB_PATH stop" +} + setup_caddy() { if [[ "$APPSMITH_RATE_LIMIT" == "disabled" ]]; then export _APPSMITH_CADDY="/opt/caddy/caddy_vanilla"