mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-09 09:21:03 +01:00
Fix Joplin migration locks on startup
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
|
||||
## 3.5.2 (22-12-2025)
|
||||
- Automatically clear stale migration locks for SQLite and PostgreSQL databases on startup to avoid blocked fresh installs
|
||||
- Add database client utilities for unlocking migrations
|
||||
|
||||
## 3.5.1 (06-12-2025)
|
||||
- Update to latest version from etechonomy/joplin-server (changelog : https://github.com/etechonomy/joplin-server/releases)
|
||||
- Added support for configuring extra environment variables via the `env_vars` add-on option alongside config.yaml. See https://github.com/alexbelgium/hassio-addons/wiki/Add-Environment-variables-to-your-Addon-2 for details.
|
||||
|
||||
@@ -55,7 +55,7 @@ ADD "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templat
|
||||
RUN chmod 744 /ha_automodules.sh && /ha_automodules.sh "$MODULES" && rm /ha_automodules.sh
|
||||
|
||||
# Manual apps
|
||||
ENV PACKAGES="procps"
|
||||
ENV PACKAGES="procps sqlite3 postgresql-client"
|
||||
|
||||
# Automatic apps & bashio
|
||||
ADD "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/ha_autoapps.sh" "/ha_autoapps.sh"
|
||||
|
||||
@@ -104,5 +104,5 @@ schema:
|
||||
slug: joplin
|
||||
udev: true
|
||||
url: https://github.com/alexbelgium/hassio-addons
|
||||
version: "3.5.1"
|
||||
version: "3.5.2"
|
||||
webui: "[PROTO:ssl]://[HOST]:[PORT:22300]"
|
||||
|
||||
@@ -5,6 +5,52 @@ set -e
|
||||
|
||||
bashio::log.warning "Warning - minimum configuration recommended : 2 cpu cores and 4 GB of memory. Otherwise the system will become unresponsive and crash."
|
||||
|
||||
unlock_sqlite_migrations() {
|
||||
local db_path="$1"
|
||||
|
||||
if ! command -v sqlite3 >/dev/null 2>&1; then
|
||||
bashio::log.warning "sqlite3 not available; skipping SQLite migration lock check."
|
||||
return
|
||||
fi
|
||||
|
||||
if ! sqlite3 "$db_path" "SELECT name FROM sqlite_master WHERE type='table' AND name='knex_migrations_lock';" | grep -q "knex_migrations_lock"; then
|
||||
return
|
||||
fi
|
||||
|
||||
local is_locked
|
||||
is_locked=$(sqlite3 "$db_path" "SELECT is_locked FROM knex_migrations_lock LIMIT 1;" 2>/dev/null || true)
|
||||
|
||||
if [[ "$is_locked" == "1" ]]; then
|
||||
bashio::log.warning "Locked SQLite migration table detected, attempting to unlock."
|
||||
sqlite3 "$db_path" "UPDATE knex_migrations_lock SET is_locked = 0;" || bashio::log.warning "Failed to clear SQLite migration lock."
|
||||
fi
|
||||
}
|
||||
|
||||
unlock_postgres_migrations() {
|
||||
if ! command -v psql >/dev/null 2>&1; then
|
||||
bashio::log.warning "psql not available; skipping PostgreSQL migration lock check."
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ -z "${POSTGRES_DATABASE:-}" || -z "${POSTGRES_USER:-}" || -z "${POSTGRES_HOST:-}" ]]; then
|
||||
bashio::log.warning "PostgreSQL configuration incomplete; skipping migration lock check."
|
||||
return
|
||||
fi
|
||||
|
||||
local pg_port="${POSTGRES_PORT:-5432}"
|
||||
export PGPASSWORD="${POSTGRES_PASSWORD:-}"
|
||||
|
||||
local is_locked
|
||||
is_locked=$(psql -h "$POSTGRES_HOST" -p "$pg_port" -U "$POSTGRES_USER" -d "$POSTGRES_DATABASE" -Atqc "SELECT is_locked FROM knex_migrations_lock LIMIT 1;" 2>/dev/null || true)
|
||||
|
||||
if [[ "$is_locked" == "1" ]]; then
|
||||
bashio::log.warning "Locked PostgreSQL migration table detected, attempting to unlock."
|
||||
psql -h "$POSTGRES_HOST" -p "$pg_port" -U "$POSTGRES_USER" -d "$POSTGRES_DATABASE" -Atqc "UPDATE knex_migrations_lock SET is_locked = 0;" || bashio::log.warning "Failed to clear PostgreSQL migration lock."
|
||||
fi
|
||||
|
||||
unset PGPASSWORD
|
||||
}
|
||||
|
||||
# Check data location
|
||||
LOCATION=$(bashio::config 'data_location')
|
||||
if [[ "$LOCATION" = "null" || -z "$LOCATION" ]]; then
|
||||
@@ -41,9 +87,11 @@ if bashio::config.has_value 'POSTGRES_DATABASE'; then
|
||||
bashio::config.has_value 'POSTGRES_USER' && export POSTGRES_USER=$(bashio::config 'POSTGRES_USER') && bashio::log.info 'Postgrep User set'
|
||||
bashio::config.has_value 'POSTGRES_PORT' && export POSTGRES_PORT=$(bashio::config 'POSTGRES_PORT') && bashio::log.info 'Postgrep Port set'
|
||||
bashio::config.has_value 'POSTGRES_HOST' && export POSTGRES_HOST=$(bashio::config 'POSTGRES_HOST') && bashio::log.info 'Postgrep Host set'
|
||||
unlock_postgres_migrations
|
||||
else
|
||||
|
||||
bashio::log.info "Using sqlite"
|
||||
unlock_sqlite_migrations "$SQLITE_DATABASE"
|
||||
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user