Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
🚑 Persists precense database
Browse files Browse the repository at this point in the history
Ref #1
  • Loading branch information
frenck committed May 19, 2018
1 parent 00f2005 commit 2bccb52
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions happy-bubbles/rootfs/etc/cont-init.d/20-persist-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/with-contenv bash
# ==============================================================================
# Community Hass.io Add-ons: Happy Bubbles
# Persists the presence database (and create if missing)
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh

if ! hass.file_exists '/data/presence.db'; then
hass.log.debug 'Starting Presence temporarly...'

cd /opt || exit
exec 3< <(./precense)

# Wait until the db exists
until hass.file_exists "/opt/precense.db"; do
sleep 1
done

# Just to be safe, wait another 2 seconds
sleep 2

# Kill it, if still alive
kill "$(pgrep precense)" >/dev/null 2>&1 || true

# Move the created database into a safe place
mv /opt/precense.db /data/precense.db

hass.log.debug 'Persistent precense database created'
fi

ln -s /data/precense.db /opt/precense.db

0 comments on commit 2bccb52

Please sign in to comment.