obbistrano 1.0.80 → 1.0.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/obbistrano_tasks.rb +170 -92
  2. data/obbistrano.gemspec +1 -1
  3. metadata +2 -2
@@ -104,17 +104,7 @@ Capistrano::Configuration.instance(:must_exist).load do
104
104
 
105
105
  namespace :app do
106
106
 
107
- task :config_check do
108
- config_setup
109
- databases rescue set(:databases, ["#{application}"])
110
- aliases rescue set(:aliases, []);
111
- end
112
-
113
- task :needs_root do
114
- config_check
115
- puts "*** This operation needs root access - Please pass in a root password using -s root=password" if !defined? "#{root_pass}"
116
- exit if !defined? "#{root_pass}"
117
- end
107
+
118
108
 
119
109
 
120
110
 
@@ -244,14 +234,7 @@ Capistrano::Configuration.instance(:must_exist).load do
244
234
  # GENERAL ADMIN FOR APPLICATIONS
245
235
  # =============================================================================
246
236
 
247
- desc "Restarts the Apache Server. Requires root password to access."
248
- task :restart do
249
- config_check
250
- needs_root
251
- with_user("root", "#{root_pass}") do
252
- run "/etc/rc.d/init.d/httpd restart"
253
- end
254
- end
237
+
255
238
 
256
239
  desc "Clears the application's cache files from tmp/cache."
257
240
  task :clearcache do
@@ -278,79 +261,7 @@ Capistrano::Configuration.instance(:must_exist).load do
278
261
  end
279
262
 
280
263
 
281
- task :setup_user do
282
- needs_root
283
- set :user_to_add, "#{user}"
284
- set :passwd_to_add, "#{password}"
285
- with_user("root", "#{root_pass}") do
286
- run "useradd -p `openssl passwd #{passwd_to_add}` #{user_to_add}"
287
- run "chmod -R 0755 /home/#{user_to_add}"
288
- end
289
- end
290
-
291
- task :setup_mysql do
292
- needs_root
293
- set :user_to_add, "#{user}"
294
- set :passwd_to_add, "#{password}"
295
- with_user("root", "#{root_pass}") do
296
- "#{databases}".each do |db|
297
- begin
298
- run "mysql -uroot -p#{root_pass} -e \"CREATE USER '#{user_to_add}'@'localhost' IDENTIFIED BY '#{passwd_to_add}';\""
299
- run "mysql -uroot -p#{root_pass} -e 'CREATE DATABASE #{db}'"
300
- run "musql -uroot -p#{root_pass} -e \"GRANT ALL PRIVILEGES ON `#{db}` . * TO '#{user_to_add}'@'localhost' IDENTIFIED BY '#{passwd_to_add}';\""
301
- rescue
302
- logger.info "Database #{db} already exists"
303
- end
304
- end
305
- end
306
264
 
307
- end
308
-
309
- task :try_login do
310
- config_check
311
- begin
312
- run "ls"
313
- puts "Logged in ok"
314
- rescue
315
- print "==== The user does not yet exist. Would you like to create? [Y/N]"
316
- line = STDIN.gets.upcase.strip
317
- puts "*** Could not continue as the login does not exist" if line !="Y"
318
- exit if line != "Y"
319
- setup_user
320
- end
321
- end
322
-
323
- desc "Creates or gets an ssh key for the application"
324
- task :ssh_key do
325
- config_check
326
- begin
327
- run "cat .ssh/id_rsa.pub"
328
- rescue
329
- run "mkdir -p .ssh/"
330
- run "ssh-keygen -t rsa -f .ssh/id_rsa -N ''"
331
- run "cat .ssh/id_rsa.pub"
332
- end
333
- end
334
-
335
- desc "Creates an Apache virtual host file"
336
- task :vhost do
337
- config_check
338
- needs_root
339
- with_user("root", "#{root_pass}") do
340
- public_ip = ""
341
- run "ifconfig eth0 | grep inet | awk '{print $2}' | sed 's/addr://'" do |_, _, public_ip| end
342
- public_ip = public_ip.strip
343
- roles[:web].servers.each do |webserver|
344
- f = File.open(File.join(File.dirname(__FILE__), 'templates/apache_vhost.erb' ))
345
- contents = f.read
346
- f.close
347
- buffer = ERB.new(contents)
348
- config = buffer.result(binding())
349
- put config, "/etc/httpd/conf.d/#{webserver}-apache-vhost.conf"
350
- end
351
- end
352
- restart
353
- end
354
265
 
355
266
 
356
267
 
@@ -415,9 +326,176 @@ Capistrano::Configuration.instance(:must_exist).load do
415
326
  namespace :setup do
416
327
  desc "Sets up the server with a user, home directory and mysql login."
417
328
  task :default do
418
- app.setup
329
+ server.setup
419
330
  end
420
331
  end
332
+
333
+ namespace :server do
334
+
335
+
336
+ desc "Sets up the server with a user, home directory and mysql login."
337
+ task :default do
338
+ "#{server_type}".setup
339
+ end
340
+
341
+ desc "Restarts the web server."
342
+ task :restart do
343
+ "#{server_type}".restart
344
+ end
345
+
346
+
347
+ ###### Private tasks for server operations #############
348
+
349
+ task :config_check do
350
+ config_setup
351
+ databases rescue set(:databases, ["#{application}"])
352
+ aliases rescue set(:aliases, []);
353
+ server_type rescue set(:server_type, "fedora")
354
+ end
355
+
356
+ task :needs_root do
357
+ config_check
358
+ puts "*** This operation needs root access - Please pass in a root password using -s root=password" if !defined? "#{root_pass}"
359
+ exit if !defined? "#{root_pass}"
360
+ end
361
+
362
+ task :try_login do
363
+ config_check
364
+ begin
365
+ run "ls"
366
+ puts "Logged in ok"
367
+ rescue
368
+ print "==== The user does not yet exist. Would you like to create? [Y/N]"
369
+ line = STDIN.gets.upcase.strip
370
+ puts "*** Could not continue as the login does not exist" if line !="Y"
371
+ exit if line != "Y"
372
+ setup_user
373
+ end
374
+ end
375
+
376
+ desc "Creates or gets an ssh key for the application"
377
+ task :ssh_key do
378
+ config_check
379
+ begin
380
+ run "cat .ssh/id_rsa.pub"
381
+ rescue
382
+ run "mkdir -p .ssh/"
383
+ run "ssh-keygen -t rsa -f .ssh/id_rsa -N ''"
384
+ run "cat .ssh/id_rsa.pub"
385
+ end
386
+ end
387
+
388
+ desc "Creates a MySQL user and database"
389
+ task :setup_mysql do
390
+ needs_root
391
+ set :user_to_add, "#{user}"
392
+ set :passwd_to_add, "#{password}"
393
+ with_user("root", "#{root_pass}") do
394
+ "#{databases}".each do |db|
395
+ begin
396
+ run "mysql -uroot -p#{root_pass} -e \"CREATE USER '#{user_to_add}'@'localhost' IDENTIFIED BY '#{passwd_to_add}';\""
397
+ run "mysql -uroot -p#{root_pass} -e 'CREATE DATABASE #{db}'"
398
+ run "musql -uroot -p#{root_pass} -e \"GRANT ALL PRIVILEGES ON `#{db}` . * TO '#{user_to_add}'@'localhost' IDENTIFIED BY '#{passwd_to_add}';\""
399
+ rescue
400
+ logger.info "Database #{db} already exists"
401
+ end
402
+ end
403
+ end
404
+ end
405
+
406
+
407
+
408
+ end
409
+
410
+ namespace :ubuntu do
411
+
412
+ desc "Ubuntu: Sets up a user and home directory"
413
+ task :setup_user do
414
+ server.needs_root
415
+ set :user_to_add, "#{user}"
416
+ set :passwd_to_add, "#{password}"
417
+ with_user("root", "#{root_pass}") do
418
+ run "useradd -d /home/#{user_to_add} -p `openssl passwd #{passwd_to_add}` -m #{user_to_add}"
419
+ run "chmod -R 0755 /home/#{user_to_add}"
420
+ end
421
+ end
422
+
423
+ desc "Ubuntu: Creates Apache virtual host file"
424
+ task :vhost do
425
+ server.config_check
426
+ needs_root
427
+ with_user("root", "#{root_pass}") do
428
+ public_ip = ""
429
+ run "ifconfig eth0 | grep inet | awk '{print $2}' | sed 's/addr://'" do |_, _, public_ip| end
430
+ public_ip = public_ip.strip
431
+ roles[:web].servers.each do |webserver|
432
+ f = File.open(File.join(File.dirname(__FILE__), 'templates/apache_vhost.erb' ))
433
+ contents = f.read
434
+ f.close
435
+ buffer = ERB.new(contents)
436
+ config = buffer.result(binding())
437
+ put config, "/etc/apache2/sites-enabled/#{webserver}-apache-vhost.conf"
438
+ end
439
+ end
440
+ server.restart
441
+ end
442
+
443
+ desc "Ubuntu: Restarts the Apache Server"
444
+ task :restart do
445
+ config_check
446
+ needs_root
447
+ with_user("root", "#{root_pass}") do
448
+ run "/etc/init.d/apache2 restart"
449
+ end
450
+ end
451
+
452
+ end
453
+
454
+ namespace :fedora do
455
+
456
+ desc "Fedora: Sets up a user and home directory"
457
+ task :setup_user do
458
+ server.needs_root
459
+ set :user_to_add, "#{user}"
460
+ set :passwd_to_add, "#{password}"
461
+ with_user("root", "#{root_pass}") do
462
+ run "useradd -p `openssl passwd #{passwd_to_add}` #{user_to_add}"
463
+ run "chmod -R 0755 /home/#{user_to_add}"
464
+ end
465
+ end
466
+
467
+ desc "Fedora: Creates an Apache virtual host file"
468
+ task :vhost do
469
+ config_check
470
+ needs_root
471
+ with_user("root", "#{root_pass}") do
472
+ public_ip = ""
473
+ run "ifconfig eth0 | grep inet | awk '{print $2}' | sed 's/addr://'" do |_, _, public_ip| end
474
+ public_ip = public_ip.strip
475
+ roles[:web].servers.each do |webserver|
476
+ f = File.open(File.join(File.dirname(__FILE__), 'templates/apache_vhost.erb' ))
477
+ contents = f.read
478
+ f.close
479
+ buffer = ERB.new(contents)
480
+ config = buffer.result(binding())
481
+ put config, "/etc/httpd/conf.d/#{webserver}-apache-vhost.conf"
482
+ end
483
+ end
484
+ restart
485
+ end
486
+
487
+ desc "Fedora: Restarts the Apache Server. Requires root password to access."
488
+ task :restart do
489
+ server.config_check
490
+ server.needs_root
491
+ with_user("root", "#{root_pass}") do
492
+ run "/etc/rc.d/init.d/httpd restart"
493
+ end
494
+ end
495
+
496
+ end
497
+
498
+
421
499
 
422
500
  end
423
501
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{obbistrano}
5
- s.version = "1.0.80"
5
+ s.version = "1.0.81"
6
6
  s.authors = ["Ross Riley", "One Black Bear"]
7
7
  s.date = Time.now
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obbistrano
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.80
4
+ version: 1.0.81
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ross Riley
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-10-08 00:00:00 +01:00
13
+ date: 2009-11-06 00:00:00 +00:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency