Merge pull request #927 from github/jcambass/2022-06-15/only_restart_actions_if_stopped

Only Start Actions if they have been Stopped
This commit is contained in:
Joel Ambass 2022-06-20 15:24:00 +02:00 коммит произвёл GitHub
Родитель d980b43850 20db671238
Коммит 11143678e5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 32 добавлений и 1 удалений

Просмотреть файл

@ -104,7 +104,7 @@ cleanup () {
update_restore_status "$1"
fi
if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
if $ACTIONS_STOPPED && ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
echo "Restarting Actions after restore ..."
# In GHES 3.3+, ghe-actions-start no longer has a -f (force) flag. In GHES 3.2 and below, we must provide the
# 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 :)
# Show usage with no <host>
[ -z "$GHE_HOSTNAME" ] && print_usage
# Flag to indicate if this script has stopped Actions.
ACTIONS_STOPPED=false
# ghe-restore-snapshot-path validates it exists, determines what current is,
# and if there's any problem, exit for us
GHE_RESTORE_SNAPSHOT_PATH="$(ghe-restore-snapshot-path "$snapshot_id")"
@ -399,6 +402,9 @@ fi
if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
echo "Stopping Actions before restoring databases ..."
# We mark Actions as stopped even if the `ghe-actions-stop`
# fails to ensure that we cleanly start actions when performing cleanup.
ACTIONS_STOPPED=true
ghe-ssh "$GHE_HOSTNAME" -- 'ghe-actions-stop' 1>&3
echo "Restoring MSSQL databases ..."

Просмотреть файл

@ -410,6 +410,25 @@ begin_test "ghe-restore stops and starts Actions"
echo "$output" | grep -q "ghe-actions-stop .* OK"
echo "$output" | grep -q "ghe-actions-start .* OK"
)
end_test
begin_test "ghe-restore does not attempt to start Actions during cleanup if they never have been stopped"
(
set -e
rm -rf "$GHE_REMOTE_ROOT_DIR"
setup_remote_metadata
enable_actions
setup_maintenance_mode "configured"
# We are not in maintance mode which means that we don't stop Actions and abort early.
disable_maintenance_mode
! output=$(ghe-restore -v -f localhost 2>&1)
! echo "$output" | grep -q "ghe-actions-stop"
! echo "$output" | grep -q "ghe-actions-start"
)
end_test
begin_test "ghe-restore with Actions data"
(

Просмотреть файл

@ -120,6 +120,12 @@ setup_maintenance_mode () {
mkdir -p "$GHE_REMOTE_DATA_USER_DIR/repositories"
}
# Moves the instance out of maintenance mode.
disable_maintenance_mode () {
# Remove file used to determine if instance is in maintenance mode.
rm "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"
}
# Mark the beginning of a test. A subshell should immediately follow this
# statement.
begin_test () {