Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
FooBarWidget committed Aug 8, 2024
1 parent 70eb636 commit 90d73cf
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions internal-scripts/ci-cd/publish/restart-web-server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RestartWebServer

# There's only one web server, so no need to call yum.fullstaqruby.org
RESTART_WEB_SERVER_API_URL = 'https://apt.fullstaqruby.org/admin/restart_web_server'
LATEST_REPO_VERSION_URL = 'https://apt.fullstaqruby.org/latest_version'
LATEST_REPO_QUERY_TIMESTAMP_URL = 'https://apt.fullstaqruby.org/latest_version'

TIMEOUT_SECS = 12

Expand All @@ -20,33 +20,31 @@ def main
require_envvar('ID_TOKEN')

begin
orig_version = get_latest_production_repo_version
orig_timestamp = get_latest_production_repo_query_timestamp
rescue QueryError, SystemCallError => e
abort("ERROR: failed to query latest version: #{e.message}")
abort("ERROR: failed to query latest web server timestamp: #{e.message}")
end

log_notice 'Restarting web servers'
initiate_restart_web_server

log_notice 'Waiting until web server is restarted'
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + TIMEOUT_SECS
puts "deadline = #{deadline}"
while true
puts "current time = #{Process.clock_gettime(Process::CLOCK_MONOTONIC)}"
if Process.clock_gettime(Process::CLOCK_MONOTONIC) >= deadline
abort('ERROR: Timed out waiting for web server to restart')
end

begin
version = get_latest_production_repo_version
timestamp = get_latest_production_repo_query_timestamp
rescue QueryError, SystemCallError => e
log_info "Error querying latest version: #{e.message}"
log_info "Error querying latest web server timestamp: #{e.message}"
log_info 'Retrying in 5s...'
sleep 5
next
end

if version == orig_version
if timestamp == orig_timestamp
log_info 'Web server has not restarted yet; waiting...'
sleep 5
next
Expand All @@ -72,8 +70,8 @@ def initiate_restart_web_server
end
end

def get_latest_production_repo_version
uri = URI(LATEST_REPO_VERSION_URL)
def get_latest_production_repo_query_timestamp
uri = URI(LATEST_REPO_QUERY_TIMESTAMP_URL)
resp = Net::HTTP.get_response(uri)
if resp.code.to_i / 100 == 2
resp.body
Expand Down

0 comments on commit 90d73cf

Please sign in to comment.