Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,6 @@ sentry/test-custom-ca-roots.py

# OSX minutia
.DS_Store

# Self-hosted Sentry Upgrade Lockfile
.upgrade.lock
1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions install/_lockfile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# The lockfile path should be included in the `.gitignore`.
UPGRADE_LOCKFILE=".upgrade.lock"

# Usage: `exists_in_lockfile <key>`
# 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 <key> <key>`
# 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"
}
21 changes: 19 additions & 2 deletions install/turn-things-off.sh
Original file line number Diff line number Diff line change
@@ -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)$')
Expand All @@ -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}"