mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 14:38:17 +08:00
parent
98354bd34c
commit
4c6eeaac15
|
@ -1,10 +1,12 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'resolv'
|
require 'resolv'
|
||||||
require 'time'
|
require 'time'
|
||||||
require 'timeout'
|
|
||||||
require 'socket'
|
require 'socket'
|
||||||
|
|
||||||
|
REFRESH_SECONDS = 30
|
||||||
|
|
||||||
HOSTS_PATH = "/etc/hosts"
|
HOSTS_PATH = "/etc/hosts"
|
||||||
|
|
||||||
CRITICAL_HOST_ENV_VARS = %w{
|
CRITICAL_HOST_ENV_VARS = %w{
|
||||||
|
@ -26,7 +28,7 @@ def swap_address(hosts, name, ips)
|
||||||
new_file = []
|
new_file = []
|
||||||
|
|
||||||
hosts.split("\n").each do |line|
|
hosts.split("\n").each do |line|
|
||||||
line = line.strip
|
line.strip!
|
||||||
if line[0] != '#'
|
if line[0] != '#'
|
||||||
_, hostname = line.strip.split(/\s+/)
|
_, hostname = line.strip.split(/\s+/)
|
||||||
next if hostname == name
|
next if hostname == name
|
||||||
|
@ -118,7 +120,7 @@ end
|
||||||
end.compact
|
end.compact
|
||||||
|
|
||||||
def loop
|
def loop
|
||||||
errors = {}
|
errors = Hash.new(0)
|
||||||
|
|
||||||
Resolv::DNS.open do |dns|
|
Resolv::DNS.open do |dns|
|
||||||
dns.timeouts = 2
|
dns.timeouts = 2
|
||||||
|
@ -132,7 +134,6 @@ def loop
|
||||||
entries = hosts_entries(dns, var)
|
entries = hosts_entries(dns, var)
|
||||||
rescue => e
|
rescue => e
|
||||||
error("Failed to resolve DNS for #{name} - #{e}")
|
error("Failed to resolve DNS for #{name} - #{e}")
|
||||||
errors[host] ||= 0
|
|
||||||
errors[host] += 1
|
errors[host] += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -140,7 +141,6 @@ def loop
|
||||||
resolved[host] = entries
|
resolved[host] = entries
|
||||||
else
|
else
|
||||||
error("Failed to find any DNS entry for #{var} : #{ENV[var]}")
|
error("Failed to find any DNS entry for #{var} : #{ENV[var]}")
|
||||||
errors[host] ||= 0
|
|
||||||
errors[host] += 1
|
errors[host] += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -176,5 +176,5 @@ end
|
||||||
|
|
||||||
while true
|
while true
|
||||||
loop
|
loop
|
||||||
sleep 30
|
sleep REFRESH_SECONDS
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user