Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 5 additions & 3 deletions bin/ghe-restore
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ if [ "$GHE_VERSION_MAJOR" -le 1 ] && [ "$GHE_BACKUP_STRATEGY" = "rsync" ]; then
fi
fi

# Make sure the GitHub appliance is in maintenance mode and all writing
# processes have bled out.
# Make sure the GitHub appliance is in maintenance mode.
if $instance_configured; then
ghe-maintenance-mode-enable "$GHE_HOSTNAME"
if ! ghe-maintenance-mode-status "$GHE_HOSTNAME"; then
echo "Error: $GHE_HOSTNAME must be put in maintenance mode before restoring. Aborting." 1>&2
exit 1
fi
fi

# Restore settings and license if restoring to an unconfigured appliance or when
Expand Down
30 changes: 30 additions & 0 deletions share/github-backup-utils/ghe-maintenance-mode-status
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh
#/ Usage: ghe-maintenance-mode-status <host>
#/ Checks the status of maintenance mode on GitHub appliance at <host>.
set -e

# Bring in the backup configuration
cd $(dirname "$0")/../..
. share/github-backup-utils/ghe-backup-config

# Parse args
while true; do
case "$1" in
-*)
echo "ghe-maintenance-mode-enable: illegal argument: $1" 1>&2
exit 1
;;
*)
break
;;
esac
done

# Show usage and bail with no arguments
[ -z "$*" ] && print_usage

# Grab host arg
host="$1"

# Check if the maintenance page is present
ghe-ssh "$host" -- test -e $GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quote the path name here just in case GHE_REMOTE_DATA_DIR has spaces in dev / test environments.

36 changes: 36 additions & 0 deletions test/test-ghe-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ begin_test "ghe-restore into configured vm"
touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured"
fi

# create file used to determine if instance is in maintenance mode.
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"

# set restore host environ var
GHE_RESTORE_HOST=127.0.0.1
export GHE_RESTORE_HOST
Expand Down Expand Up @@ -133,6 +137,10 @@ begin_test "ghe-restore aborts without user verification"
touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured"
fi

# create file used to determine if instance is in maintenance mode.
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"

# set restore host environ var
GHE_RESTORE_HOST=127.0.0.1
export GHE_RESTORE_HOST
Expand Down Expand Up @@ -160,6 +168,10 @@ begin_test "ghe-restore accepts user verification"
touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured"
fi

# create file used to determine if instance is in maintenance mode.
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"

# set restore host environ var
GHE_RESTORE_HOST=127.0.0.1
export GHE_RESTORE_HOST
Expand All @@ -182,6 +194,10 @@ begin_test "ghe-restore -c into unconfigured vm"
GHE_RESTORE_HOST=127.0.0.1
export GHE_RESTORE_HOST

# create file used to determine if instance is in maintenance mode.
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"

# run ghe-restore and write output to file for asserting against
if ! ghe-restore -v -f -c > "$TRASHDIR/restore-out" 2>&1; then
cat "$TRASHDIR/restore-out"
Expand Down Expand Up @@ -227,6 +243,10 @@ begin_test "ghe-restore into unconfigured vm"
GHE_RESTORE_HOST=127.0.0.1
export GHE_RESTORE_HOST

# create file used to determine if instance is in maintenance mode.
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"

if [ "$GHE_VERSION_MAJOR" -le 1 ]; then
# run ghe-restore and write output to file for asserting against
# this should fail due to the appliance being in an unconfigured state
Expand Down Expand Up @@ -284,6 +304,10 @@ begin_test "ghe-restore with host arg"
touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured"
fi

# create file used to determine if instance is in maintenance mode.
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"

# set restore host environ var
GHE_RESTORE_HOST=127.0.0.1
export GHE_RESTORE_HOST
Expand Down Expand Up @@ -323,6 +347,10 @@ begin_test "ghe-restore no host arg or configured restore host"
touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured"
fi

# create file used to determine if instance is in maintenance mode.
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"

# unset configured restore host
unset GHE_RESTORE_HOST

Expand All @@ -344,6 +372,10 @@ begin_test "ghe-restore with no pages backup"
touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured"
fi

# create file used to determine if instance is in maintenance mode.
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"

# remove pages data
rm -rf "$GHE_DATA_DIR/1/pages"

Expand All @@ -365,6 +397,10 @@ begin_test "ghe-restore with tarball strategy"
touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured"
fi

# create file used to determine if instance is in maintenance mode.
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"

# run it
echo "tarball" > "$GHE_DATA_DIR/current/strategy"
output=$(ghe-restore -v -f localhost)
Expand Down