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