-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh.rb
More file actions
32 lines (28 loc) · 1.11 KB
/
ssh.rb
File metadata and controls
32 lines (28 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'net/ssh'
COMMANDS = {:full_update => 'bucardo update sync the_sync onetimecopy=2',
:reload_sync => 'bucardo reload the_sync',
:status => 'bucardo status the_sync',
:stop => 'bucardo stop',
:start => 'bucardo start',
:wait => 'sleep 5',
:truncate_slave => 'su - postgres -c \'psql -U postgres -d jaka_db -c "truncate public.microposts, public.users, public.relationships, public.schema_migrations"\''
}
slave_ip = '188.166.15.157'
master_ip = '128.199.59.160'
time = Time.now
Net::SSH.start(slave_ip, 'root') do |ssh|
[:truncate_slave].each do |command|
puts "Running command " + command.to_s
output = ssh.exec!(COMMANDS[command])
puts output
end
end
Net::SSH.start(master_ip, 'root') do |ssh|
[:status, :full_update, :reload, :stop, :wait, :start, :status].each do |command|
puts "Running command " + command.to_s
output = ssh.exec!(COMMANDS[command])
puts output
end
puts Time.now - time
end
#add before_action to application_controller to clear activerecord id