module RailsPwnerer::App
Public Class Methods
control_all(action = :start)
click to toggle source
start or stop all apps
# File lib/rails_pwnerer/app/main.rb 140 def self.control_all(action = :start) 141 case action 142 when :start 143 Database.new.control_all :start 144 Scripts.new.control_all :pre_start 145 ClusterConfig.new.control_all :start 146 NginxConfig.new.control_all :start 147 Scripts.new.control_all :post_start 148 when :stop 149 Scripts.new.control_all :pre_stop 150 NginxConfig.new.control_all :stop 151 ClusterConfig.new.control_all :stop 152 Scripts.new.control_all :post_stop 153 Database.new.control_all :stop 154 end 155 end
install(remote_path, instance_name)
click to toggle source
installs an application given its SVN path
# File lib/rails_pwnerer/app/main.rb 16 def self.install(remote_path, instance_name) 17 app_name = File.basename remote_path 18 app_name = app_name[0, app_name.rindex('#')] if app_name.rindex '#' 19 app_name = app_name[0, app_name.rindex('.')] if app_name.rindex '.' 20 app_name.gsub! /\W/, '' # Remove weird punctuation. 21 instance_magic(app_name, instance_name) do |app, instance| 22 Config.new.alloc app, instance 23 24 success = nil 25 [Git, Perforce, Svn].each do |vcs| 26 success = vcs.new.checkout remote_path, app, instance 27 break unless success == :next 28 end 29 if success == :ok 30 [Config, Gems, Assets, Files, Database, ClusterConfig, NginxConfig, Scripts].each do |mod| 31 mod.new.setup app, instance 32 end 33 Scripts.new.pre_start app, instance 34 ClusterConfig.new.start app, instance 35 Scripts.new.post_start app, instance 36 else 37 if success == :next 38 print "rails_pwange only supports git, subversion, and perforce at this time.\n" 39 else 40 print "You didn't checkout a Rails application. Check your remote path.\n" 41 end 42 43 [Files, Config].each do |mod| 44 mod.new.remove app, instance 45 end 46 end 47 end 48 end
instance_magic(app_name, instance_name) { |app_name, i| ... }
click to toggle source
internal method implementing magic instance names
# File lib/rails_pwnerer/app/main.rb 3 def self.instance_magic(app_name, instance_name) 4 app_name = app_name.gsub /\W/, '' # Remove weird punctuation. 5 case instance_name 6 when '*' 7 RailsPwnerer::Config.all_instances app_name { |i| yield app_name, i } 8 when '.' 9 yield app_name, RailsPwnerer::Config[:host][:instance] 10 else 11 yield app_name, instance_name 12 end 13 end
manage(app_name, instance_name, action = :checkpoint)
click to toggle source
performs application management (checkpoint / rollback / console)
# File lib/rails_pwnerer/app/main.rb 95 def self.manage(app_name, instance_name, action = :checkpoint) 96 instance_magic(app_name, instance_name) do |app, instance| 97 # TODO: add backup / restore for the configuration db (easy) 98 case action 99 when :checkpoint 100 ClusterConfig.new.manage app, instance, action 101 Files.new.manage app, instance, action 102 self.update_app app, instance do 103 Database.new.manage app, instance, action 104 end 105 when :rollback 106 self.update_app app, instance do 107 [Files, Gems, Database, ClusterConfig].each do |mod| 108 mod.new.manage app, instance, action 109 end 110 end 111 when :rollback_db 112 self.update_app app, instance do 113 [Database, ClusterConfig].each do |mod| 114 mod.new.manage app, instance, :rollback 115 end 116 Database.new.manage app, instance, :update 117 end 118 when :rekey 119 self.update_app app, instance do 120 [Config, Database].each do |mod| 121 mod.new.manage app, instance, action 122 end 123 end 124 when :console 125 Files.new.manage app, instance, action 126 when :db_console 127 Files.new.manage app, instance, action 128 when :db_reset 129 app_config = RailsPwnerer::Config[app, instance] 130 self.update_app app, instance do 131 Scripts.new.pre_reset app, instance 132 Database.new.manage app, instance, action 133 Scripts.new.post_reset app, instance 134 end 135 end 136 end 137 end
remove(app_name, instance_name)
click to toggle source
removes an application (and stops its servers)
# File lib/rails_pwnerer/app/main.rb 67 def self.remove(app_name, instance_name) 68 app_name = app_name.gsub /\W/, '' # Remove weird punctuation. 69 instance_magic(app_name, instance_name) do |app, instance| 70 Scripts.new.pre_stop app, instance 71 ClusterConfig.new.stop app, instance 72 Scripts.new.post_stop app, instance 73 74 [NginxConfig, ClusterConfig, Database, Perforce, Files, Config].each do |mod| 75 mod.new.remove app, instance 76 end 77 end 78 end
update(app_name, instance_name)
click to toggle source
updates an application (restart servers if necessary)
# File lib/rails_pwnerer/app/main.rb 51 def self.update(app_name, instance_name) 52 app_name = app_name.gsub /\W/, '' # Remove weird punctuation. 53 instance_magic(app_name, instance_name) do |app, instance| 54 [Assets, Git, Perforce, Svn].each do |mod| 55 mod.new.update_prefetch app, instance 56 end 57 update_app app, instance do 58 [Git, Perforce, Svn, Config, Gems, Assets, Files, Database, Scripts].each do |mod| 59 mod.new.update app, instance 60 end 61 end 62 NginxConfig.new.update app, instance 63 end 64 end
update_app(app_name, instance_name) { || ... }
click to toggle source
# File lib/rails_pwnerer/app/main.rb 80 def self.update_app(app_name, instance_name, &block) 81 Scripts.new.pre_stop app_name, instance_name 82 ClusterConfig.new.stop app_name, instance_name 83 ClusterConfig.new.pre_update app_name, instance_name 84 Scripts.new.post_stop app_name, instance_name 85 yield 86 ensure 87 ClusterConfig.new.post_update app_name, instance_name 88 NginxConfig.new.update app_name, instance_name 89 Scripts.new.pre_start app_name, instance_name 90 ClusterConfig.new.start app_name, instance_name 91 Scripts.new.post_start app_name, instance_name 92 end