Browse Source

Ensure thread safety when updating app entries (#405)

Co-authored-by: Luke Childs <lukechilds123@gmail.com>
Co-authored-by: Lounès Ksouri <dev@louneskmt.com>
bitcoin-conf-clean
Aaron Dewes 4 years ago
committed by GitHub
parent
commit
7c5a854268
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      scripts/app
  2. 6
      scripts/start

11
scripts/app

@ -117,9 +117,20 @@ compose() {
update_installed_apps() {
local action="${1}"
local app="${2}"
while ! (set -o noclobber; echo "$$" > "${USER_FILE}.lock") 2> /dev/null; do
echo "Waiting for JSON lock to be released for ${app} update..."
sleep 1
done
# This will cause the lock-file to be deleted in case of a
# premature exit.
trap "rm -f "${USER_FILE}.lock"; exit $?" INT TERM EXIT
[[ "${action}" == "add" ]] && operator="+" || operator="-"
updated_json=$(cat "${USER_FILE}" | jq ".installedApps |= (. ${operator} [\"${app}\"] | unique)")
echo "${updated_json}" > "${USER_FILE}"
rm -f "${USER_FILE}.lock"
}
# Pulls down images for an app and starts it

6
scripts/start

@ -90,6 +90,12 @@ echo
echo
echo "Starting installed apps..."
echo
# Unlock the user file on each start of Umbrel to avoid issues
# Normally, the user file shouldn't ever be locked, if it is, something went wrong, but it could still be working
if [[ -f "${UMBREL_ROOT}/db/user.json.lock" ]]; then
echo "WARNING: The user file was locked, Umbrel probably wasn't shut down properly"
rm "${UMBREL_ROOT}/db/user.json.lock"
fi
"${UMBREL_ROOT}/scripts/app" start installed
echo

Loading…
Cancel
Save