forked from moonpolysoft/dynomite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Capfile
97 lines (81 loc) · 2.73 KB
/
Capfile
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#Define your servers in servers.rb like so:
# role :dyn, "server1",
# "server2",
# "server3",
# "server4"
#
# role :tester, "server5"
load "servers.rb"
set :storage, (ENV["STORAGE"] || "dets_storage")
namespace :dynomite do
desc <<-EOF
Deploy dynomite via rsync, configure the data directories
and launch one node per server.
EOF
task :default, :roles => :dyn do
deploy.rsync
deploy.compile
deploy.data_reset
deploy.config
deploy.start
end
task :bench, :roles => :tester do
run "ruby dynomite/rlibs/distributed_bench.rb"
end
task :stop, :roles => :dyn do
deploy.stop
end
namespace :deploy do
task :rsync do
username = ENV['USER']
execute_on_servers(options) do |servers|
servers.each do |server|
puts %Q(rsync -avz -e ssh "./" "#{username}@#{server}:dynomite" --exclude ".git" --exclude "etest/log")
`rsync -avz -e ssh "./" "#{username}@#{server}:dynomite" --exclude ".git" --exclude "etest/log"`
end
end
end
task :compile do
run "cd dynomite && rake clean && rake native default"
end
task :data_reset, :roles => :dyn do
run "rm -rf /bfd/dyn-int-data dyn-int-log/*"
run "mkdir -p /bfd/dyn-int-data"
run "mkdir -p dyn-int-log"
end
task :config, :roles => :dyn do
configuration = ENV["CONFIG"] || "dist_config.json"
contents = File.read(configuration)
put(contents, "./dynomite/config.json")
end
task :start, :roles => :dyn, :depends => [:data_reset, :config] do
execute_on_servers(options) do |servers|
first_server = servers.shift
shortname = first_server.to_s.split('.').first
first = sessions[first_server]
rest = servers.map {|s| sessions[s]}
puts shortname
if ENV["SERVERS"]
rest = rest[0...(ENV["SERVERS"].to_i-1)]
end
Command.process("./dynomite/bin/dynomite start -c config.json -l ~/dyn-int-log -d", [first], options.merge(:logger => logger))
sleep(3)
Command.process("./dynomite/bin/dynomite start -c config.json -j dynomite@#{shortname} -l ~/dyn-int-log -d", rest, options.merge(:logger => logger))
end
end
task :stop, :roles => :dyn do
run "./dynomite/bin/dynomite stop"
end
end
end
def put_file(path, remote_path, options = {})
execute_on_servers(options) do |servers|
servers.each do |server|
logger.info "uploading #{File.basename(path)} to #{server}"
sftp = sessions[server].sftp
sftp.connect unless sftp.state == :open
sftp.put_file path, remote_path
logger.debug "done uploading #{File.basename(path)} to #{server}"
end
end
end