Concurrent commands for the same app could each read a setting, change it, and write it back, so all of them exited successfully while silently dropping changes made by the others. Updates to app settings are now serialized so every change is kept, and readers never see a partially written value.
159 lines
5.4 KiB
Bash
Executable File
159 lines
5.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eo pipefail
|
|
[[ $DOKKU_TRACE ]] && set -x
|
|
|
|
fn-plugin-property-get() {
|
|
declare desc="returns the value for a given property"
|
|
declare PLUGIN="$1" APP="$2" KEY="$3" DEFAULT="$4"
|
|
|
|
fn-plugin-property-get-default "$PLUGIN" "$APP" "$KEY" "$DEFAULT"
|
|
}
|
|
|
|
fn-plugin-property-clone() {
|
|
declare desc="clone the properties for an app"
|
|
declare PLUGIN="$1" OLD_APP="$2" NEW_APP="$3"
|
|
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "clone" "$PLUGIN" "$OLD_APP" "$NEW_APP"
|
|
}
|
|
|
|
fn-plugin-property-destroy() {
|
|
declare desc="destroy the properties for an app"
|
|
declare PLUGIN="$1" APP="$2"
|
|
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "destroy" "$PLUGIN" "$APP"
|
|
}
|
|
|
|
fn-plugin-property-delete() {
|
|
declare desc="delete a key from the property store for an app"
|
|
declare PLUGIN="$1" APP="$2" KEY="$3"
|
|
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "del" "$PLUGIN" "$APP" "$KEY"
|
|
}
|
|
|
|
fn-plugin-property-exists() {
|
|
declare desc="returns whether the property store has a value for an app"
|
|
declare PLUGIN="$1" APP="$2" KEY="$3"
|
|
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "exists" "$PLUGIN" "$APP" "$KEY"
|
|
}
|
|
|
|
fn-plugin-property-get-all() {
|
|
declare desc="returns a map of all properties for a given app"
|
|
declare PLUGIN="$1" APP="$2"
|
|
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "get-all" "$PLUGIN" "$APP"
|
|
}
|
|
|
|
fn-plugin-property-get-all-by-prefix() {
|
|
declare desc="returns a map of all properties for a given app with a specified prefix"
|
|
declare PLUGIN="$1" APP="$2" PREFIX="$3"
|
|
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "get-all-by-prefix" "$PLUGIN" "$APP" "$PREFIX"
|
|
}
|
|
|
|
fn-plugin-property-get-default() {
|
|
declare desc="returns the value for a given property with a specified default value"
|
|
declare PLUGIN="$1" APP="$2" KEY="$3" DEFAULT="$4"
|
|
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "get-with-default" "$PLUGIN" "$APP" "$KEY" "$DEFAULT"
|
|
}
|
|
|
|
fn-plugin-property-list-add() {
|
|
declare desc="adds a property to a list at an optionally specified index"
|
|
declare PLUGIN="$1" APP="$2" KEY="$3" VALUE="$4" INDEX="$5"
|
|
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "rpush" "$PLUGIN" "$APP" "$KEY" "$VALUE" "$INDEX"
|
|
}
|
|
|
|
fn-plugin-property-list-get() {
|
|
declare desc="returns a property list"
|
|
declare PLUGIN="$1" APP="$2" KEY="$3"
|
|
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "lrange" "$PLUGIN" "$APP" "$KEY"
|
|
}
|
|
|
|
fn-plugin-property-list-get-by-index() {
|
|
declare desc="returns an entry within property list by index"
|
|
declare PLUGIN="$1" APP="$2" KEY="$3" INDEX="$4"
|
|
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "lindex" "$PLUGIN" "$APP" "$KEY" "$INDEX"
|
|
}
|
|
|
|
fn-plugin-property-list-get-by-value() {
|
|
declare desc="returns an entry within property list by value"
|
|
declare PLUGIN="$1" APP="$2" KEY="$3" VALUE="$4"
|
|
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "lismember" "$PLUGIN" "$APP" "$KEY" "$VALUE"
|
|
}
|
|
|
|
fn-plugin-property-list-length() {
|
|
declare desc="returns the length of a property list"
|
|
declare PLUGIN="$1" APP="$2" KEY="$3"
|
|
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "llen" "$PLUGIN" "$APP" "$KEY"
|
|
}
|
|
|
|
fn-plugin-property-list-remove() {
|
|
declare desc="removes a value from a property list"
|
|
declare PLUGIN="$1" APP="$2" KEY="$3" VALUE="$4"
|
|
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "lrem" "$PLUGIN" "$APP" "$KEY" "$VALUE"
|
|
}
|
|
|
|
fn-plugin-property-list-remove-by-prefix() {
|
|
declare desc="removes a value by prefix from a property list"
|
|
declare PLUGIN="$1" APP="$2" KEY="$3" PREFIX="$4"
|
|
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "lrem-by-prefix" "$PLUGIN" "$APP" "$KEY" "$PREFIX"
|
|
}
|
|
|
|
fn-plugin-property-list-set() {
|
|
declare desc="sets a value within a property list at a specified index"
|
|
declare PLUGIN="$1" APP="$2" KEY="$3" VALUE="$4" INDEX="$5"
|
|
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "lset" "$PLUGIN" "$APP" "$KEY" "$VALUE" "$INDEX"
|
|
}
|
|
|
|
fn-plugin-property-write() {
|
|
declare desc="read a key from the property store for an app"
|
|
declare PLUGIN="$1" APP="$2" KEY="$3" VALUE="$4"
|
|
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "set" "$PLUGIN" "$APP" "$KEY" "$VALUE"
|
|
}
|
|
|
|
fn-plugin-property-setup() {
|
|
declare desc="creates the plugin config root"
|
|
declare PLUGIN="$1"
|
|
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "setup" "$PLUGIN"
|
|
}
|
|
|
|
fn-plugin-property-setup-app() {
|
|
declare desc="setup the properties for an app"
|
|
declare PLUGIN="$1" APP="$2"
|
|
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "setup-app" "$PLUGIN" "$APP"
|
|
}
|
|
|
|
fn-plugin-property-lock() {
|
|
declare desc="runs a callback while holding the exclusive property lock for an app"
|
|
declare PLUGIN="$1" APP="$2" CALLBACK="$3"
|
|
shift 3
|
|
local lock_dir="${DOKKU_LIB_ROOT}/config/${PLUGIN}/${APP}"
|
|
local lock_fd previous_locked_directories="$DOKKU_LOCKED_DIRECTORIES"
|
|
|
|
if fn-plugin-property-lock-held "$lock_dir"; then
|
|
"$CALLBACK" "$@"
|
|
return
|
|
fi
|
|
|
|
fn-plugin-property-setup-app "$PLUGIN" "$APP"
|
|
exec {lock_fd}<"$lock_dir"
|
|
flock "$lock_fd"
|
|
|
|
export DOKKU_LOCKED_DIRECTORIES="${previous_locked_directories:+$previous_locked_directories$'\n'}$lock_dir"
|
|
"$CALLBACK" "$@"
|
|
local status=$?
|
|
|
|
if [[ -n "$previous_locked_directories" ]]; then
|
|
export DOKKU_LOCKED_DIRECTORIES="$previous_locked_directories"
|
|
else
|
|
unset DOKKU_LOCKED_DIRECTORIES
|
|
fi
|
|
exec {lock_fd}<&-
|
|
return "$status"
|
|
}
|
|
|
|
fn-plugin-property-lock-held() {
|
|
declare desc="returns whether a property lock directory is already held by a parent process"
|
|
declare LOCK_DIR="$1"
|
|
local held
|
|
|
|
while IFS= read -r held; do
|
|
[[ -n "$held" ]] && [[ "$held" == "$LOCK_DIR" ]] && return 0
|
|
done <<<"$DOKKU_LOCKED_DIRECTORIES"
|
|
return 1
|
|
}
|