Skip to content

Commit 1114367

Browse files
authored
Merge pull request #927 from github/jcambass/2022-06-15/only_restart_actions_if_stopped
Only Start Actions if they have been Stopped
2 parents d980b43 + 20db671 commit 1114367

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

bin/ghe-restore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ cleanup () {
104104
update_restore_status "$1"
105105
fi
106106

107-
if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
107+
if $ACTIONS_STOPPED && ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
108108
echo "Restarting Actions after restore ..."
109109
# In GHES 3.3+, ghe-actions-start no longer has a -f (force) flag. In GHES 3.2 and below, we must provide the
110110
# force flag to make sure it can start in maintenance mode. Use it conditionally based on whether it exists
@@ -161,6 +161,9 @@ hostname=$(echo "$GHE_HOSTNAME" | cut -f 1 -d :)
161161
# Show usage with no <host>
162162
[ -z "$GHE_HOSTNAME" ] && print_usage
163163

164+
# Flag to indicate if this script has stopped Actions.
165+
ACTIONS_STOPPED=false
166+
164167
# ghe-restore-snapshot-path validates it exists, determines what current is,
165168
# and if there's any problem, exit for us
166169
GHE_RESTORE_SNAPSHOT_PATH="$(ghe-restore-snapshot-path "$snapshot_id")"
@@ -399,6 +402,9 @@ fi
399402

400403
if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
401404
echo "Stopping Actions before restoring databases ..."
405+
# We mark Actions as stopped even if the `ghe-actions-stop`
406+
# fails to ensure that we cleanly start actions when performing cleanup.
407+
ACTIONS_STOPPED=true
402408
ghe-ssh "$GHE_HOSTNAME" -- 'ghe-actions-stop' 1>&3
403409

404410
echo "Restoring MSSQL databases ..."

test/test-ghe-restore.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,25 @@ begin_test "ghe-restore stops and starts Actions"
410410
echo "$output" | grep -q "ghe-actions-stop .* OK"
411411
echo "$output" | grep -q "ghe-actions-start .* OK"
412412
)
413+
end_test
414+
415+
begin_test "ghe-restore does not attempt to start Actions during cleanup if they never have been stopped"
416+
(
417+
set -e
418+
rm -rf "$GHE_REMOTE_ROOT_DIR"
419+
setup_remote_metadata
420+
enable_actions
421+
422+
setup_maintenance_mode "configured"
423+
# We are not in maintance mode which means that we don't stop Actions and abort early.
424+
disable_maintenance_mode
425+
426+
! output=$(ghe-restore -v -f localhost 2>&1)
427+
428+
! echo "$output" | grep -q "ghe-actions-stop"
429+
! echo "$output" | grep -q "ghe-actions-start"
430+
)
431+
end_test
413432

414433
begin_test "ghe-restore with Actions data"
415434
(

test/testlib.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ setup_maintenance_mode () {
120120
mkdir -p "$GHE_REMOTE_DATA_USER_DIR/repositories"
121121
}
122122

123+
# Moves the instance out of maintenance mode.
124+
disable_maintenance_mode () {
125+
# Remove file used to determine if instance is in maintenance mode.
126+
rm "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"
127+
}
128+
123129
# Mark the beginning of a test. A subshell should immediately follow this
124130
# statement.
125131
begin_test () {

0 commit comments

Comments
 (0)