diff --git a/.gitignore b/.gitignore index 26d3ff590b1..f42fc456277 100644 --- a/.gitignore +++ b/.gitignore @@ -105,3 +105,6 @@ sentry/test-custom-ca-roots.py # OSX minutia .DS_Store + +# Self-hosted Sentry Upgrade Lockfile +.upgrade.lock diff --git a/install.sh b/install.sh index c6b3a62a178..87f99354d24 100755 --- a/install.sh +++ b/install.sh @@ -13,6 +13,7 @@ fi source install/_logging.sh source install/_lib.sh +source install/_lockfile.sh # Pre-flight. No impact yet. source install/parse-cli.sh diff --git a/install/_lockfile.sh b/install/_lockfile.sh new file mode 100644 index 00000000000..f4494c47601 --- /dev/null +++ b/install/_lockfile.sh @@ -0,0 +1,37 @@ +# The lockfile path should be included in the `.gitignore`. +UPGRADE_LOCKFILE=".upgrade.lock" + +# Usage: `exists_in_lockfile ` +# Returns 1 if the key exists in the lockfile, 0 otherwise +function exist_in_lockfile { + if [[ ! -f "$UPGRADE_LOCKFILE" ]]; then + echo "// This file is automatically generated for self-hosted Sentry installations. DO NOT EDIT." >"$UPGRADE_LOCKFILE" + return 0 + fi + # Read `.upgrade.lock` file and check whether the `key` exists + grep -q "$1" "$UPGRADE_LOCKFILE" + return $? +} + +# Usage: `add_to_lockfile ` +# Adds the `key` to the lockfile, and mark it as executed +function add_to_lockfile { + # If the `.upgrade.lock` file does not exist, create it + # with warnings of "DO NOT EDIT" etc above it. + # Otherwise, just add the `key` and the current timestamp + # to the maching key separated by a space. + # Example: `key 2022-01-01T00:00:00Z` + if [[ ! -f "$UPGRADE_LOCKFILE" ]]; then + echo "// This file is automatically generated for self-hosted Sentry installations. DO NOT EDIT." >"$UPGRADE_LOCKFILE" + fi + + # If the `key` already exists, do nothing + if exist_in_lockfile "$1"; then + return + fi + + # Add the `key` and the current timestamp to the maching key separated by a space. + # Example: `key 2022-01-01T00:00:00Z` + local timestamp=$(date +"%Y-%m-%dT%H:%M:%S%z") + echo "$1 $timestamp" >>"$UPGRADE_LOCKFILE" +} diff --git a/install/turn-things-off.sh b/install/turn-things-off.sh index fc0ddf38d48..9ffff546b91 100644 --- a/install/turn-things-off.sh +++ b/install/turn-things-off.sh @@ -1,5 +1,19 @@ echo "${_group}Turning things off ..." +if ! exist_in_lockfile "move-seaweedfs-tmp-data"; then + # Only execute this when `seaweedfs` container is running + if ! $dc ps --quiet seaweedfs; then + echo "SeaweedFS container is not running, skipping moving tmp data." + return + fi + + echo "Moving SeaweedFS tmp data to persistent storage..." + $dc exec seaweedfs find /tmp -maxdepth 1 -name "*.dat" -exec mv -v {} /data/ \; + $dc exec seaweedfs find /tmp -maxdepth 1 -name "*.vif" -exec mv -v {} /data/ \; + echo "Moved SeaweedFS tmp data to persistent storage." + add_to_lockfile "move-seaweedfs-tmp-data" +fi + if [[ -n "$MINIMIZE_DOWNTIME" ]]; then # Stop everything but relay and nginx $dc rm -fsv $($dc config --services | grep -v -E '^(nginx|relay)$') @@ -25,8 +39,11 @@ remove_volume() { $remove_command $1 } -if exists_volume sentry-symbolicator; then - echo "Removed $(remove_volume sentry-symbolicator)." +if ! exist_in_lockfile "remove-symbolicator-volume-distroless"; then + if exists_volume sentry-symbolicator; then + echo "Removed $(remove_volume sentry-symbolicator)." + add_to_lockfile "remove-symbolicator-volume-distroless" + fi fi echo "${_endgroup}"