fix crons

This commit is contained in:
Torsten 2022-03-28 01:05:11 +03:00
parent 435229680d
commit dd1bdc9995

View File

@ -16,14 +16,10 @@ class Routers
end end
# print info for each ip # print info for each ip
def print( info = nil) def print( info )
info = "host_name" unless info info = "host_name" unless info
ips(false) do |ip , connection| each_router do |ip , connection|
if connection.is_a?(String) message = send(info.to_sym , connection)
message = connection
else
message = send(info.to_sym , connection)
end
puts "#{ip} = #{message}" puts "#{ip} = #{message}"
end end
end end
@ -40,7 +36,7 @@ class Routers
cron_file = "/etc/crontabs/root" cron_file = "/etc/crontabs/root"
cron_create = "echo '#{cron_job}' > #{cron_file}" cron_create = "echo '#{cron_job}' > #{cron_file}"
crond_restart = "/etc/init.d/cron restart" crond_restart = "/etc/init.d/cron restart"
ips do |ip , connection| each_router do |ip , connection|
connection.exec!(cron_create) connection.exec!(cron_create)
connection.exec!(crond_restart) connection.exec!(crond_restart)
puts "Cron for #{ip} ok" puts "Cron for #{ip} ok"
@ -66,7 +62,7 @@ class Routers
def each_router def each_router
routers = YAML::load(File.open("#{Rails.root}/config/routers.yml")) routers = YAML::load(File.open("#{Rails.root}/config/routers.yml"))
routers.each do |ip ,info| routers.each do |ip ,info|
connection = Net::SSH.start(at , "root" , connection = Net::SSH.start(ip , "root" ,
password: Rails.application.credentials.sala, password: Rails.application.credentials.sala,
non_interactive: true , non_interactive: true ,
timeout: 4) timeout: 4)