rails_pwnerer 0.4.19 → 0.5.0

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.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.5.0. Implemented configuration repository.
2
+
1
3
  v0.4.19. Fixed bug in cleaning up application directory on SVN update.
2
4
 
3
5
  v0.4.18. Added explicit installation for sqlite3 packages (for CSAIL Debian).
data/README CHANGED
@@ -57,8 +57,14 @@ sudo rpwn restore your_application
57
57
  * Poke around your application using the Rails console:
58
58
  rpwn console your_application
59
59
 
60
+ * Poke around your database using the Rails console:
61
+ rpwn db_console your_application
62
+
60
63
  * Configure DynDns for your application server
61
64
  sudo rpwn scaffold ddns full_host_name ddns_user ddns_password
62
65
 
63
66
  * Bring down all the applications (panic mode):
64
67
  sudo rpwn go down
68
+
69
+ 7) Uninstall your application
70
+ sudo rpwn uninstall your_application
@@ -30,10 +30,17 @@ class RailsPwnage::App::ClusterConfig
30
30
  system "mongrel_rails cluster::configure -e production -N #{instances} -p #{first_port} -a 127.0.0.1 -c #{app_path} --user #{pwnerer_user} --group #{pwnerer_group}"
31
31
 
32
32
  # copy the configuration to the launch directory
33
- FileUtils.cp('config/mongrel_cluster.yml', "#{RailsPwnage::Config.path_to :mongrel_configs}#{File::SEPARATOR}#{app_name}.yml")
33
+ launch_config = File.join RailsPwnage::Config.path_to(:mongrel_configs), "#{app_name}.yml"
34
+ FileUtils.cp 'config/mongrel_cluster.yml', launch_config
34
35
  end
35
36
  end
36
37
 
38
+ def remove_mongrels(app_name)
39
+ # bomb the configuration from the launch directory
40
+ launch_config = File.join RailsPwnage::Config.path_to(:mongrel_configs), "#{app_name}.yml"
41
+ File.delete launch_config if File.exists? launch_config
42
+ end
43
+
37
44
  def stop_mongrels(app_name)
38
45
  # silently die if the app was completely busted
39
46
  return unless File.exists? RailsPwnage::Config.path_to(app_name)
@@ -69,6 +76,10 @@ class RailsPwnage::App::ClusterConfig
69
76
  start_mongrels(app_name)
70
77
  end
71
78
 
79
+ def remove(app_name)
80
+ remove_mongrels app_name
81
+ end
82
+
72
83
  def manage(app_name, action)
73
84
  case action
74
85
  when :checkpoint
@@ -92,6 +103,10 @@ class RailsPwnage::App::ClusterConfig
92
103
  self.new.setup(app_name)
93
104
  end
94
105
 
106
+ def self.remove(app_name)
107
+ self.new.remove(app_name)
108
+ end
109
+
95
110
  def self.update(app_name, &update_proc)
96
111
  self.new.update(app_name, &update_proc)
97
112
  end
@@ -33,7 +33,7 @@ ENDSQL
33
33
  File.delete('tmp/admin_db.sql')
34
34
  end
35
35
  end
36
-
36
+
37
37
  # configures rails to use the database in the production environment
38
38
  def configure_rails(app_name)
39
39
  db_name = RailsPwnage::Config.app_dbname(app_name)
@@ -105,6 +105,11 @@ ENDSQL
105
105
  migrate_database app_name
106
106
  end
107
107
 
108
+ def remove(app_name)
109
+ control_boot_script('mysql', :start)
110
+ admin_database app_name, :drop
111
+ end
112
+
108
113
  # backs up or restores the database
109
114
  def manage(app_name, action)
110
115
 
@@ -137,6 +142,10 @@ ENDSQL
137
142
  self.new.update(app_name)
138
143
  end
139
144
 
145
+ def self.remove(app_name)
146
+ self.new.remove(app_name)
147
+ end
148
+
140
149
  def self.manage(app_name, action)
141
150
  self.new.manage(app_name, action)
142
151
  end
@@ -1,5 +1,5 @@
1
1
  module RailsPwnage::App
2
- # install an application given its SVN path
2
+ # installs an application given its SVN path
3
3
  def self.install(svn_path)
4
4
  app_name = Svn.setup(svn_path)
5
5
  Gems.setup(app_name)
@@ -8,7 +8,7 @@ module RailsPwnage::App
8
8
  NginxConfig.setup(app_name)
9
9
  end
10
10
 
11
- # update an application (restart servers if necessary)
11
+ # updates an application (restart servers if necessary)
12
12
  def self.update(app_name)
13
13
  ClusterConfig.update app_name do
14
14
  Svn.update app_name
@@ -17,6 +17,14 @@ module RailsPwnage::App
17
17
  end
18
18
  NginxConfig.update app_name
19
19
  end
20
+
21
+ # removes an application (and stops its servers)
22
+ def self.remove(app_name)
23
+ ClusterConfig.remove app_name
24
+ NginxConfig.remove app_name
25
+ Database.remove app_name
26
+ Svn.remove app_name
27
+ end
20
28
 
21
29
  # performs application management (checkpoint / rollback / console)
22
30
  def self.manage(app_name, action = :checkpoint)
@@ -35,6 +43,8 @@ module RailsPwnage::App
35
43
  end
36
44
  when :console
37
45
  Svn.manage app_name, action
46
+ when :db_console
47
+ Svn.manage app_name, action
38
48
  end
39
49
  end
40
50
 
@@ -8,7 +8,8 @@ class RailsPwnage::App::NginxConfig
8
8
  first_port = RailsPwnage::Config.app_port0(app_name)
9
9
  hostname_filter = RailsPwnage::Config.app_servername(app_name)
10
10
 
11
- File.open(File.join(RailsPwnage::Config.path_to(:nginx_configs), app_name), 'w') do |f|
11
+ nginx_config = File.join(RailsPwnage::Config.path_to(:nginx_configs), app_name)
12
+ File.open(nginx_config, 'w') do |f|
12
13
  # link to the mongrels
13
14
  f << " upstream #{app_name} {\n"
14
15
  RailsPwnage::Config.app_instances(app_name).times do |instance|
@@ -46,16 +47,25 @@ NGINX_CONFIG
46
47
  end
47
48
  end
48
49
 
50
+ def remove_nginx_config(app_name)
51
+ nginx_config = File.join(RailsPwnage::Config.path_to(:nginx_configs), app_name)
52
+ File.delete nginx_config if File.exists? nginx_config
53
+ end
54
+
49
55
  # removes the default configuration stub (so nginx doesn't stumble upon it)
50
56
  def remove_nginx_stub
51
- stub_file = RailsPwnage::Config.path_to(:nginx_configs) + File::SEPARATOR + 'default'
52
- File.delete(stub_file) if File.exists?(stub_file)
57
+ stub_file = File.join(RailsPwnage::Config.path_to(:nginx_configs), 'default')
58
+ File.delete stub_file if File.exists?(stub_file)
53
59
  end
54
60
 
55
61
  def setup(app_name)
56
- config_nginx(app_name)
62
+ config_nginx app_name
57
63
  remove_nginx_stub
58
- end
64
+ end
65
+
66
+ def remove(app_name)
67
+ remove_nginx_config app_name
68
+ end
59
69
 
60
70
  def control_all(action)
61
71
  case action
@@ -63,6 +73,8 @@ NGINX_CONFIG
63
73
  control_boot_script('nginx', :start)
64
74
  when :stop
65
75
  control_boot_script('nginx', :stop)
76
+ when :reload
77
+ control_boot_script('nginx', :reload)
66
78
  end
67
79
  end
68
80
 
@@ -74,6 +86,10 @@ NGINX_CONFIG
74
86
  # nothing to do here, unless we enable config rewriting
75
87
  end
76
88
 
89
+ def self.remove(app_name)
90
+ self.new.remove(app_name)
91
+ end
92
+
77
93
  def self.control_all(action = :start)
78
94
  self.new.control_all(action)
79
95
  end
@@ -9,7 +9,7 @@ class RailsPwnage::App::Svn
9
9
  def svn_checkout(svn_path)
10
10
  app_name = File.basename(svn_path)
11
11
 
12
- prod_apps = RailsPwnage::Config.path_to :prod_apps
12
+ prod_apps = RailsPwnage::Config.path_to :apps
13
13
  Dir.chdir(prod_apps) do
14
14
  # checkout application
15
15
  system "svn co #{svn_path} #{app_name}"
@@ -74,7 +74,7 @@ class RailsPwnage::App::Svn
74
74
  # loads the latest file dump from the backup area
75
75
  def load_files(app_name)
76
76
  dump_file = Dir.glob(RailsPwnage::Config.path_to(:backup, app_name) + File::SEPARATOR + "files/#{app_name}_*").max
77
- Dir.chdir(RailsPwnage::Config.path_to(:prod_apps)) do
77
+ Dir.chdir(RailsPwnage::Config.path_to(:apps)) do
78
78
  # find the latest dump and load it in
79
79
  system "tar -xzf #{dump_file}"
80
80
  end
@@ -121,6 +121,10 @@ class RailsPwnage::App::Svn
121
121
  Dir.chdir(RailsPwnage::Config.path_to(app_name)) do
122
122
  Kernel.system 'ruby script/console production'
123
123
  end
124
+ when :db_console
125
+ Dir.chdir(RailsPwnage::Config.path_to(app_name)) do
126
+ Kernel.system 'ruby script/dbconsole --include-password production'
127
+ end
124
128
  end
125
129
  end
126
130
 
@@ -143,6 +147,10 @@ class RailsPwnage::App::Svn
143
147
  svn_update(app_name)
144
148
  end
145
149
 
150
+ def remove(app_name)
151
+ drop_files(app_name)
152
+ end
153
+
146
154
  def self.setup(svn_path)
147
155
  self.new.setup(svn_path)
148
156
  end
@@ -150,6 +158,10 @@ class RailsPwnage::App::Svn
150
158
  def self.update(app_name)
151
159
  self.new.update(app_name)
152
160
  end
161
+
162
+ def self.remove(app_name)
163
+ self.new.remove(app_name)
164
+ end
153
165
 
154
166
  def self.manage(app_name, action)
155
167
  self.new.manage(app_name, action)
@@ -1,35 +1,4 @@
1
1
  module RailsPwnage::Config
2
- # the path to something important (e.g. :prod_apps --> path to all production applications)
3
- def self.path_to(what = :prod, app_name = nil)
4
- case what
5
- when :prod
6
- # the directory containing all the production data
7
- '/prod'
8
- when :prod_apps
9
- # the directory containing the production apps
10
- '/prod/apps'
11
- when :prod_config
12
- # the directory containing the config files
13
- '/prod/config'
14
- when :prod_backups
15
- '/prod/backups'
16
- when :mongrel_configs
17
- # the directory containing the mongrel_cluster config files
18
- '/etc/mongrel_cluster'
19
- when :nginx_configs
20
- # the directory containing the nginx config files
21
- '/etc/nginx/sites-enabled'
22
- when :ddclient_config
23
- '/etc/ddclient.conf'
24
- when :backup
25
- # the backup directory for an application
26
- '/prod/backups/' + app_name
27
- when String
28
- # an application
29
- self.path_to(:prod_apps) + File::SEPARATOR + what
30
- end
31
- end
32
-
33
2
  # the user which will receive the keys to the production system
34
3
  def self.pwnerer_user
35
4
  'victor'
@@ -1,3 +1,5 @@
1
+ require 'pp'
2
+
1
3
  class RailsPwnage::Executor
2
4
  include RailsPwnage::Scaffolds
3
5
 
@@ -6,18 +8,20 @@ class RailsPwnage::Executor
6
8
  case args[0]
7
9
  when 'scaffold', 'den00b'
8
10
  case args[1]
11
+ when 'config'
12
+ Config.go
9
13
  when 'dirs'
10
14
  Dirs.go
11
- when 'rubygems'
12
- RubyGems.go
13
15
  when 'gems'
14
16
  Gems.go
15
- when 'packages'
16
- Packages.go
17
17
  when 'mongrels'
18
18
  HookMongrels.go
19
19
  when 'mysql'
20
20
  MysqlConfig.go
21
+ when 'packages'
22
+ Packages.go
23
+ when 'rubygems'
24
+ RubyGems.go
21
25
  when 'ddns'
22
26
  if args.length < 5
23
27
  print 'Usage: rpwn scaffold ddns host_name user_name user_password'
@@ -29,6 +33,7 @@ class RailsPwnage::Executor
29
33
  RubyGems.go
30
34
  Gems.go
31
35
  Dirs.go
36
+ Config.go
32
37
  MysqlConfig.go
33
38
  HookMongrels.go
34
39
  end
@@ -41,6 +46,10 @@ class RailsPwnage::Executor
41
46
  app_name = args[1]
42
47
  RailsPwnage::App.update app_name
43
48
 
49
+ when 'uninstall', 'remove'
50
+ app_name = args[1]
51
+ RailsPwnage::App.remove app_name
52
+
44
53
  when 'go'
45
54
  case args[1]
46
55
  when 'live', 'pwn'
@@ -57,7 +66,19 @@ class RailsPwnage::Executor
57
66
  RailsPwnage::App.manage args[1], :rollback
58
67
  when 'console'
59
68
  RailsPwnage::App.manage args[1], :console
69
+ when 'db_console'
70
+ RailsPwnage::App.manage args[1], :db_console
60
71
 
72
+ when 'config_show'
73
+ if args.length < 2
74
+ # dump all databases
75
+ RailsPwnage::Config.databases.each do |db|
76
+ print "Database: #{db}"
77
+ pp RailsPwnage::Config[db]
78
+ end
79
+ else
80
+ pp RailsPwnage::Config[args[1]]
81
+ end
61
82
  else
62
83
  print "Unrecognized command #{args[0]}\n"
63
84
  end
@@ -9,7 +9,7 @@ class RailsPwnage::Scaffolds::Dirs
9
9
  def run
10
10
  pwnerer_uid = uid_for_username(RailsPwnage::Config.pwnerer_user)
11
11
  Dir.chdir('/') do
12
- [:prod_apps, :prod_config, :prod_backups].map { |k| RailsPwnage::Config.path_to k }.each do |path|
12
+ [:config, :apps, :backups].map { |k| RailsPwnage::Config.path_to k }.each do |path|
13
13
  FileUtils.mkpath path
14
14
  File.chown(pwnerer_uid, nil, path)
15
15
  end
@@ -10,9 +10,12 @@ class RailsPwnage::Scaffolds::Packages
10
10
  install_packages %w(dpkg_dev openssh-server)
11
11
 
12
12
  # subversion is needed to pull code from SVN repositories
13
+ # should work from source, except package author decided to block that
14
+ install_packages %w(subversion)
15
+
13
16
  # ddclient does dynamic DNS
14
17
  # avahi-daemon does mDNS, a.k.a. Bonjour (makes "ping hostname.local" work)
15
- install_packages %w(subversion ddclient avahi-daemon), :source => true
18
+ install_packages %w(ddclient avahi-daemon), :source => true
16
19
  end
17
20
 
18
21
  # packages that are needed by popular gems
@@ -39,6 +42,11 @@ class RailsPwnage::Scaffolds::Packages
39
42
  install_packages %w(mysql-client mysql-server libmysqlclient15-dev)
40
43
  end
41
44
 
45
+ # the packages for sqlite3
46
+ def install_sqlite3
47
+ install_packages %w(libsqlite3 libsqlite3-dev sqlite3), :source => true
48
+ end
49
+
42
50
  # the packager for _the_ load balancer (nginx, from Russia with <3)
43
51
  def install_balancer
44
52
  remove_packages %w(nginx)
@@ -48,10 +56,6 @@ class RailsPwnage::Scaffolds::Packages
48
56
 
49
57
  # runner
50
58
  def run
51
- install_packages %w(libsqlite3 libsqlite3-dev sqlite3), :source => true
52
- print 'Fuck ok?'
53
- exit
54
-
55
59
  add_package_source 'http://debian.mirrors.tds.net/debian/',
56
60
  %w(unstable main non-free contrib), :source => true
57
61
 
@@ -60,6 +64,7 @@ class RailsPwnage::Scaffolds::Packages
60
64
  install_tools
61
65
  install_ruby
62
66
  install_mysql
67
+ install_sqlite3
63
68
  install_balancer
64
69
  end
65
70
 
data/lib/rails_pwnage.rb CHANGED
@@ -5,15 +5,21 @@ module RailsPwnage::Scaffolds
5
5
  end
6
6
 
7
7
  require 'pwnage/base.rb'
8
+ require 'pwnage/base/atomics.rb'
8
9
  require 'pwnage/base/dirs.rb'
9
10
  require 'pwnage/base/gems.rb'
11
+ require 'pwnage/base/hostname.rb'
10
12
  require 'pwnage/base/packages.rb'
11
13
  require 'pwnage/base/startup.rb'
12
14
 
13
15
  require 'pwnage/config/main.rb'
16
+ require 'pwnage/config/paths.rb'
17
+ require 'pwnage/config/ports.rb'
18
+ require 'pwnage/config/repository.rb'
14
19
 
15
20
  require 'pwnage/executor.rb'
16
21
 
22
+ require 'pwnage/scaffolds/config.rb'
17
23
  require 'pwnage/scaffolds/dirs.rb'
18
24
  require 'pwnage/scaffolds/gems.rb'
19
25
  require 'pwnage/scaffolds/hook_mongrels.rb'
@@ -1,18 +1,18 @@
1
1
 
2
- # Gem::Specification for Rails_pwnerer-0.4.19
2
+ # Gem::Specification for Rails_pwnerer-0.5.0
3
3
  # Originally generated by Echoe
4
4
 
5
5
  --- !ruby/object:Gem::Specification
6
6
  name: rails_pwnerer
7
7
  version: !ruby/object:Gem::Version
8
- version: 0.4.19
8
+ version: 0.5.0
9
9
  platform: ruby
10
10
  authors:
11
11
  - Victor Costan
12
12
  autorequire:
13
13
  bindir: bin
14
14
 
15
- date: 2008-08-10 00:00:00 -04:00
15
+ date: 2008-08-15 00:00:00 -04:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_pwnerer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.19
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Costan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-10 00:00:00 -04:00
12
+ date: 2008-08-15 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency