diff --git a/bin/ghe-restore b/bin/ghe-restore index 48ab357e6..9db3d6c0c 100755 --- a/bin/ghe-restore +++ b/bin/ghe-restore @@ -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 diff --git a/share/github-backup-utils/ghe-maintenance-mode-status b/share/github-backup-utils/ghe-maintenance-mode-status new file mode 100755 index 000000000..679ebb894 --- /dev/null +++ b/share/github-backup-utils/ghe-maintenance-mode-status @@ -0,0 +1,30 @@ +#!/bin/sh +#/ Usage: ghe-maintenance-mode-status +#/ Checks the status of maintenance mode on GitHub appliance at . +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" diff --git a/test/test-ghe-restore.sh b/test/test-ghe-restore.sh index f4e3b509a..9d2570329 100755 --- a/test/test-ghe-restore.sh +++ b/test/test-ghe-restore.sh @@ -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 @@ -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 @@ -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 @@ -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" @@ -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 @@ -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 @@ -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 @@ -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" @@ -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)