Skip to content

Commit b624f3a

Browse files
authored
Merge pull request #670 from github/hao/cleanup-nomad-container
Cleanup nomad container when restore for 2.22
2 parents 033d213 + 0881064 commit b624f3a

File tree

5 files changed

+75
-3
lines changed

5 files changed

+75
-3
lines changed

bin/ghe-host-check

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ if [ $rc -ne 0 ]; then
8484
exit $rc
8585
fi
8686

87+
CLUSTER=false
88+
if ghe-ssh "$host" -- \
89+
"[ -f '$GHE_REMOTE_ROOT_DIR/etc/github/cluster' ]"; then
90+
CLUSTER=true
91+
fi
92+
93+
# ensure all nodes in the cluster are running the same version
94+
if "$CLUSTER"; then
95+
node_version_list=$(ghe-ssh "$host" ghe-cluster-each -- ghe-version)
96+
distinct_versions=$(echo "$node_version_list" | awk '{split($0, a, ":"); print a[2]}' | awk '{print $4}' | uniq | wc -l)
97+
if [ "$distinct_versions" -ne 1 ]; then
98+
echo "$node_version_list" 1>&2
99+
echo "Error: Not all nodes are running the same version! Please ensure all nodes are running the same version before using backup-utils." 1>&2
100+
exit 1
101+
fi
102+
fi
103+
87104
version=$(echo "$output" | grep "GitHub Enterprise" | awk '{print $NF}')
88105

89106
if [ -z "$version" ]; then

bin/ghe-restore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,16 @@ if $CLUSTER; then
410410
echo "Configuring cluster ..."
411411
if [ "$GHE_VERSION_MAJOR" -eq "3" ]; then
412412
ghe-ssh "$GHE_HOSTNAME" -- "ghe-cluster-nomad-cleanup" 1>&3 2>&3
413+
elif [ "$GHE_VERSION_MAJOR" -eq "2" ] && [ "$GHE_VERSION_MINOR" -eq "22" ]; then
414+
ghe-ssh "$GHE_HOSTNAME" -- "ghe-cluster-each -- /usr/local/share/enterprise/ghe-nomad-cleanup" 1>&3 2>&3
413415
fi
414416
ghe-ssh "$GHE_HOSTNAME" -- "ghe-cluster-config-apply" 1>&3 2>&3
415417
elif $instance_configured; then
416418
echo "Configuring appliance ..."
417419
if [ "$GHE_VERSION_MAJOR" -eq "3" ]; then
418420
ghe-ssh "$GHE_HOSTNAME" -- "ghe-nomad-cleanup" 1>&3 2>&3
421+
elif [ "$GHE_VERSION_MAJOR" -eq "2" ] && [ "$GHE_VERSION_MINOR" -eq "22" ]; then
422+
ghe-ssh "$GHE_HOSTNAME" -- "/usr/local/share/enterprise/ghe-nomad-cleanup" 1>&3 2>&3
419423
fi
420424
ghe-ssh "$GHE_HOSTNAME" -- "ghe-config-apply" 1>&3 2>&3
421425
fi

share/github-backup-utils/ghe-restore-settings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ GHE_RESTORE_SNAPSHOT_PATH="$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT"
2828
echo "Restoring license ..."
2929
ghe-ssh "$GHE_HOSTNAME" -- 'ghe-import-license' < "$GHE_RESTORE_SNAPSHOT_PATH/enterprise.ghl" 1>&3
3030

31-
echo "Restoring settings ..."
31+
echo "Restoring settings and applying configuration ..."
3232

3333
# Restore external MySQL password if running external MySQL DB.
3434
restore-secret "external MySQL password" "external-mysql-password" "secrets.external.mysql"

test/bin/ghe-cluster-each

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,34 @@ for _ in "$@"; do
1616
shift
1717
shift
1818
;;
19+
--)
20+
if [ "$1" = "--" ]; then
21+
shift
22+
COMMAND="$*"
23+
fi
24+
break
25+
;;
1926
esac
2027
done
2128

29+
if [ "$COMMAND" == "ghe-version" ]; then
30+
if [ -z "$DIFFERENT_VERSIONS" ]; then
31+
echo "fake-uuid: GitHub Enterprise Server 3.1.0 lxc 2020-12-16 5e97c07602"
32+
echo "fake-uuid1: GitHub Enterprise Server 3.1.0 lxc 2020-12-16 5e97c07602"
33+
echo "fake-uuid2: GitHub Enterprise Server 3.1.0 lxc 2020-12-16 5e97c07602"
34+
else
35+
echo "fake-uuid: GitHub Enterprise Server 3.1.0 lxc 2020-12-16 5e97c07602"
36+
echo "fake-uuid1: GitHub Enterprise Server 3.1.0 lxc 2020-12-16 5e97c07602"
37+
echo "fake-uuid2: GitHub Enterprise Server 2.19 lxc 2020-12-13 5e97c07622"
38+
fi
39+
exit 0
40+
fi
41+
42+
if [ "$COMMAND" == "/usr/local/share/enterprise/ghe-nomad-cleanup" ]; then
43+
echo "nomad cleanup"
44+
exit 0
45+
fi
46+
2247
if $SHOW_UUID; then
2348
CONFIG="$GHE_REMOTE_DATA_USER_DIR/common/cluster.conf"
2449

@@ -36,4 +61,4 @@ if $SHOW_UUID; then
3661
echo $hostname
3762
done
3863
fi
39-
fi
64+
fi

test/test-ghe-restore.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ setup_test_data "$GHE_DATA_DIR/1"
535535
# Make the current symlink
536536
ln -s 1 "$GHE_DATA_DIR/current"
537537

538-
begin_test "ghe-restore cluster"
538+
begin_test "ghe-restore cluster with matching node versions"
539539
(
540540
set -e
541541
rm -rf "$GHE_REMOTE_ROOT_DIR"
@@ -598,6 +598,32 @@ begin_test "ghe-restore cluster"
598598
)
599599
end_test
600600

601+
begin_test "ghe-restore cluster with different node versions should fail at ghe-host-check"
602+
(
603+
set -e
604+
rm -rf "$GHE_REMOTE_ROOT_DIR"
605+
setup_moreutils_parallel
606+
setup_remote_metadata
607+
setup_remote_cluster
608+
echo "cluster" > "$GHE_DATA_DIR/current/strategy"
609+
610+
# set that versions should not match for this test
611+
DIFFERENT_VERSIONS=1
612+
export DIFFERENT_VERSIONS
613+
614+
# set as configured, enable maintenance mode and create required directories
615+
setup_maintenance_mode "configured"
616+
617+
# set restore host environ var
618+
GHE_RESTORE_HOST=127.0.0.1
619+
export GHE_RESTORE_HOST
620+
621+
! output=$(ghe-restore -v -f 2>&1)
622+
623+
echo "$output" | grep -q "Error: Not all nodes are running the same version! Please ensure all nodes are running the same version before using backup-utils."
624+
)
625+
end_test
626+
601627
begin_test "ghe-restore missing directories or files from source snapshot displays warning"
602628
(
603629
# Tests the scenario where something exists in the database, but not on disk.

0 commit comments

Comments
 (0)