Skip to content

Commit

Permalink
Merge pull request #6 from linuxserver/sqlite
Browse files Browse the repository at this point in the history
Handle SQLite dbs
  • Loading branch information
thespad authored Nov 14, 2023
2 parents 928e5d7 + 57edb2e commit f2ae297
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
9 changes: 5 additions & 4 deletions readme-vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ param_usage_include_ports: true
param_ports:
- { external_port: "8080", internal_port: "8080", port_desc: "API port" }

param_usage_include_env: true
param_env_vars:
- { env_var: "HISHTORY_POSTGRES_DB", env_value: "postgresql://${HISHTORY_DB_USER}:${HISHTORY_DB_PASS}@hishtory-db:5432/hishtory?sslmode=disable", desc: "Postgres DB [Connection URI](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING). Special characters must be [URL encoded](https://en.wikipedia.org/wiki/URL_encoding)."}
param_usage_include_env: false

opt_param_usage_include_env: false
opt_param_usage_include_env: true
opt_param_env_vars:
- { env_var: "HISHTORY_POSTGRES_DB", env_value: "postgresql://${HISHTORY_DB_USER}:${HISHTORY_DB_PASS}@hishtory-db:5432/hishtory?sslmode=disable", desc: "Postgres DB [Connection URI](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING). Special characters must be [URL encoded](https://en.wikipedia.org/wiki/URL_encoding)."}
- { env_var: "HISHTORY_SQLITE_DB", env_value: "/config/hishtory.db", desc: "SQLite database path. Needs to be a mounted volume for persistence. Don't set at the same time as HISHTORY_POSTGRES_DB."}

app_setup_block_enabled: true
app_setup_block: |
Expand Down
17 changes: 9 additions & 8 deletions root/etc/s6-overlay/s6-rc.d/init-hishtory-config/run
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
if [[ -n ${HISHTORY_POSTGRES_DB} ]]; then
DBHOST=$(echo "${HISHTORY_POSTGRES_DB}" | awk -F '@' '{print $NF}' | awk -F ':' '{print $1}')
DBPORT=$(echo "${HISHTORY_POSTGRES_DB}" | awk -F '@' '{print $NF}' | awk -F ':' '{print $2}' | awk -F '/' '{print $1}')
echo "Waiting for DB ${DBHOST} to become available on port ${DBPORT}..."
while :; do
if nc -w 1 -z "$DBHOST" "$DBPORT" > /dev/null 2>&1; then
exit 0
fi
sleep 3
done
elif [[ -n ${HISHTORY_SQLITE_DB} ]]; then
echo "Using SQLite database, ensure you have mounted $(dirname "${HISHTORY_SQLITE_DB}") to your host"
else
echo "No database configured, sleeping..."
sleep infinity
fi

echo "Waiting for DB ${DBHOST} to become available on port ${DBPORT}..."
while :; do
if nc -w 1 -z "$DBHOST" "$DBPORT" > /dev/null 2>&1; then
exit 0
fi
sleep 3
done

0 comments on commit f2ae297

Please sign in to comment.