57ea5789
Antonio Terceiro
Support using lxc...
|
1
2
|
require 'yaml'
|
7ac21657
Antonio Terceiro
Rakefile: load 'l...
|
3
4
5
6
7
8
|
begin
load 'local.rake'
rescue LoadError
# nothing
end
|
53720ead
Antonio Terceiro
Rename "developme...
|
9
|
$SPB_ENV = ENV.fetch('SPB_ENV', 'local')
|
942a634a
Antonio Terceiro
Remove IP address...
|
10
|
|
23a7805f
Antonio Terceiro
Use separate SSH ...
|
11
|
ssh_config_file = "config/#{$SPB_ENV}/ssh_config"
|
3e39c878
Antonio Terceiro
Move list of IP a...
|
12
13
|
ips_file = "config/#{$SPB_ENV}/ips.yaml"
config_file = "config/#{$SPB_ENV}/config.yaml"
|
df683687
Sergio Oliveira
Manage firewall r...
|
14
|
iptables_file = "config/#{$SPB_ENV}/iptables-filter-rules"
|
3e39c878
Antonio Terceiro
Move list of IP a...
|
15
|
|
d327915b
Antonio Terceiro
Use one CHAKE_TMP...
|
16
|
ENV['CHAKE_TMPDIR'] = "tmp/chake.#{$SPB_ENV}"
|
23a7805f
Antonio Terceiro
Use separate SSH ...
|
17
18
|
ENV['CHAKE_SSH_CONFIG'] = ssh_config_file
|
53326c17
Antonio Terceiro
fix my stupidity
|
19
20
21
22
|
chake_rsync_options = ENV['CHAKE_RSYNC_OPTIONS'].to_s.clone
chake_rsync_options += ' --exclude backups'
chake_rsync_options += ' --exclude src'
ENV['CHAKE_RSYNC_OPTIONS'] = chake_rsync_options
|
52f2d929
Athos
Do not upload the...
|
23
|
|
57ea5789
Antonio Terceiro
Support using lxc...
|
24
25
26
27
28
29
30
31
32
33
34
35
36
|
if $SPB_ENV == 'lxc'
system("mkdir -p config/lxc; sudo lxc-ls -f -F name,ipv4 | sed -e '/^softwarepublico/ !d; s/softwarepublico_//; s/_[0-9_]*/:/ ' > #{ips_file}.new")
begin
ips = YAML.load_file("#{ips_file}.new")
raise ArgumentError unless ips.is_a?(Hash)
FileUtils.mv ips_file + '.new', ips_file
rescue Exception => ex
puts ex.message
puts
puts "Q: did you boot the containers first?"
exit
end
config = YAML.load_file('config/local/config.yaml')
|
57ea5789
Antonio Terceiro
Support using lxc...
|
37
38
39
40
41
|
File.open(config_file, 'w') do |f|
f.puts(YAML.dump(config))
end
File.open('config/lxc/iptables-filter-rules', 'w') do |f|
|
5ff1b4a5
Tallys Martins
Fixes lxc bridge ...
|
42
43
|
lxc_host_bridge_name = `awk '{ if ($1 == "lxc.network.link") { print($3) } }' /etc/lxc/default.conf`.strip
lxc_host_bridge_ip = ` /sbin/ifconfig #{lxc_host_bridge_name} | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1 }' `.strip
|
57ea5789
Antonio Terceiro
Support using lxc...
|
44
|
f.puts "-A INPUT -s #{lxc_host_bridge_ip} -p tcp -m state --state NEW --dport 22 -j ACCEPT"
|
37f8ac41
Antonio Terceiro
lxc: also whiteli...
|
45
|
f.puts "-A INPUT -s #{lxc_host_bridge_ip} -p tcp -m state --state NEW --dport 5555 -j ACCEPT"
|
57ea5789
Antonio Terceiro
Support using lxc...
|
46
47
48
|
end
end
|
23a7805f
Antonio Terceiro
Use separate SSH ...
|
49
50
|
require 'chake'
|
3544fc36
Paulo Tada
Updating chake ve...
|
51
|
if Gem::Version.new(Chake::VERSION) < Gem::Version.new('0.13')
|
b8b38926
Antonio Terceiro
check dependencie...
|
52
|
fail "Please upgrade to chake 0.10+"
|
23a7805f
Antonio Terceiro
Use separate SSH ...
|
53
54
|
end
|
57ea5789
Antonio Terceiro
Support using lxc...
|
55
56
57
|
ips ||= YAML.load_file(ips_file)
config ||= YAML.load_file(config_file)
firewall ||= File.open(iptables_file).read
|
ffef2fa2
Rodrigo Siqueira de Melo
Clean yum cache b...
|
58
|
config['keep_yum_cache'] = ENV['keep_yum_cache'] ? true : false
|
942a634a
Antonio Terceiro
Remove IP address...
|
59
|
$nodes.each do |node|
|
e0172c8c
Antonio Terceiro
munin: display en...
|
60
|
node.data['environment'] = $SPB_ENV
|
999fbfe3
Antonio Terceiro
Extract config da...
|
61
|
node.data['config'] = config
|
942a634a
Antonio Terceiro
Remove IP address...
|
62
|
node.data['peers'] = ips
|
df683687
Sergio Oliveira
Manage firewall r...
|
63
|
node.data['firewall'] = firewall
|
942a634a
Antonio Terceiro
Remove IP address...
|
64
65
|
end
|
942a634a
Antonio Terceiro
Remove IP address...
|
66
67
68
69
70
|
task :console do
require 'pry'
binding.pry
end
|
f47a7caa
Antonio Terceiro
Add first bits of...
|
71
|
task :test do
|
6e01ed62
Athos
Fix test_helper.s...
|
72
|
sh "SPB_ENV=#{$SPB_ENV} ./test/run_all"
|
f47a7caa
Antonio Terceiro
Add first bits of...
|
73
74
|
end
|
aede9435
Antonio Terceiro
centralize IP con...
|
75
|
file 'ssh_config.erb'
|
57ea5789
Antonio Terceiro
Support using lxc...
|
76
77
78
79
80
81
82
83
|
if ['local', 'lxc'].include?($SPB_ENV)
file ssh_config_file => ['nodes.yaml', ips_file, 'ssh_config.erb', 'Rakefile'] do |t|
require 'erb'
template = ERB.new(File.read('ssh_config.erb'))
File.open(t.name, 'w') do |f|
f.write(template.result(binding))
end
puts 'ERB %s' % t.name
|
aede9435
Antonio Terceiro
centralize IP con...
|
84
|
end
|
aede9435
Antonio Terceiro
centralize IP con...
|
85
|
end
|
2d01f6b8
Antonio Terceiro
Rakefile: make bo...
|
86
87
|
task 'bootstrap_common' => ssh_config_file
task 'run_input' => ssh_config_file
|
aede9435
Antonio Terceiro
centralize IP con...
|
88
|
|
5d1b6a66
Athos
Remove backups di...
|
89
|
desc 'Downloads latest system backups to backups directory. WARNING: This overrides anything written in the backups directory'
|
e1d28e4b
Matheus Fernandes
Add rake backup a...
|
90
|
task :backup => ssh_config_file do
|
4567db1b
Athos
Add missing resto...
|
91
|
# setup
|
5d1b6a66
Athos
Remove backups di...
|
92
|
sh 'rm', '-rf', 'backups'
|
e1d28e4b
Matheus Fernandes
Add rake backup a...
|
93
|
sh 'mkdir', '-p', 'backups'
|
4567db1b
Athos
Add missing resto...
|
94
|
# integration
|
ce25b7d2
Athos
Fix backup and re...
|
95
96
|
sh 'ssh', '-F', ssh_config_file, 'integration', 'sudo', 'chmod a+xr /.snapshots'
sh 'scp', '-F', ssh_config_file, 'integration:/.snapshots/hourly.0/spb/*', 'backups/'
|
4567db1b
Athos
Add missing resto...
|
97
|
# social
|
ce25b7d2
Athos
Fix backup and re...
|
98
99
|
sh 'ssh', '-F', ssh_config_file, 'social', 'sudo', 'chmod a+xr /.snapshots'
sh 'scp', '-F', ssh_config_file, 'social:/.snapshots/hourly.0/spb/*', 'backups/'
|
e1d28e4b
Matheus Fernandes
Add rake backup a...
|
100
101
|
end
|
5d1b6a66
Athos
Remove backups di...
|
102
|
desc 'Restores content saved in the backups directory to the target env. WARNING: This will drop all the current databases'
|
ce25b7d2
Athos
Fix backup and re...
|
103
|
task :restore => [ssh_config_file, config_file] do
|
bfef631c
Athos
Drop noosfero dat...
|
104
105
|
# setup
sh 'ssh', '-F', ssh_config_file, 'integration', 'sudo', 'rm -rf /tmp/backups'
|
ce25b7d2
Athos
Fix backup and re...
|
106
|
sh 'ssh', '-F', ssh_config_file, 'integration', 'sudo', 'systemctl stop colab'
|
bfef631c
Athos
Drop noosfero dat...
|
107
108
|
sh 'ssh', '-F', ssh_config_file, 'social', 'sudo', 'rm -rf /tmp/backups'
sh 'ssh', '-F', ssh_config_file, 'social', 'sudo', 'systemctl stop noosfero'
|
ce25b7d2
Athos
Fix backup and re...
|
109
110
|
sh 'ssh', '-F', ssh_config_file, 'database', 'sudo', 'sudo -u postgres dropdb colab 2> /dev/null'
sh 'ssh', '-F', ssh_config_file, 'database', 'sudo', 'sudo -u postgres createdb colab --owner colab 2> /dev/null'
|
bfef631c
Athos
Drop noosfero dat...
|
111
112
|
sh 'ssh', '-F', ssh_config_file, 'database', 'sudo', 'sudo -u postgres dropdb noosfero 2> /dev/null'
sh 'ssh', '-F', ssh_config_file, 'database', 'sudo', 'sudo -u postgres createdb noosfero --owner noosfero 2> /dev/null'
|
e1d28e4b
Matheus Fernandes
Add rake backup a...
|
113
114
115
|
#integration
sh 'scp', '-r', '-F', ssh_config_file, 'backups', 'integration:/tmp'
sh 'scp', '-F', ssh_config_file, 'utils/migration/restore_integration.sh', 'integration:/tmp'
|
ce25b7d2
Athos
Fix backup and re...
|
116
|
sh 'ssh', '-F', ssh_config_file, 'integration', 'sudo', "env SPB_URL=#{config['lists_hostname']} /tmp/restore_integration.sh"
|
e1d28e4b
Matheus Fernandes
Add rake backup a...
|
117
118
119
120
|
#social
sh 'scp', '-r', '-F', ssh_config_file, 'backups', 'social:/tmp'
sh 'scp', '-F', ssh_config_file, 'utils/migration/restore_social.sh', 'social:/tmp'
sh 'ssh', '-F', ssh_config_file, 'social', 'sudo', '/tmp/restore_social.sh'
|
bfef631c
Athos
Drop noosfero dat...
|
121
|
sh 'ssh', '-F', ssh_config_file, 'social', 'sudo', 'systemctl start noosfero'
|
ce25b7d2
Athos
Fix backup and re...
|
122
|
sh 'ssh', '-F', ssh_config_file, 'integration', 'sudo', 'systemctl start colab'
|
e1d28e4b
Matheus Fernandes
Add rake backup a...
|
123
124
|
end
|
481ffab7
Arthur Esposte
Add documentation...
|
125
126
127
128
129
130
131
132
|
namespace :export_data do
task :noosfero => [ssh_config_file, config_file] do
# setup
sh 'mkdir', '-p', 'exported_data'
#social
sh 'ssh', '-F', ssh_config_file, 'social', 'cd /usr/lib/noosfero/ && sudo -u noosfero RAILS_ENV=production bundle exec rake export:catalog:csv'
sh 'scp', '-F', ssh_config_file, 'social:/tmp/software_catalog_csvs.tar.gz', 'exported_data/'
end
|
2a10f681
Arthur Esposte
Add exported_data...
|
133
134
|
end
|
b8b38926
Antonio Terceiro
check dependencie...
|
135
|
task :bootstrap_common => :check_dependencies
|
d0c7dab3
Antonio Terceiro
Fix services conf...
|
136
|
|
341821af
Antonio Terceiro
Rakefile: make co...
|
137
138
|
unless ENV['nodeps']
task 'converge:integration' => 'converge:database'
|
f40ecb03
Antonio Terceiro
Make converge:int...
|
139
|
task 'converge:integration' => 'converge:social'
|
7ec65795
Antonio Terceiro
Noosfero configur...
|
140
|
task 'converge:social' => 'converge:database'
|
ca899415
Antonio Terceiro
Publish documenta...
|
141
|
task 'upload:reverseproxy' => 'doc'
|
341821af
Antonio Terceiro
Rakefile: make co...
|
142
|
end
|
0433524f
Antonio Terceiro
Add `preconfig` t...
|
143
144
145
146
147
148
|
$ALT_SSH_PORT = config.fetch('alt_ssh_port', 2222)
$nodes.find { |n| n.hostname == 'reverseproxy' }.data['ssh_port'] = $ALT_SSH_PORT
desc 'Makes configurations needed before the bootstrap phase'
task :preconfig => ssh_config_file do
|
d902bc15
Sergio Oliveira
Created tmp direc...
|
149
|
sh 'mkdir', '-p', 'tmp/'
|
0433524f
Antonio Terceiro
Add `preconfig` t...
|
150
151
152
153
154
155
|
preconfig_file = "tmp/preconfig.#{$SPB_ENV}.stamp"
if File.exist?(preconfig_file)
puts "I: preconfig already done."
puts "I: delete #{preconfig_file} to force running again"
else
sh 'scp', '-F', ssh_config_file, 'utils/reverseproxy_ssh_setup', 'reverseproxy.unconfigured:/tmp'
|
87b9ec69
Paulo Tada
Fix preconfig scr...
|
156
|
sh 'ssh', '-F', ssh_config_file, 'reverseproxy.unconfigured', 'sudo', '/tmp/reverseproxy_ssh_setup', $ALT_SSH_PORT.to_s, config['external_ip'], ips['reverseproxy'], ips['integration']
|
0433524f
Antonio Terceiro
Add `preconfig` t...
|
157
158
159
160
161
162
|
File.open(preconfig_file, 'w') do |f|
f.puts($ALT_SSH_PORT)
end
end
end
|
2ee1cfc0
Antonio Terceiro
Add task to build...
|
163
164
|
Dir.glob('tasks/*.rake').each { |f| load f }
|