badger-rails 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/BadgerGit.png +0 -0
- data/COPYING +674 -0
- data/LICENSING +30 -0
- data/Manifest +112 -0
- data/README.md +80 -0
- data/Rakefile +36 -0
- data/badger-rails.gemspec +34 -0
- data/bin/badger +486 -0
- data/lib/badger/Capfile +1 -0
- data/lib/badger/config/deploy.rb +211 -0
- data/lib/badger/config/rails-app.yml +6 -0
- data/lib/badger/config/rails-app.yml.bk +6 -0
- data/lib/badger/core/claws/app.claw +112 -0
- data/lib/badger/core/claws/db-app.claw +59 -0
- data/lib/badger/core/claws/rails-app.claw +125 -0
- data/lib/badger/core/files/badger/info +0 -0
- data/lib/badger/core/files/cap/Capfile +4 -0
- data/lib/badger/core/files/cap/deploy/production-app.rb +139 -0
- data/lib/badger/core/files/cap/deploy/production.rb +136 -0
- data/lib/badger/core/files/cap/deploy/staging-app.rb +139 -0
- data/lib/badger/core/files/cap/deploy/staging.rb +134 -0
- data/lib/badger/core/files/cap/deploy.rb +6 -0
- data/lib/badger/core/files/git/git +0 -0
- data/lib/badger/core/files/god/angel/resque-dev.god +54 -0
- data/lib/badger/core/files/god/angel/resque-stg.god +54 -0
- data/lib/badger/core/files/god/angel/resque.god +55 -0
- data/lib/badger/core/files/god/angel/unicorn-stg.god +62 -0
- data/lib/badger/core/files/god/angel/unicorn.god +62 -0
- data/lib/badger/core/files/god/god +108 -0
- data/lib/badger/core/files/god/unicorn-stg.rb +70 -0
- data/lib/badger/core/files/god/unicorn.rb +70 -0
- data/lib/badger/core/files/logrotate/logrotate.conf +23 -0
- data/lib/badger/core/files/logrotate/logrotate.cron +8 -0
- data/lib/badger/core/files/mysql/database.yml.bk +18 -0
- data/lib/badger/core/files/mysql/db_stats +0 -0
- data/lib/badger/core/files/mysql/my.cnf +11 -0
- data/lib/badger/core/files/nginx/nginx +106 -0
- data/lib/badger/core/files/nginx/nginx.conf +30 -0
- data/lib/badger/core/files/nginx/sites/port443.btl +42 -0
- data/lib/badger/core/files/nginx/sites/port80.btl +39 -0
- data/lib/badger/core/files/nginx/sites/production-web +117 -0
- data/lib/badger/core/files/nginx/sites/staging-web +41 -0
- data/lib/badger/core/files/postfix/main.cf +678 -0
- data/lib/badger/core/files/postfix/master.cf +81 -0
- data/lib/badger/core/files/redis/redis-server +59 -0
- data/lib/badger/core/files/redis/redis.conf +444 -0
- data/lib/badger/core/files/resque/resque.rb +5 -0
- data/lib/badger/core/files/resque/resque.yml +19 -0
- data/lib/badger/core/files/resque/resque_web.rb +2 -0
- data/lib/badger/core/files/ssh/authorized_keys +0 -0
- data/lib/badger/core/functions +174 -0
- data/lib/badger/core/scripts/app_info +40 -0
- data/lib/badger/core/scripts/app_scale +15 -0
- data/lib/badger/core/scripts/remove_app +25 -0
- data/lib/badger/core/scripts/remove_app_db +30 -0
- data/lib/badger/core/scripts/remove_gems +2 -0
- data/lib/badger/core/teeth/automake.th +9 -0
- data/lib/badger/core/teeth/badger.th +27 -0
- data/lib/badger/core/teeth/bison.th +20 -0
- data/lib/badger/core/teeth/bundler.th +4 -0
- data/lib/badger/core/teeth/capistrano-ext.th +37 -0
- data/lib/badger/core/teeth/chkconfig.th +4 -0
- data/lib/badger/core/teeth/curl.th +24 -0
- data/lib/badger/core/teeth/faac.th +11 -0
- data/lib/badger/core/teeth/ffmpeg.th +28 -0
- data/lib/badger/core/teeth/firewall.th +70 -0
- data/lib/badger/core/teeth/gcc-c++.th +9 -0
- data/lib/badger/core/teeth/gcc.th +9 -0
- data/lib/badger/core/teeth/git.th +23 -0
- data/lib/badger/core/teeth/god.th +17 -0
- data/lib/badger/core/teeth/lame.th +9 -0
- data/lib/badger/core/teeth/libffi.th +4 -0
- data/lib/badger/core/teeth/libid3tag.th +10 -0
- data/lib/badger/core/teeth/libmad.th +11 -0
- data/lib/badger/core/teeth/libogg.th +9 -0
- data/lib/badger/core/teeth/libtool.th +9 -0
- data/lib/badger/core/teeth/libxml2.th +19 -0
- data/lib/badger/core/teeth/libxslt.th +19 -0
- data/lib/badger/core/teeth/libyaml.th +19 -0
- data/lib/badger/core/teeth/logrotate.th +19 -0
- data/lib/badger/core/teeth/madplay.th +10 -0
- data/lib/badger/core/teeth/make.th +9 -0
- data/lib/badger/core/teeth/mysql-config.th +40 -0
- data/lib/badger/core/teeth/mysql-server.th +16 -0
- data/lib/badger/core/teeth/mysql.th +14 -0
- data/lib/badger/core/teeth/nginx.th +56 -0
- data/lib/badger/core/teeth/ntp.th +15 -0
- data/lib/badger/core/teeth/openssl.th +19 -0
- data/lib/badger/core/teeth/pcre.th +9 -0
- data/lib/badger/core/teeth/plugins.th +14 -0
- data/lib/badger/core/teeth/postfix.th +11 -0
- data/lib/badger/core/teeth/pwgen.th +9 -0
- data/lib/badger/core/teeth/rake.th +12 -0
- data/lib/badger/core/teeth/readline.th +19 -0
- data/lib/badger/core/teeth/redis.th +18 -0
- data/lib/badger/core/teeth/resque.th +12 -0
- data/lib/badger/core/teeth/ruby.th +52 -0
- data/lib/badger/core/teeth/rubygems.th +17 -0
- data/lib/badger/core/teeth/san_juan.th +4 -0
- data/lib/badger/core/teeth/sox.th +12 -0
- data/lib/badger/core/teeth/speex.th +12 -0
- data/lib/badger/core/teeth/sqlite3.th +14 -0
- data/lib/badger/core/teeth/ssh_keys.th +10 -0
- data/lib/badger/core/teeth/sshpass.th +9 -0
- data/lib/badger/core/teeth/sudo.th +9 -0
- data/lib/badger/core/teeth/syslog-ng.th +16 -0
- data/lib/badger/core/teeth/sysv-rc-conf.th +4 -0
- data/lib/badger/core/teeth/x264.th +11 -0
- data/lib/badger/core/teeth/xvid.th +11 -0
- data/lib/badger/core/teeth/yasm.th +11 -0
- data/lib/badger/core/teeth/zlib.th +9 -0
- data/lib/core.rb +313 -0
- data/lib/errors.rb +202 -0
- metadata +297 -0
data/bin/badger
ADDED
@@ -0,0 +1,486 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
#--------------------------------#
|
4
|
+
#--- Author Nathan Kelley -------#
|
5
|
+
#--- Company Curiousminds -------#
|
6
|
+
#--- Licensing@curiousminds.com -#
|
7
|
+
#--------------------------------#
|
8
|
+
#
|
9
|
+
require 'fileutils'
|
10
|
+
require 'rubygems'
|
11
|
+
require 'yaml'
|
12
|
+
require 'errors'
|
13
|
+
require 'core'
|
14
|
+
|
15
|
+
@errors = Errors.new
|
16
|
+
|
17
|
+
def remove_app(rails_root)
|
18
|
+
spec = Gem::Specification.find_by_name("badger-rails")
|
19
|
+
badger_root = spec.gem_dir + "/lib/"
|
20
|
+
FileUtils.cp(Dir.pwd + "/badger.yml", badger_root + "badger/config/rails-app.yml")
|
21
|
+
Dir.chdir(badger_root + "badger/")
|
22
|
+
while true
|
23
|
+
puts <<EOF
|
24
|
+
|
25
|
+
This will remove the #{ARGV[1]} project from the server.
|
26
|
+
Do you wish to remove the database as well? [ y/n ]
|
27
|
+
|
28
|
+
EOF
|
29
|
+
response = STDIN.gets.chomp
|
30
|
+
if response == "y"
|
31
|
+
exists = `cap #{ARGV[1]} exists`
|
32
|
+
if not exists.chomp == "true"
|
33
|
+
@errors.errors('rails')
|
34
|
+
exit
|
35
|
+
end
|
36
|
+
`cap #{ARGV[1]} removedb`
|
37
|
+
Dir.chdir(rails_root)
|
38
|
+
`git remote rm badger`
|
39
|
+
break
|
40
|
+
elsif response == "n"
|
41
|
+
exists = `cap #{ARGV[1]} exists`
|
42
|
+
if not exists.chomp == "true"
|
43
|
+
@errors.errors('rails')
|
44
|
+
exit
|
45
|
+
end
|
46
|
+
`cap #{ARGV[1]} remove`
|
47
|
+
Dir.chdir(rails_root)
|
48
|
+
`git remote rm badger`
|
49
|
+
break
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
unless ARGV[0].nil?
|
55
|
+
argv=ARGV[0].downcase
|
56
|
+
end
|
57
|
+
|
58
|
+
if argv.tr('^A-Za-z', '') == "app"
|
59
|
+
if ARGV[1] == "build"
|
60
|
+
core_app = Core.new
|
61
|
+
core_app.ensure_rails_root
|
62
|
+
core_app.ensure_external_db
|
63
|
+
core_app.create(argv)
|
64
|
+
exit
|
65
|
+
elsif ARGV[1] == "scale"
|
66
|
+
if ARGV[2].nil? or ARGV[2].to_i == "0"
|
67
|
+
@errors.errors('scale int')
|
68
|
+
exit
|
69
|
+
else
|
70
|
+
core_scale = Core.new
|
71
|
+
core_scale.ensure_rails_root
|
72
|
+
core_scale.scale ARGV[2], ARGV[0]
|
73
|
+
exit
|
74
|
+
end
|
75
|
+
else
|
76
|
+
if ARGV[1][0].downcase == "s"
|
77
|
+
@errors.errors('scale')
|
78
|
+
exit
|
79
|
+
elsif ARGV[1][0].downcase == "b"
|
80
|
+
@errors.errors('app build')
|
81
|
+
exit
|
82
|
+
else
|
83
|
+
@errors.errors('app usage')
|
84
|
+
exit
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
case argv
|
90
|
+
when "info"
|
91
|
+
core_info = Core.new
|
92
|
+
core_info.ensure_rails_root
|
93
|
+
core_info.info
|
94
|
+
|
95
|
+
when "create"
|
96
|
+
if ARGV[1].nil?
|
97
|
+
@errors.errors('name')
|
98
|
+
else
|
99
|
+
if ARGV[1] == "db" or ARGV[1][0..2] == "app"
|
100
|
+
@errors.errors('specific name')
|
101
|
+
exit
|
102
|
+
else
|
103
|
+
core_create = Core.new
|
104
|
+
core_create.ensure_rails_root
|
105
|
+
core_create.create
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
when "update"
|
110
|
+
if ARGV[1].nil?
|
111
|
+
@errors.errors('name')
|
112
|
+
else
|
113
|
+
core_update = Core.new
|
114
|
+
core_update.ensure_rails_root
|
115
|
+
core_update.update
|
116
|
+
end
|
117
|
+
|
118
|
+
when "db"
|
119
|
+
if not ARGV[1] == "build"
|
120
|
+
@errors.errors('db build')
|
121
|
+
else
|
122
|
+
core_db = Core.new
|
123
|
+
core_db.ensure_rails_root
|
124
|
+
core_db.db
|
125
|
+
end
|
126
|
+
|
127
|
+
when "gen", "g", "generate"
|
128
|
+
case ARGV[1].downcase
|
129
|
+
when "ruby-plugin"
|
130
|
+
config_dir = Dir.exists?("config/")
|
131
|
+
if config_dir
|
132
|
+
new_config_dir = Dir.pwd
|
133
|
+
if not File.exists?("lib/badger_plugin.rb")
|
134
|
+
badger_plugin = <<EOF
|
135
|
+
module BadgerPluginMethods
|
136
|
+
|
137
|
+
def initialize()
|
138
|
+
#code for pre-rails migration
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
class BadgerPlugin
|
144
|
+
include BadgerPluginMethods
|
145
|
+
end
|
146
|
+
EOF
|
147
|
+
`echo '#{badger_plugin}' >> lib/badger_plugin.rb`
|
148
|
+
puts <<EOF
|
149
|
+
|
150
|
+
lib/badger_plugin.rb
|
151
|
+
|
152
|
+
EOF
|
153
|
+
else
|
154
|
+
@errors.errors('plugins')
|
155
|
+
end
|
156
|
+
else
|
157
|
+
while not Dir.pwd == "/"
|
158
|
+
if Dir.exists?("config/")
|
159
|
+
break
|
160
|
+
else
|
161
|
+
Dir.chdir("..")
|
162
|
+
end
|
163
|
+
end
|
164
|
+
if Dir.pwd == "/"
|
165
|
+
@errors.errors('rails root')
|
166
|
+
else
|
167
|
+
config_dir = Dir.pwd
|
168
|
+
if not File.exists?("lib/badger_plugin.rb")
|
169
|
+
badger_plugin = <<EOF
|
170
|
+
module BadgerPluginMethods
|
171
|
+
|
172
|
+
def initialize()
|
173
|
+
#code for pre-rails migration
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
class BadgerPlugin
|
179
|
+
include BadgerPluginMethods
|
180
|
+
end
|
181
|
+
EOF
|
182
|
+
`echo '#{badger_plugin}' >> lib/badger_plugin.rb`
|
183
|
+
puts <<EOF
|
184
|
+
|
185
|
+
lib/badger_plugin.rb
|
186
|
+
|
187
|
+
EOF
|
188
|
+
else
|
189
|
+
@errors.errors('plugins')
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
when "plugins"
|
195
|
+
config_dir = Dir.exists?("config/")
|
196
|
+
if config_dir
|
197
|
+
new_config_dir = Dir.pwd
|
198
|
+
if not Dir.exists?("lib/badger/")
|
199
|
+
`mkdir -p lib/badger/teeth/;
|
200
|
+
touch lib/badger/before;
|
201
|
+
touch lib/badger/dev;
|
202
|
+
touch lib/badger/after;
|
203
|
+
touch lib/badger/teeth/fail2ban.th`
|
204
|
+
fail_2ban = <<EOF
|
205
|
+
#add_fail2ban() {
|
206
|
+
# fail2ban-client status && return 0
|
207
|
+
# yum -y install fail2ban
|
208
|
+
# fail2ban-client start
|
209
|
+
#}
|
210
|
+
EOF
|
211
|
+
`echo '#{fail_2ban}' >> lib/badger/teeth/fail2ban.th`
|
212
|
+
`echo '#add_fail2ban' >> lib/badger/after`
|
213
|
+
puts <<EOF
|
214
|
+
lib/badger
|
215
|
+
lib/badger/teeth/
|
216
|
+
lib/badger/after
|
217
|
+
lib/badger/before
|
218
|
+
lib/badger/dev
|
219
|
+
lib/badger/teeth/fail2ban.th
|
220
|
+
EOF
|
221
|
+
else
|
222
|
+
@errors.errors('plugins')
|
223
|
+
end
|
224
|
+
else
|
225
|
+
while not Dir.pwd == "/"
|
226
|
+
if Dir.exists?("config/")
|
227
|
+
break
|
228
|
+
else
|
229
|
+
Dir.chdir("..")
|
230
|
+
end
|
231
|
+
end
|
232
|
+
if Dir.pwd == "/"
|
233
|
+
@errors.errors('rails root')
|
234
|
+
else
|
235
|
+
config_dir = Dir.pwd
|
236
|
+
if not Dir.exists?("lib/badger/")
|
237
|
+
`mkdir -p lib/badger/teeth/;
|
238
|
+
touch lib/badger/before;
|
239
|
+
touch lib/badger/dev;
|
240
|
+
touch lib/badger/after;
|
241
|
+
touch lib/badger/teeth/fail2ban.th`
|
242
|
+
fail_2ban = <<EOF
|
243
|
+
#add_fail2ban() {
|
244
|
+
# fail2ban-client status && return 0
|
245
|
+
# yum -y install fail2ban
|
246
|
+
# fail2ban-client start
|
247
|
+
#}
|
248
|
+
EOF
|
249
|
+
`echo '#{fail_2ban}' >> lib/badger/teeth/fail2ban.th`
|
250
|
+
`echo '#add_fail2ban' >> lib/badger/after`
|
251
|
+
puts <<EOF
|
252
|
+
lib/badger
|
253
|
+
lib/badger/teeth/
|
254
|
+
lib/badger/after
|
255
|
+
lib/badger/before
|
256
|
+
lib/badger/dev
|
257
|
+
lib/badger/teeth/fail2ban.th
|
258
|
+
EOF
|
259
|
+
else
|
260
|
+
@errors.errors('plugins')
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
when "yml"
|
266
|
+
config_dir = Dir.exists?("config/")
|
267
|
+
if config_dir
|
268
|
+
new_config_dir = Dir.pwd
|
269
|
+
if not File.exists?("config/badger.yml")
|
270
|
+
`touch config/badger.yml`
|
271
|
+
badger_yml = <<EOF
|
272
|
+
username: "typically root"
|
273
|
+
password: "server password"
|
274
|
+
domain: "domain or ip of the server"
|
275
|
+
port: "ssh port usually port 22"
|
276
|
+
redis: false #true will host redis locally
|
277
|
+
environment: "production" # or "staging", development and testing are excluded.
|
278
|
+
EOF
|
279
|
+
`echo '#{badger_yml}' >> config/badger.yml`
|
280
|
+
puts "config/badger.yml"
|
281
|
+
else
|
282
|
+
@errors.errors('badger yaml')
|
283
|
+
end
|
284
|
+
else
|
285
|
+
while not Dir.pwd == "/"
|
286
|
+
if Dir.exists?("config/")
|
287
|
+
break
|
288
|
+
else
|
289
|
+
Dir.chdir("..")
|
290
|
+
end
|
291
|
+
end
|
292
|
+
if Dir.pwd == "/"
|
293
|
+
@errors.errors('rails root')
|
294
|
+
else
|
295
|
+
config_dir = Dir.pwd
|
296
|
+
if not File.exists?("config/badger.yml")
|
297
|
+
`touch config/badger.yml`
|
298
|
+
badger_yml = <<EOF
|
299
|
+
username: "typically root"
|
300
|
+
password: "server password"
|
301
|
+
domain: "domain or ip of the server"
|
302
|
+
port: "ssh port usually port 22"
|
303
|
+
redis: false #true will host redis locally
|
304
|
+
environment: "production" # or "staging", development and testing are excluded.
|
305
|
+
EOF
|
306
|
+
`echo '#{badger_yml}' >> config/badger.yml`
|
307
|
+
puts "config/badger.yml"
|
308
|
+
else
|
309
|
+
@errors.errors('badger yaml')
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
else
|
314
|
+
if ARGV[1][0].downcase == "p"
|
315
|
+
@errors.errors('generate plugins')
|
316
|
+
elsif ARGV[1][0].downcase == "y"
|
317
|
+
@errors.errors('generate yaml')
|
318
|
+
else
|
319
|
+
@errors.errors('generate')
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
when "remove"
|
324
|
+
if ARGV[1].nil?
|
325
|
+
@errors.errors('name')
|
326
|
+
else
|
327
|
+
config_dir = Dir.exists?("config/")
|
328
|
+
if config_dir
|
329
|
+
new_config_dir = Dir.pwd
|
330
|
+
Dir.chdir("config/")
|
331
|
+
remove_app(new_config_dir)
|
332
|
+
else
|
333
|
+
while not Dir.pwd == "/"
|
334
|
+
if Dir.exists?("config/")
|
335
|
+
break
|
336
|
+
else
|
337
|
+
Dir.chdir("..")
|
338
|
+
end
|
339
|
+
end
|
340
|
+
if Dir.pwd == "/"
|
341
|
+
@errors.errors('rails root')
|
342
|
+
else
|
343
|
+
config_dir = Dir.pwd
|
344
|
+
Dir.chdir("config/")
|
345
|
+
remove_app(config_dir)
|
346
|
+
end
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
when "rake"
|
351
|
+
core_rake = Core.new
|
352
|
+
core_rake.ensure_rails_root
|
353
|
+
core_rake.rake_tasks
|
354
|
+
|
355
|
+
when "logs"
|
356
|
+
core_logs = Core.new
|
357
|
+
core_logs.ensure_rails_root
|
358
|
+
core_logs.badger_logs
|
359
|
+
|
360
|
+
when "gemset"
|
361
|
+
case ARGV[1]
|
362
|
+
when "clear"
|
363
|
+
spec = Gem::Specification.find_by_name("badger-rails")
|
364
|
+
badger_root = spec.gem_dir + "/lib/"
|
365
|
+
Dir.chdir(badger_root + "badger/")
|
366
|
+
while true
|
367
|
+
puts <<EOF
|
368
|
+
|
369
|
+
Are you sure you want to remove all gems from the server? [ y/n ]
|
370
|
+
|
371
|
+
EOF
|
372
|
+
response = STDIN.gets.chomp
|
373
|
+
if response == "y"
|
374
|
+
`cap rails-app gemset_clear`
|
375
|
+
break
|
376
|
+
elsif response == "n"
|
377
|
+
exit
|
378
|
+
end
|
379
|
+
end
|
380
|
+
else
|
381
|
+
@errors.errors('gemset clear')
|
382
|
+
end
|
383
|
+
|
384
|
+
when "help", "-h", "--help"
|
385
|
+
@errors.errors('usage')
|
386
|
+
exit
|
387
|
+
|
388
|
+
when "deploy"
|
389
|
+
config_dir = Dir.exists?("config/")
|
390
|
+
if config_dir
|
391
|
+
new_config_dir = Dir.pwd
|
392
|
+
if `cat Gemfile.lock | grep therubyracer` == ""
|
393
|
+
@errors.errors('rubyracer')
|
394
|
+
exit
|
395
|
+
elsif `cat Gemfile.lock | grep mysql2` == ""
|
396
|
+
@errors.errors('mysql2')
|
397
|
+
exit
|
398
|
+
elsif `cat Gemfile.lock | grep unicorn` == ""
|
399
|
+
@errors.errors('unicorn')
|
400
|
+
exit
|
401
|
+
end
|
402
|
+
spec = Gem::Specification.find_by_name("badger-rails")
|
403
|
+
badger_root = spec.gem_dir + "/lib/"
|
404
|
+
if Dir.exists?("lib/badger/") and File.exists?("lib/badger/before") and File.exists?("lib/badger/after") and Dir.exists?("lib/badger/teeth/")
|
405
|
+
`cp -rf lib/badger #{badger_root}badger/core/scripts/badger`
|
406
|
+
else
|
407
|
+
`rm -rf #{badger_root}badger/core/scripts/badger`
|
408
|
+
end
|
409
|
+
Dir.chdir("config/")
|
410
|
+
FileUtils.cp(Dir.pwd + "/badger.yml", badger_root + "badger/config/rails-app.yml")
|
411
|
+
Dir.chdir(badger_root + "badger/")
|
412
|
+
if File.exists?("#{Dir.home}/.ssh/id_rsa.pub")
|
413
|
+
`cap rails-app deploy`
|
414
|
+
unless ARGV[1].nil?
|
415
|
+
if ARGV[1].downcase == "--with-workers"
|
416
|
+
Dir.chdir(new_config_dir)
|
417
|
+
core_app = Core.new
|
418
|
+
core_app.ensure_rails_root
|
419
|
+
core_app.ensure_external_db
|
420
|
+
badger_yml = core_app.yml
|
421
|
+
badger_yml.keys.each do |k|
|
422
|
+
if k.tr('^A-Za-z', '') == "app"
|
423
|
+
core_app.create(k)
|
424
|
+
end
|
425
|
+
end
|
426
|
+
exit
|
427
|
+
end
|
428
|
+
end
|
429
|
+
else
|
430
|
+
@errors.errors('ssh')
|
431
|
+
end
|
432
|
+
else
|
433
|
+
while not Dir.pwd == "/"
|
434
|
+
if Dir.exists?("config/")
|
435
|
+
break
|
436
|
+
else
|
437
|
+
Dir.chdir("..")
|
438
|
+
end
|
439
|
+
end
|
440
|
+
if Dir.pwd == "/"
|
441
|
+
@errors.errors('rails root')
|
442
|
+
else
|
443
|
+
config_dir = Dir.pwd
|
444
|
+
if `cat Gemfile.lock | grep therubyracer` == ""
|
445
|
+
@errors.errors('rubyracer')
|
446
|
+
exit
|
447
|
+
elsif `cat Gemfile.lock | grep mysql2` == ""
|
448
|
+
@errors.errors('mysql2')
|
449
|
+
exit
|
450
|
+
elsif `cat Gemfile.lock | grep unicorn` == ""
|
451
|
+
@errors.errors('unicorn')
|
452
|
+
exit
|
453
|
+
end
|
454
|
+
spec = Gem::Specification.find_by_name("badger-rails")
|
455
|
+
badger_root = spec.gem_dir + "/lib/"
|
456
|
+
if Dir.exists?("lib/badger/")
|
457
|
+
`cp -rf lib/badger #{badger_root}badger/core/scripts/badger`
|
458
|
+
end
|
459
|
+
Dir.chdir("config/")
|
460
|
+
FileUtils.cp(Dir.pwd + "/badger.yml", badger_root + "badger/config/rails-app.yml")
|
461
|
+
Dir.chdir(badger_root + "badger/")
|
462
|
+
if File.exists?("#{Dir.home}/.ssh/id_rsa.pub")
|
463
|
+
`cap rails-app deploy`
|
464
|
+
unless ARGV[1].nil?
|
465
|
+
if ARGV[1].downcase == "--with-workers"
|
466
|
+
Dir.chdir(config_dir)
|
467
|
+
core_app = Core.new
|
468
|
+
core_app.ensure_rails_root
|
469
|
+
core_app.ensure_external_db
|
470
|
+
badger_yml = core_app.yml
|
471
|
+
badger_yml.keys.each do |k|
|
472
|
+
if k.tr('^A-Za-z', '') == "app"
|
473
|
+
core_app.create(k)
|
474
|
+
end
|
475
|
+
end
|
476
|
+
exit
|
477
|
+
end
|
478
|
+
end
|
479
|
+
else
|
480
|
+
@errors.errors('ssh')
|
481
|
+
end
|
482
|
+
end
|
483
|
+
end
|
484
|
+
else
|
485
|
+
@errors.errors('usage')
|
486
|
+
end
|
data/lib/badger/Capfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
load 'config/deploy.rb'
|
@@ -0,0 +1,211 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
def remote_file_exists?(full_path)
|
6
|
+
'true' == capture("if [ -d #{full_path} ]; then echo 'true'; fi").strip
|
7
|
+
end
|
8
|
+
|
9
|
+
def remote_directory_empty?(full_path)
|
10
|
+
'true' == capture('[ "$(ls -A /opt/git/)" ] && echo "false" || echo "true"').strip
|
11
|
+
end
|
12
|
+
|
13
|
+
def check_local_db(teh_yml)
|
14
|
+
if teh_yml['local_db'] == nil or teh_yml['local_db'] == true
|
15
|
+
puts
|
16
|
+
puts "Worker servers cannot be deployed with a local project database."
|
17
|
+
puts "Please use an exteral database."
|
18
|
+
puts
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
yml = YAML.load_file "config/rails-app.yml"
|
24
|
+
set :user, yml['username']
|
25
|
+
set :password, yml['password']
|
26
|
+
set :domain, yml['domain']
|
27
|
+
set :port, yml['port']
|
28
|
+
set :server, yml['server']
|
29
|
+
set :environment, yml['environment']
|
30
|
+
|
31
|
+
role :web, domain
|
32
|
+
|
33
|
+
desc "host"
|
34
|
+
task ARGV[0], :roles => :web do
|
35
|
+
case ARGV[1]
|
36
|
+
when "db_setup", "db_sync", "db_deploy"
|
37
|
+
roles[:app].clear
|
38
|
+
roles[:web].clear
|
39
|
+
set :user, yml['db']['username']
|
40
|
+
set :password, yml['db']['password']
|
41
|
+
set :domain, yml['db']['domain']
|
42
|
+
set :port, yml['db']['port']
|
43
|
+
role :db, domain
|
44
|
+
when "app_setup", "app_sync", "app_deploy", "scale"
|
45
|
+
roles[:app].clear
|
46
|
+
roles[:web].clear
|
47
|
+
set :user, yml[ARGV[0]]['username']
|
48
|
+
set :password, yml[ARGV[0]]['password']
|
49
|
+
set :domain, yml[ARGV[0]]['domain']
|
50
|
+
set :port, yml[ARGV[0]]['port']
|
51
|
+
role :app, domain
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "info"
|
56
|
+
task :info, roles => :web do
|
57
|
+
run "cd /etc/badger/core/scripts/; chmod +x app_info; ./app_info"
|
58
|
+
end
|
59
|
+
|
60
|
+
desc "scale"
|
61
|
+
task :scale, roles => :app do
|
62
|
+
run "cd /etc/badger/core/scripts/; chmod +x app_scale; ./app_scale #{workers} #{yml['environment']}"
|
63
|
+
end
|
64
|
+
|
65
|
+
desc "exists"
|
66
|
+
task :exists, roles => :web do
|
67
|
+
if remote_file_exists?("/opt/git/#{ARGV[0]}.git")
|
68
|
+
puts "true"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
desc "createExists"
|
73
|
+
task :createExists, roles => :web do
|
74
|
+
if remote_directory_empty?("/opt/git/#{ARGV[0]}.git")
|
75
|
+
puts "false"
|
76
|
+
else
|
77
|
+
puts "true"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
desc "sync"
|
82
|
+
task :sync, :roles => :web do
|
83
|
+
upload "../badger/core", "/etc/badger/", :via => :scp, :recursive => :true
|
84
|
+
end
|
85
|
+
|
86
|
+
desc "db_sync"
|
87
|
+
task :db_sync, :roles => :db do
|
88
|
+
upload "../badger/core", "/etc/badger/", :via => :scp, :recursive => :true
|
89
|
+
end
|
90
|
+
|
91
|
+
desc "app_sync"
|
92
|
+
task :app_sync, :roles => :app do
|
93
|
+
upload "../badger/core", "/etc/badger/", :via => :scp, :recursive => :true
|
94
|
+
end
|
95
|
+
|
96
|
+
desc "setup"
|
97
|
+
task :setup, :roles => :web do
|
98
|
+
`cat ~/.ssh/id_rsa.pub >> core/files/ssh/authorized_keys`
|
99
|
+
run <<EOF
|
100
|
+
mkdir -p /etc/badger/core;
|
101
|
+
[ "$(cat /etc/issue | grep CentOS)" ] && rpm -Uvh https://github.com/downloads/curiousminds/packages/epel-release-6-5.noarch.rpm;
|
102
|
+
[ "$(cat /etc/issue | grep CentOS)" ] && yum -y repolist;
|
103
|
+
[ "$(cat /etc/issue | grep CentOS)" ] && yum -y install git && yum -y update git;
|
104
|
+
[ "$(cat /etc/issue | grep Red)" ] && rpm -Uvh https://github.com/downloads/curiousminds/packages/epel-release-6-5.noarch.rpm;
|
105
|
+
[ "$(cat /etc/issue | grep Red)" ] && yum -y repolist;
|
106
|
+
[ "$(cat /etc/issue | grep Red)" ] && yum -y install git && yum -y update git;
|
107
|
+
[ "$(cat /etc/issue | grep Red)" ] && yum -y update git;
|
108
|
+
[ "$(cat /etc/issue | grep Ubuntu)" ] && apt-get update;
|
109
|
+
[ "$(cat /etc/issue | grep Ubuntu)" ] && apt-get -y install git-core;
|
110
|
+
[ "$(cat /etc/issue | grep Debian)" ] && apt-get update;
|
111
|
+
[ "$(cat /etc/issue | grep Debian)" ] && apt-get -y install git-core;
|
112
|
+
EOF
|
113
|
+
end
|
114
|
+
|
115
|
+
desc "db_setup"
|
116
|
+
task :db_setup, :roles => :db do
|
117
|
+
`cat ~/.ssh/id_rsa.pub >> core/files/ssh/authorized_keys`
|
118
|
+
run <<EOF
|
119
|
+
mkdir -p /etc/badger/core;
|
120
|
+
[ "$(cat /etc/issue | grep CentOS)" ] && rpm -Uvh https://github.com/downloads/curiousminds/packages/epel-release-6-5.noarch.rpm;
|
121
|
+
[ "$(cat /etc/issue | grep CentOS)" ] && yum -y repolist;
|
122
|
+
[ "$(cat /etc/issue | grep CentOS)" ] && yum -y install git && yum -y update git;
|
123
|
+
[ "$(cat /etc/issue | grep Red)" ] && rpm -Uvh https://github.com/downloads/curiousminds/packages/epel-release-6-5.noarch.rpm;
|
124
|
+
[ "$(cat /etc/issue | grep Red)" ] && yum -y repolist;
|
125
|
+
[ "$(cat /etc/issue | grep Red)" ] && yum -y install git && yum -y update git;
|
126
|
+
[ "$(cat /etc/issue | grep Red)" ] && yum -y update git;
|
127
|
+
[ "$(cat /etc/issue | grep Ubuntu)" ] && apt-get update;
|
128
|
+
[ "$(cat /etc/issue | grep Ubuntu)" ] && apt-get -y install git-core;
|
129
|
+
[ "$(cat /etc/issue | grep Debian)" ] && apt-get update;
|
130
|
+
[ "$(cat /etc/issue | grep Debian)" ] && apt-get -y install git-core;
|
131
|
+
EOF
|
132
|
+
end
|
133
|
+
|
134
|
+
desc "app_setup"
|
135
|
+
task :app_setup, :roles => :app do
|
136
|
+
`cat ~/.ssh/id_rsa.pub >> core/files/ssh/authorized_keys`
|
137
|
+
run <<EOF
|
138
|
+
mkdir -p /etc/badger/core;
|
139
|
+
[ "$(cat /etc/issue | grep CentOS)" ] && rpm -Uvh https://github.com/downloads/curiousminds/packages/epel-release-6-5.noarch.rpm;
|
140
|
+
[ "$(cat /etc/issue | grep CentOS)" ] && yum -y repolist;
|
141
|
+
[ "$(cat /etc/issue | grep CentOS)" ] && yum -y install git && yum -y update git;
|
142
|
+
[ "$(cat /etc/issue | grep Red)" ] && rpm -Uvh https://github.com/downloads/curiousminds/packages/epel-release-6-5.noarch.rpm;
|
143
|
+
[ "$(cat /etc/issue | grep Red)" ] && yum -y repolist;
|
144
|
+
[ "$(cat /etc/issue | grep Red)" ] && yum -y install git && yum -y update git;
|
145
|
+
[ "$(cat /etc/issue | grep Red)" ] && yum -y update git;
|
146
|
+
[ "$(cat /etc/issue | grep Ubuntu)" ] && apt-get update;
|
147
|
+
[ "$(cat /etc/issue | grep Ubuntu)" ] && apt-get -y install git-core;
|
148
|
+
[ "$(cat /etc/issue | grep Debian)" ] && apt-get update;
|
149
|
+
[ "$(cat /etc/issue | grep Debian)" ] && apt-get -y install git-core;
|
150
|
+
EOF
|
151
|
+
end
|
152
|
+
|
153
|
+
desc "db_deploy"
|
154
|
+
task :db_deploy, :roles => :db do
|
155
|
+
run "chmod +x /etc/badger/core/claws/#{ARGV[0]}.claw; /etc/badger/core/claws/./#{ARGV[0]}.claw"
|
156
|
+
end
|
157
|
+
|
158
|
+
desc "app_deploy"
|
159
|
+
task :app_deploy, :roles => :app do
|
160
|
+
check_local_db(yml)
|
161
|
+
run "chmod +x /etc/badger/core/claws/app.claw; /etc/badger/core/claws/./app.claw"
|
162
|
+
end
|
163
|
+
|
164
|
+
desc "deploy"
|
165
|
+
task :deploy, :roles => :web do
|
166
|
+
if Dir.exists?("../badger/core/scripts/badger/")
|
167
|
+
upload "../badger/core/scripts/badger", "/etc/badger/core/scripts/", :via => :scp, :recursive => :true
|
168
|
+
end
|
169
|
+
run "chmod +x /etc/badger/core/claws/#{ARGV[0]}.claw; /etc/badger/core/claws/./#{ARGV[0]}.claw"
|
170
|
+
end
|
171
|
+
|
172
|
+
desc "gemset_clear"
|
173
|
+
task :gemset_clear, :roles => :web do
|
174
|
+
run "cd /etc/badger/core/scripts/; chmod +x *; ./remove_gems"
|
175
|
+
end
|
176
|
+
|
177
|
+
desc "git"
|
178
|
+
task :git, :roles => :web do
|
179
|
+
ssh = `cat ~/.ssh/id_rsa.pub`
|
180
|
+
run "groupadd git; useradd -m git -g git && mkdir -p /home/git/.ssh/ && touch /home/git/.ssh/authorized_keys; chown git /home/git/.ssh; echo #{ssh} >> /home/git/.ssh/authorized_keys"
|
181
|
+
run "mkdir -p /opt/git/#{ARGV[0]}.git; cd /opt/git/#{ARGV[0]}.git; git --bare init; chown -R git:git /opt/git/;"
|
182
|
+
run "echo git@#{yml['domain']}:/opt/git/#{ARGV[0]}.git > /etc/badger/core/files/git/git"
|
183
|
+
end
|
184
|
+
|
185
|
+
desc "rake"
|
186
|
+
task :rake, :roles => :web do
|
187
|
+
run "cd /opt/web/current/; PATH=/opt/rubygems/bin:$PATH; rake #{brat.gsub("^", " ")} RAILS_ENV=#{environment}"
|
188
|
+
end
|
189
|
+
|
190
|
+
desc "logs"
|
191
|
+
task :logs, :roles => :web do
|
192
|
+
if brat == "tail"
|
193
|
+
trap("INT") do
|
194
|
+
run "pkill tail"
|
195
|
+
exit
|
196
|
+
end
|
197
|
+
run "tail -f /opt/web/current/log/#{yml['environment']}.log /opt/web/current/log/god_unicorn.log /var/log/nginx/access.log /var/log/nginx/error.log"
|
198
|
+
else
|
199
|
+
run "tail /opt/web/current/log/#{yml['environment']}.log /opt/web/current/log/god_unicorn.log /var/log/nginx/access.log /var/log/nginx/error.log"
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
desc "remove"
|
204
|
+
task :remove, :roles => :web do
|
205
|
+
run "cd /etc/badger/core/scripts/; chmod +x remove_app; ./remove_app #{ARGV[0]}"
|
206
|
+
end
|
207
|
+
|
208
|
+
desc "removedb"
|
209
|
+
task :removedb, :roles => :web do
|
210
|
+
run "cd /etc/badger/core/scripts/; chmod +x remove_app_db; ./remove_app_db #{ARGV[0]}"
|
211
|
+
end
|