Skip to content

Commit fc8d2d8

Browse files
committed
Merge pull request #84 from mikemcquaid/ghe-restore-check-maintenance
ghe-restore: check maintenance mode is enabled.
2 parents f0cd355 + ac35884 commit fc8d2d8

File tree

3 files changed

+71
-3
lines changed

3 files changed

+71
-3
lines changed

bin/ghe-restore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,12 @@ if [ "$GHE_VERSION_MAJOR" -le 1 ] && [ "$GHE_BACKUP_STRATEGY" = "rsync" ]; then
147147
fi
148148
fi
149149

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

156158
# Restore settings and license if restoring to an unconfigured appliance or when
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
#/ Usage: ghe-maintenance-mode-status <host>
3+
#/ Checks the status of maintenance mode on GitHub appliance at <host>.
4+
set -e
5+
6+
# Bring in the backup configuration
7+
cd $(dirname "$0")/../..
8+
. share/github-backup-utils/ghe-backup-config
9+
10+
# Parse args
11+
while true; do
12+
case "$1" in
13+
-*)
14+
echo "ghe-maintenance-mode-enable: illegal argument: $1" 1>&2
15+
exit 1
16+
;;
17+
*)
18+
break
19+
;;
20+
esac
21+
done
22+
23+
# Show usage and bail with no arguments
24+
[ -z "$*" ] && print_usage
25+
26+
# Grab host arg
27+
host="$1"
28+
29+
# Check if the maintenance page is present
30+
ghe-ssh "$host" -- test -e "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"

test/test-ghe-restore.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ begin_test "ghe-restore into configured vm"
7676
touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured"
7777
fi
7878

79+
# create file used to determine if instance is in maintenance mode.
80+
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
81+
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"
82+
7983
# set restore host environ var
8084
GHE_RESTORE_HOST=127.0.0.1
8185
export GHE_RESTORE_HOST
@@ -133,6 +137,10 @@ begin_test "ghe-restore aborts without user verification"
133137
touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured"
134138
fi
135139

140+
# create file used to determine if instance is in maintenance mode.
141+
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
142+
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"
143+
136144
# set restore host environ var
137145
GHE_RESTORE_HOST=127.0.0.1
138146
export GHE_RESTORE_HOST
@@ -160,6 +168,10 @@ begin_test "ghe-restore accepts user verification"
160168
touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured"
161169
fi
162170

171+
# create file used to determine if instance is in maintenance mode.
172+
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
173+
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"
174+
163175
# set restore host environ var
164176
GHE_RESTORE_HOST=127.0.0.1
165177
export GHE_RESTORE_HOST
@@ -182,6 +194,10 @@ begin_test "ghe-restore -c into unconfigured vm"
182194
GHE_RESTORE_HOST=127.0.0.1
183195
export GHE_RESTORE_HOST
184196

197+
# create file used to determine if instance is in maintenance mode.
198+
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
199+
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"
200+
185201
# run ghe-restore and write output to file for asserting against
186202
if ! ghe-restore -v -f -c > "$TRASHDIR/restore-out" 2>&1; then
187203
cat "$TRASHDIR/restore-out"
@@ -227,6 +243,10 @@ begin_test "ghe-restore into unconfigured vm"
227243
GHE_RESTORE_HOST=127.0.0.1
228244
export GHE_RESTORE_HOST
229245

246+
# create file used to determine if instance is in maintenance mode.
247+
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
248+
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"
249+
230250
if [ "$GHE_VERSION_MAJOR" -le 1 ]; then
231251
# run ghe-restore and write output to file for asserting against
232252
# this should fail due to the appliance being in an unconfigured state
@@ -284,6 +304,10 @@ begin_test "ghe-restore with host arg"
284304
touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured"
285305
fi
286306

307+
# create file used to determine if instance is in maintenance mode.
308+
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
309+
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"
310+
287311
# set restore host environ var
288312
GHE_RESTORE_HOST=127.0.0.1
289313
export GHE_RESTORE_HOST
@@ -323,6 +347,10 @@ begin_test "ghe-restore no host arg or configured restore host"
323347
touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured"
324348
fi
325349

350+
# create file used to determine if instance is in maintenance mode.
351+
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
352+
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"
353+
326354
# unset configured restore host
327355
unset GHE_RESTORE_HOST
328356

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

375+
# create file used to determine if instance is in maintenance mode.
376+
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
377+
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"
378+
347379
# remove pages data
348380
rm -rf "$GHE_DATA_DIR/1/pages"
349381

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

400+
# create file used to determine if instance is in maintenance mode.
401+
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
402+
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"
403+
368404
# run it
369405
echo "tarball" > "$GHE_DATA_DIR/current/strategy"
370406
output=$(ghe-restore -v -f localhost)

0 commit comments

Comments
 (0)