rails_pwnerer 0.6.64 → 0.6.65

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/CHANGELOG +2 -0
  2. data/LICENSE +0 -0
  3. data/Manifest +51 -49
  4. data/README +0 -0
  5. data/RUBYFORGE +0 -0
  6. data/Rakefile +7 -11
  7. data/ext/rpwn_setup_notice/extconf.rb +24 -16
  8. data/lib/{pwnage → rails_pwnerer}/app/cluster_config.rb +17 -17
  9. data/lib/{pwnage → rails_pwnerer}/app/config.rb +14 -14
  10. data/lib/{pwnage → rails_pwnerer}/app/db/mysql.rb +9 -9
  11. data/lib/{pwnage → rails_pwnerer}/app/files.rb +13 -13
  12. data/lib/{pwnage → rails_pwnerer}/app/gems.rb +3 -3
  13. data/lib/{pwnage → rails_pwnerer}/app/main.rb +4 -4
  14. data/lib/{pwnage → rails_pwnerer}/app/nginx_config.rb +7 -7
  15. data/lib/{pwnage → rails_pwnerer}/app/scripts.rb +4 -4
  16. data/lib/{pwnage → rails_pwnerer}/app/vcs/git.rb +9 -9
  17. data/lib/{pwnage → rails_pwnerer}/app/vcs/perforce.rb +11 -11
  18. data/lib/{pwnage → rails_pwnerer}/app/vcs/svn.rb +9 -9
  19. data/lib/{pwnage → rails_pwnerer}/base/atomics.rb +1 -1
  20. data/lib/{pwnage → rails_pwnerer}/base/cpus.rb +1 -1
  21. data/lib/{pwnage → rails_pwnerer}/base/dirs.rb +1 -1
  22. data/lib/{pwnage → rails_pwnerer}/base/gems.rb +2 -2
  23. data/lib/{pwnage → rails_pwnerer}/base/hostname.rb +1 -1
  24. data/lib/{pwnage → rails_pwnerer}/base/input.rb +1 -1
  25. data/lib/rails_pwnerer/base/packages.rb +272 -0
  26. data/lib/{pwnage → rails_pwnerer}/base/process.rb +1 -1
  27. data/lib/{pwnage → rails_pwnerer}/base/rails.rb +1 -1
  28. data/lib/{pwnage → rails_pwnerer}/base/startup.rb +1 -1
  29. data/lib/{pwnage → rails_pwnerer}/base.rb +1 -1
  30. data/lib/{pwnage → rails_pwnerer}/config/app.rb +1 -1
  31. data/lib/{pwnage → rails_pwnerer}/config/frontends.rb +1 -1
  32. data/lib/rails_pwnerer/config/main.rb +3 -0
  33. data/lib/{pwnage → rails_pwnerer}/config/paths.rb +1 -1
  34. data/lib/{pwnage → rails_pwnerer}/config/ports.rb +1 -1
  35. data/lib/{pwnage → rails_pwnerer}/config/repository.rb +7 -7
  36. data/lib/rails_pwnerer/ctl_executor.rb +19 -0
  37. data/lib/{pwnage → rails_pwnerer}/dev_executor.rb +2 -2
  38. data/lib/{pwnage → rails_pwnerer}/executor.rb +17 -17
  39. data/lib/{pwnage → rails_pwnerer}/scaffolds/config.rb +7 -7
  40. data/lib/{pwnage → rails_pwnerer}/scaffolds/dir_permissions.rb +4 -4
  41. data/lib/{pwnage → rails_pwnerer}/scaffolds/dirs.rb +3 -3
  42. data/lib/{pwnage → rails_pwnerer}/scaffolds/gems.rb +2 -2
  43. data/lib/{pwnage → rails_pwnerer}/scaffolds/hook_daemon.rb +2 -2
  44. data/lib/{pwnage → rails_pwnerer}/scaffolds/hook_dyndns.rb +3 -3
  45. data/lib/{pwnage → rails_pwnerer}/scaffolds/mysql_config.rb +2 -2
  46. data/lib/rails_pwnerer/scaffolds/packages.rb +118 -0
  47. data/lib/{pwnage → rails_pwnerer}/scaffolds/rubygems.rb +2 -2
  48. data/lib/{pwnage → rails_pwnerer}/scaffolds/sshd.rb +2 -2
  49. data/lib/{pwnage → rails_pwnerer}/util/kill_process_set.rb +1 -1
  50. data/lib/rails_pwnerer/util/main.rb +5 -0
  51. data/lib/rails_pwnerer.rb +52 -52
  52. data/rails_pwnerer.gemspec +17 -7
  53. data/test/base_package_test.rb +126 -0
  54. data/test/helper.rb +25 -0
  55. metadata +151 -107
  56. data/lib/pwnage/base/packages.rb +0 -159
  57. data/lib/pwnage/config/main.rb +0 -3
  58. data/lib/pwnage/ctl_executor.rb +0 -19
  59. data/lib/pwnage/scaffolds/packages.rb +0 -110
  60. data/lib/pwnage/util/main.rb +0 -5
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.6.65. Tweaks and tests for package installation code.
2
+
1
3
  v0.6.64. mysql is the default again. mysql2 still fails.
2
4
 
3
5
  v0.6.63. Bugfix in mysql / mysql2 choosing code bugfix.
data/LICENSE CHANGED
File without changes
data/Manifest CHANGED
@@ -1,54 +1,56 @@
1
- bin/rpwn
2
- bin/rpwnctl
3
- bin/rpwndev
4
1
  CHANGELOG
5
- ext/rpwn_setup_notice/extconf.rb
6
- lib/pwnage/app/cluster_config.rb
7
- lib/pwnage/app/config.rb
8
- lib/pwnage/app/db/mysql.rb
9
- lib/pwnage/app/files.rb
10
- lib/pwnage/app/gems.rb
11
- lib/pwnage/app/main.rb
12
- lib/pwnage/app/nginx_config.rb
13
- lib/pwnage/app/scripts.rb
14
- lib/pwnage/app/vcs/git.rb
15
- lib/pwnage/app/vcs/perforce.rb
16
- lib/pwnage/app/vcs/svn.rb
17
- lib/pwnage/base/atomics.rb
18
- lib/pwnage/base/cpus.rb
19
- lib/pwnage/base/dirs.rb
20
- lib/pwnage/base/gems.rb
21
- lib/pwnage/base/hostname.rb
22
- lib/pwnage/base/input.rb
23
- lib/pwnage/base/packages.rb
24
- lib/pwnage/base/process.rb
25
- lib/pwnage/base/rails.rb
26
- lib/pwnage/base/startup.rb
27
- lib/pwnage/base.rb
28
- lib/pwnage/config/app.rb
29
- lib/pwnage/config/frontends.rb
30
- lib/pwnage/config/main.rb
31
- lib/pwnage/config/paths.rb
32
- lib/pwnage/config/ports.rb
33
- lib/pwnage/config/repository.rb
34
- lib/pwnage/ctl_executor.rb
35
- lib/pwnage/dev_executor.rb
36
- lib/pwnage/executor.rb
37
- lib/pwnage/scaffolds/config.rb
38
- lib/pwnage/scaffolds/dir_permissions.rb
39
- lib/pwnage/scaffolds/dirs.rb
40
- lib/pwnage/scaffolds/gems.rb
41
- lib/pwnage/scaffolds/hook_daemon.rb
42
- lib/pwnage/scaffolds/hook_dyndns.rb
43
- lib/pwnage/scaffolds/mysql_config.rb
44
- lib/pwnage/scaffolds/packages.rb
45
- lib/pwnage/scaffolds/rubygems.rb
46
- lib/pwnage/scaffolds/sshd.rb
47
- lib/pwnage/util/kill_process_set.rb
48
- lib/pwnage/util/main.rb
49
- lib/rails_pwnerer.rb
50
2
  LICENSE
51
3
  Manifest
52
- Rakefile
53
4
  README
54
5
  RUBYFORGE
6
+ Rakefile
7
+ bin/rpwn
8
+ bin/rpwnctl
9
+ bin/rpwndev
10
+ ext/rpwn_setup_notice/extconf.rb
11
+ lib/rails_pwnerer.rb
12
+ lib/rails_pwnerer/app/cluster_config.rb
13
+ lib/rails_pwnerer/app/config.rb
14
+ lib/rails_pwnerer/app/db/mysql.rb
15
+ lib/rails_pwnerer/app/files.rb
16
+ lib/rails_pwnerer/app/gems.rb
17
+ lib/rails_pwnerer/app/main.rb
18
+ lib/rails_pwnerer/app/nginx_config.rb
19
+ lib/rails_pwnerer/app/scripts.rb
20
+ lib/rails_pwnerer/app/vcs/git.rb
21
+ lib/rails_pwnerer/app/vcs/perforce.rb
22
+ lib/rails_pwnerer/app/vcs/svn.rb
23
+ lib/rails_pwnerer/base.rb
24
+ lib/rails_pwnerer/base/atomics.rb
25
+ lib/rails_pwnerer/base/cpus.rb
26
+ lib/rails_pwnerer/base/dirs.rb
27
+ lib/rails_pwnerer/base/gems.rb
28
+ lib/rails_pwnerer/base/hostname.rb
29
+ lib/rails_pwnerer/base/input.rb
30
+ lib/rails_pwnerer/base/packages.rb
31
+ lib/rails_pwnerer/base/process.rb
32
+ lib/rails_pwnerer/base/rails.rb
33
+ lib/rails_pwnerer/base/startup.rb
34
+ lib/rails_pwnerer/config/app.rb
35
+ lib/rails_pwnerer/config/frontends.rb
36
+ lib/rails_pwnerer/config/main.rb
37
+ lib/rails_pwnerer/config/paths.rb
38
+ lib/rails_pwnerer/config/ports.rb
39
+ lib/rails_pwnerer/config/repository.rb
40
+ lib/rails_pwnerer/ctl_executor.rb
41
+ lib/rails_pwnerer/dev_executor.rb
42
+ lib/rails_pwnerer/executor.rb
43
+ lib/rails_pwnerer/scaffolds/config.rb
44
+ lib/rails_pwnerer/scaffolds/dir_permissions.rb
45
+ lib/rails_pwnerer/scaffolds/dirs.rb
46
+ lib/rails_pwnerer/scaffolds/gems.rb
47
+ lib/rails_pwnerer/scaffolds/hook_daemon.rb
48
+ lib/rails_pwnerer/scaffolds/hook_dyndns.rb
49
+ lib/rails_pwnerer/scaffolds/mysql_config.rb
50
+ lib/rails_pwnerer/scaffolds/packages.rb
51
+ lib/rails_pwnerer/scaffolds/rubygems.rb
52
+ lib/rails_pwnerer/scaffolds/sshd.rb
53
+ lib/rails_pwnerer/util/kill_process_set.rb
54
+ lib/rails_pwnerer/util/main.rb
55
+ test/base_package_test.rb
56
+ test/helper.rb
data/README CHANGED
File without changes
data/RUBYFORGE CHANGED
File without changes
data/Rakefile CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'rubygems'
2
- gem 'echoe'
3
2
  require 'echoe'
4
3
 
5
4
  Echoe.new('rails_pwnerer') do |p|
@@ -7,22 +6,19 @@ Echoe.new('rails_pwnerer') do |p|
7
6
 
8
7
  p.author = 'Victor Costan'
9
8
  p.email = 'victor@costan.us'
10
- p.summary = 'Rails deployment tool/hack.'
9
+ p.summary = 'Rails deployment hack.'
11
10
  p.url = 'http://www.costan.us/rails_pwnage'
12
- p.runtime_dependencies = []
13
11
  p.dependencies = []
14
- # remove echoe, because it becomes a runtime dependency for rubygems < 1.2
15
- p.development_dependencies = []
16
- # override echoe's default of 1.2
17
- p.rubygems_version = '>= 0'
18
- p.extensions = ['ext/rpwn_setup_notice/extconf.rb']
12
+ p.development_dependencies = ['echoe', 'fakefs', 'flexmock']
13
+ p.extension_pattern = ['ext/**/extconf.rb']
19
14
  p.eval = proc do |p|
20
15
  p.default_executable = 'bin/rpwn'
21
16
  end
22
17
 
23
- p.need_tar_gz = true
24
- p.need_zip = true
25
- p.rdoc_pattern = /^(lib|bin|tasks|ext)|^BUILD|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
18
+ p.need_tar_gz = !Gem.win_platform?
19
+ p.need_zip = !Gem.win_platform?
20
+ p.rdoc_pattern =
21
+ /^(lib|bin|tasks|ext)|^BUILD|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
26
22
  end
27
23
 
28
24
  if $0 == __FILE__
@@ -1,19 +1,25 @@
1
- # invoked when the gem is installed
1
+ # Invoked when the gem is installed. Hack to get a post-install hook.
2
2
 
3
- # cheat to get the gem installed in the right place even on Debians
3
+ require 'rubygems'
4
+
5
+
6
+ # Cheat to get the gem binaries installed in the user's path even on Debians.
4
7
  ['rpwn', 'rpwnctl', 'rpwndev'].each do |file|
5
- binpath = "/usr/bin/#{file}"
6
- unless File.exists? binpath
7
- Kernel.system "ln -s #{File.expand_path(__FILE__ + "/../../../bin/#{file}")} #{binpath}"
8
+ bin_path = "/usr/bin/#{file}"
9
+ unless File.exists? bin_path
10
+ source_path = File.expand_path "../../../bin/#{file}", __FILE__
11
+ Kernel.system "ln -s #{source_path} #{bin_path}"
8
12
  end
9
13
 
10
- File.chmod((File.stat(binpath).mode | 0755), binpath)
14
+ File.chmod((File.stat(binpath).mode | 0755), binpath) rescue nil
11
15
  end
12
16
 
13
- # make the gem readable by anyone (workaround systems with messed up permission masks)
17
+ # Make the gem readable and runnable by anyone.
18
+ #
19
+ # This is a work-around for systems with messed up permission masks.
14
20
  def openup(path)
15
21
  if File.file?(path)
16
- File.chmod((File.stat(path).mode | 0755), path)
22
+ File.chmod((File.stat(path).mode | 0755), path) rescue nil
17
23
  return
18
24
  end
19
25
 
@@ -22,13 +28,15 @@ def openup(path)
22
28
  openup File.join(path, entry)
23
29
  end
24
30
  end
25
- base_path = File.expand_path(__FILE__ + "/../../../")
26
- openup(base_path)
31
+ base_path = File.expand_path "../../..", __FILE__
32
+ openup base_path
27
33
 
28
- # we really shouldn't be abusing rubygems' root; then again, the Debian maintaines shouldn't be
29
- # abusing the patience of Ruby developers
34
+ # We really shouldn't be abusing rubygems' root. Then again, the Debian
35
+ # maintaines shouldn't be abusing the patience of Ruby developers.
30
36
 
31
- # now trick rubygems into believeing that all is good
32
- File.open('Makefile', 'w') { |f| f.write "all:\n\ninstall:\n\n" }
33
- File.open('rpwn_setup_notice.so', 'w') {}
34
- File.open('rpwn_setup_notice.dll', 'w') {}
37
+ # Now trick rubygems and echoe into believeing that a gem got installed is good.
38
+ ext_binary = 'rpwn_setup_notice' + (Gem.win_platform? ? '.dll' : '.so')
39
+ File.open(ext_binary, 'w') { |f| }
40
+ File.open('Makefile', 'w') do |f|
41
+ f.write "# target_prefix = #{ext_binary}\nall:\n\ninstall:\n\n"
42
+ end
@@ -2,11 +2,11 @@
2
2
 
3
3
  require 'fileutils'
4
4
 
5
- class RailsPwnage::App::ClusterConfig
6
- include RailsPwnage::Base
5
+ class RailsPwnerer::App::ClusterConfig
6
+ include RailsPwnerer::Base
7
7
 
8
8
  def fix_permissions(app_name, instance_name)
9
- app_config = RailsPwnage::Config[app_name, instance_name]
9
+ app_config = RailsPwnerer::Config[app_name, instance_name]
10
10
  pwnerer_user = app_config[:pwnerer_user]
11
11
  pwnerer_uid = uid_for_username(pwnerer_user)
12
12
  pwnerer_group = group_for_username(pwnerer_user)
@@ -25,27 +25,27 @@ class RailsPwnage::App::ClusterConfig
25
25
  end
26
26
 
27
27
  def manage_ports(app_name, instance_name, action)
28
- app_config = RailsPwnage::Config[app_name, instance_name]
29
- return unless frontends = RailsPwnage::Config.app_frontends(app_name, instance_name)
28
+ app_config = RailsPwnerer::Config[app_name, instance_name]
29
+ return unless frontends = RailsPwnerer::Config.app_frontends(app_name, instance_name)
30
30
 
31
31
  case action
32
32
  when :alloc
33
- app_config[:port0] = RailsPwnage::Config.alloc_ports frontends
33
+ app_config[:port0] = RailsPwnerer::Config.alloc_ports frontends
34
34
  when :free
35
- RailsPwnage::Config.free_ports app_config[:port0], frontends
35
+ RailsPwnerer::Config.free_ports app_config[:port0], frontends
36
36
  return if app_config[:port0] == 0 # do not release if ports have already been released
37
37
  app_config[:port0] = 0
38
38
  end
39
- RailsPwnage::Config.flush_db RailsPwnage::Config.app_db_name(app_name, instance_name)
39
+ RailsPwnerer::Config.flush_db RailsPwnerer::Config.app_db_name(app_name, instance_name)
40
40
  end
41
41
 
42
42
  def stop(app_name, instance_name)
43
- app_config = RailsPwnage::Config[app_name, instance_name]
43
+ app_config = RailsPwnerer::Config[app_name, instance_name]
44
44
  # silently die if the app was completely busted
45
45
  return unless app_config and File.exists? app_config[:app_path]
46
46
 
47
47
  app_path, first_port = app_config[:app_path], app_config[:port0]
48
- frontends = RailsPwnage::Config.app_frontends(app_name, instance_name)
48
+ frontends = RailsPwnerer::Config.app_frontends(app_name, instance_name)
49
49
 
50
50
  cmdline_patterns = ['thin', nil]
51
51
 
@@ -55,7 +55,7 @@ class RailsPwnage::App::ClusterConfig
55
55
  fe_port = first_port + f
56
56
  cmdline = "thin stop -a 127.0.0.1 -p #{fe_port} -d -P tmp/pids/fe.#{fe_port}.pid"
57
57
  cmdline_patterns[1] = "(127.0.0.1:#{fe_port})"
58
- RailsPwnage::Util.kill_process_set(cmdline, "tmp/pids/fe.#{fe_port}.pid",
58
+ RailsPwnerer::Util.kill_process_set(cmdline, "tmp/pids/fe.#{fe_port}.pid",
59
59
  cmdline_patterns, :verbose => false, :sleep_delay => 0.2)
60
60
  end
61
61
 
@@ -63,13 +63,13 @@ class RailsPwnage::App::ClusterConfig
63
63
  end
64
64
 
65
65
  def start(app_name, instance_name)
66
- app_config = RailsPwnage::Config[app_name, instance_name]
66
+ app_config = RailsPwnerer::Config[app_name, instance_name]
67
67
  # silently die if the app was completely busted
68
68
  return unless app_config and File.exists? app_config[:app_path]
69
69
 
70
70
  app_path, pwnerer_user = app_config[:app_path], app_config[:pwnerer_user]
71
71
  pwnerer_group = group_for_username(pwnerer_user)
72
- frontends = RailsPwnage::Config.app_frontends(app_name, instance_name)
72
+ frontends = RailsPwnerer::Config.app_frontends(app_name, instance_name)
73
73
  first_port, environment = app_config[:port0], app_config[:environment]
74
74
 
75
75
  stop app_name, instance_name
@@ -78,7 +78,7 @@ class RailsPwnage::App::ClusterConfig
78
78
  if first_port == 0
79
79
  manage_ports app_name, instance_name, :alloc
80
80
  first_port = app_config[:port0]
81
- RailsPwnage::App::NginxConfig.new.update app_name, instance_name
81
+ RailsPwnerer::App::NginxConfig.new.update app_name, instance_name
82
82
  end
83
83
 
84
84
  static_cmd = "thin start -a 127.0.0.1 -c #{app_path} -d -u #{pwnerer_user}" +
@@ -128,12 +128,12 @@ class RailsPwnage::App::ClusterConfig
128
128
  end
129
129
 
130
130
  def control_all(action)
131
- RailsPwnage::Config.all_applications.each do |ai|
131
+ RailsPwnerer::Config.all_applications.each do |ai|
132
132
  case action
133
133
  when :start
134
- RailsPwnage::App::ClusterConfig.new.start ai[0], ai[1]
134
+ RailsPwnerer::App::ClusterConfig.new.start ai[0], ai[1]
135
135
  when :stop
136
- RailsPwnage::App::ClusterConfig.new.stop ai[0], ai[1]
136
+ RailsPwnerer::App::ClusterConfig.new.stop ai[0], ai[1]
137
137
  end
138
138
  end
139
139
  end
@@ -1,8 +1,8 @@
1
1
  # syncs the app's internal configuration with the configuration database
2
2
  require 'yaml'
3
3
 
4
- class RailsPwnage::App::Config
5
- include RailsPwnage::Base
4
+ class RailsPwnerer::App::Config
5
+ include RailsPwnerer::Base
6
6
 
7
7
  def random_db_password
8
8
  (0...16).map { |i| "abcdefghijklmnopqrstuvwxyz"[rand(26),1]}.join
@@ -13,12 +13,12 @@ class RailsPwnage::App::Config
13
13
  # update: this adds keys that might have been added in new versions of rpwn
14
14
  def populate_defaults(app_name, instance_name, app_db)
15
15
  # the path to application main files
16
- app_db[:app_path] = File.join(RailsPwnage::Config.path_to(:apps), app_name + '.' + instance_name)
16
+ app_db[:app_path] = File.join(RailsPwnerer::Config.path_to(:apps), app_name + '.' + instance_name)
17
17
  # the path to application backups
18
- app_db[:backup_path] ||= File.join(RailsPwnage::Config.path_to(:backups), app_name + '.' + instance_name)
18
+ app_db[:backup_path] ||= File.join(RailsPwnerer::Config.path_to(:backups), app_name + '.' + instance_name)
19
19
 
20
20
  # the user which will receive the "keys" to the production system
21
- app_db[:pwnerer_user] ||= RailsPwnage::Config[:host][:pwnerer_user]
21
+ app_db[:pwnerer_user] ||= RailsPwnerer::Config[:host][:pwnerer_user]
22
22
  # the number of frontends for the application instance
23
23
  app_db[:frontends] ||= 4 # most computers have 2 cores nowadays
24
24
  # the number of frontends per core for the application instance
@@ -52,19 +52,19 @@ class RailsPwnage::App::Config
52
52
 
53
53
  # allocates room for the application and creates the application configuration database
54
54
  def alloc(app_name, instance_name)
55
- app_db_name = RailsPwnage::Config.app_db_name(app_name, instance_name)
56
- app_db = RailsPwnage::Config.create_db app_db_name
55
+ app_db_name = RailsPwnerer::Config.app_db_name(app_name, instance_name)
56
+ app_db = RailsPwnerer::Config.create_db app_db_name
57
57
  populate_defaults app_name, instance_name, app_db
58
58
 
59
59
  FileUtils.mkpath app_db[:app_path]
60
60
 
61
- RailsPwnage::Config.flush_db app_db
61
+ RailsPwnerer::Config.flush_db app_db
62
62
  return app_db[:app_path]
63
63
  end
64
64
 
65
65
  # pushes config changes from the application file to the database
66
66
  def update(app_name, instance_name)
67
- app_config = RailsPwnage::Config[app_name, instance_name]
67
+ app_config = RailsPwnerer::Config[app_name, instance_name]
68
68
 
69
69
  db_name, db_user, db_pass = app_config[:db_name], app_config[:db_user], app_config[:db_pass]
70
70
  app_config.clear
@@ -95,16 +95,16 @@ class RailsPwnage::App::Config
95
95
  # TODO: if database settings changed, the database should be moved (re-created or re-keyed)
96
96
  if db_pass != app_config[:db_pass]
97
97
  db_pass = random_db_password if !db_pass || db_pass.empty?
98
- RailsPwnage::App::Database.new.manage app_name, instance_name, :rekey
98
+ RailsPwnerer::App::Database.new.manage app_name, instance_name, :rekey
99
99
  end
100
100
 
101
- RailsPwnage::Config.flush_db RailsPwnage::Config.app_db_name(app_name, instance_name)
101
+ RailsPwnerer::Config.flush_db RailsPwnerer::Config.app_db_name(app_name, instance_name)
102
102
  end
103
103
 
104
104
  def manage(app_name, instance_name, action)
105
105
  case action
106
106
  when :rekey
107
- app_config = RailsPwnage::Config[app_name, instance_name]
107
+ app_config = RailsPwnerer::Config[app_name, instance_name]
108
108
  app_config[:db_pass] = random_db_password
109
109
  end
110
110
  end
@@ -114,7 +114,7 @@ class RailsPwnage::App::Config
114
114
  end
115
115
 
116
116
  def remove(app_name, instance_name)
117
- app_db_name = RailsPwnage::Config.app_db_name(app_name, instance_name)
118
- RailsPwnage::Config.drop_db app_db_name
117
+ app_db_name = RailsPwnerer::Config.app_db_name(app_name, instance_name)
118
+ RailsPwnerer::Config.drop_db app_db_name
119
119
  end
120
120
  end
@@ -2,12 +2,12 @@
2
2
 
3
3
  require 'yaml'
4
4
 
5
- class RailsPwnage::App::Database
6
- include RailsPwnage::Base
5
+ class RailsPwnerer::App::Database
6
+ include RailsPwnerer::Base
7
7
 
8
8
  # creates/drops the mysql database for the application
9
9
  def admin_database(app_name, instance_name, action = :create)
10
- app_config = RailsPwnage::Config[app_name, instance_name]
10
+ app_config = RailsPwnerer::Config[app_name, instance_name]
11
11
  # exit and don't complain if the app is busted
12
12
  return unless app_config and File.exists? app_config[:app_path]
13
13
 
@@ -34,8 +34,8 @@ ENDSQL
34
34
 
35
35
  # run it
36
36
  File.open('admin_db.sql', 'w') { |f| f.write sql_commands }
37
- dbroot_name = RailsPwnage::Config[:host][:dbroot_name]
38
- dbroot_pass = RailsPwnage::Config[:host][:dbroot_pass]
37
+ dbroot_name = RailsPwnerer::Config[:host][:dbroot_name]
38
+ dbroot_pass = RailsPwnerer::Config[:host][:dbroot_pass]
39
39
  dbpass_arg = dbroot_pass.empty? ? '' : "-p#{dbroot_pass}"
40
40
  system "mysql -u#{dbroot_name} #{dbpass_arg} < admin_db.sql"
41
41
 
@@ -67,7 +67,7 @@ ENDSQL
67
67
 
68
68
  # configures rails to use the database in the production environment
69
69
  def configure_rails(app_name, instance_name)
70
- app_config = RailsPwnage::Config[app_name, instance_name]
70
+ app_config = RailsPwnerer::Config[app_name, instance_name]
71
71
  db_name, db_user, db_pass = app_config[:db_name], app_config[:db_user], app_config[:db_pass]
72
72
 
73
73
  config_file = File.join app_config[:app_path], 'config', 'database.yml'
@@ -89,7 +89,7 @@ ENDSQL
89
89
 
90
90
  # migrates the database to the latest schema version
91
91
  def migrate_database(app_name, instance_name)
92
- Dir.chdir RailsPwnage::Config[app_name, instance_name][:app_path] do
92
+ Dir.chdir RailsPwnerer::Config[app_name, instance_name][:app_path] do
93
93
  # now migrate the database
94
94
  system "rake db:migrate RAILS_ENV=production"
95
95
  end
@@ -97,7 +97,7 @@ ENDSQL
97
97
 
98
98
  # creates a database dump in the backup area
99
99
  def dump_database(app_name, instance_name)
100
- app_config = RailsPwnage::Config[app_name, instance_name]
100
+ app_config = RailsPwnerer::Config[app_name, instance_name]
101
101
  db_name, db_user, db_pass = app_config[:db_name], app_config[:db_user], app_config[:db_pass]
102
102
 
103
103
  pwnerer_user = app_config[:pwnerer_user]
@@ -118,7 +118,7 @@ ENDSQL
118
118
 
119
119
  # loads the latest database dump from the backup area
120
120
  def load_database(app_name, instance_name)
121
- app_config = RailsPwnage::Config[app_name, instance_name]
121
+ app_config = RailsPwnerer::Config[app_name, instance_name]
122
122
  db_name, db_user, db_pass = app_config[:db_name], app_config[:db_user], app_config[:db_pass]
123
123
 
124
124
  Dir.chdir app_config[:backup_path] do
@@ -1,19 +1,19 @@
1
1
  # manages an application's file system
2
2
 
3
- class RailsPwnage::App::Files
4
- include RailsPwnage::Base
3
+ class RailsPwnerer::App::Files
4
+ include RailsPwnerer::Base
5
5
 
6
6
  # dump the application files to the backup area
7
7
  def dump_files(app_name, instance_name)
8
- pwnerer_user = RailsPwnage::Config[app_name, instance_name][:pwnerer_user]
8
+ pwnerer_user = RailsPwnerer::Config[app_name, instance_name][:pwnerer_user]
9
9
  pwnerer_uid = uid_for_username(pwnerer_user)
10
10
  pwnerer_gid = gid_for_username(pwnerer_user)
11
11
 
12
12
  timestamp = Time.now.strftime '%Y%m%d%H%M%S'
13
13
  dump_file = "files/#{app_name}.#{instance_name}_#{timestamp}.tar.gz"
14
14
 
15
- backup_path = RailsPwnage::Config[app_name, instance_name][:backup_path]
16
- app_path = RailsPwnage::Config[app_name, instance_name][:app_path]
15
+ backup_path = RailsPwnerer::Config[app_name, instance_name][:backup_path]
16
+ app_path = RailsPwnerer::Config[app_name, instance_name][:app_path]
17
17
  Dir.chdir backup_path do
18
18
  # create a cold copy of the application files
19
19
  cold_copy = File.join('tmp', File.basename(app_path))
@@ -21,7 +21,7 @@ class RailsPwnage::App::Files
21
21
  FileUtils.cp_r app_path, 'tmp'
22
22
 
23
23
  # remove the garbage in the cold copy
24
- [RailsPwnage::App::Git, RailsPwnage::App::Svn].each do |mod|
24
+ [RailsPwnerer::App::Git, RailsPwnerer::App::Svn].each do |mod|
25
25
  mod.new.cleanup_app_caches cold_copy, instance_name, true
26
26
  end
27
27
 
@@ -39,11 +39,11 @@ class RailsPwnage::App::Files
39
39
 
40
40
  # creates the directory scaffold in the application's backup dir
41
41
  def scaffold_backup(app_name, instance_name)
42
- pwnerer_user = RailsPwnage::Config[app_name, instance_name][:pwnerer_user]
42
+ pwnerer_user = RailsPwnerer::Config[app_name, instance_name][:pwnerer_user]
43
43
  pwnerer_uid = uid_for_username(pwnerer_user)
44
44
  pwnerer_gid = gid_for_username(pwnerer_user)
45
45
 
46
- backup_path = RailsPwnage::Config[app_name, instance_name][:backup_path]
46
+ backup_path = RailsPwnerer::Config[app_name, instance_name][:backup_path]
47
47
  FileUtils.mkpath backup_path unless File.exists? backup_path
48
48
  File.chown(pwnerer_uid, pwnerer_gid, backup_path)
49
49
 
@@ -57,8 +57,8 @@ class RailsPwnage::App::Files
57
57
 
58
58
  # loads the latest file dump from the backup area
59
59
  def load_files(app_name, instance_name)
60
- backup_path = RailsPwnage::Config[app_name, instance_name][:backup_path]
61
- app_path = RailsPwnage::Config[app_name, instance_name][:app_path]
60
+ backup_path = RailsPwnerer::Config[app_name, instance_name][:backup_path]
61
+ app_path = RailsPwnerer::Config[app_name, instance_name][:app_path]
62
62
 
63
63
  dump_file = Dir.glob(File.join(backup_path, "files/#{app_name}.#{instance_name}_*")).max
64
64
  unless dump_file
@@ -73,7 +73,7 @@ class RailsPwnage::App::Files
73
73
 
74
74
  # remove the application files
75
75
  def drop_files(app_name, instance_name)
76
- app_config = RailsPwnage::Config[app_name, instance_name]
76
+ app_config = RailsPwnerer::Config[app_name, instance_name]
77
77
  # exit and don't complain if the app is busted
78
78
  return unless app_config and File.exists? app_config[:app_path]
79
79
 
@@ -89,7 +89,7 @@ class RailsPwnage::App::Files
89
89
  drop_files app_name, instance_name
90
90
  load_files app_name, instance_name
91
91
  when :console
92
- Dir.chdir(RailsPwnage::Config[app_name, instance_name][:app_path]) do
92
+ Dir.chdir(RailsPwnerer::Config[app_name, instance_name][:app_path]) do
93
93
  if File.exist? 'script/rails'
94
94
  Kernel.system 'rails console production'
95
95
  else
@@ -97,7 +97,7 @@ class RailsPwnage::App::Files
97
97
  end
98
98
  end
99
99
  when :db_console
100
- Dir.chdir(RailsPwnage::Config[app_name, instance_name][:app_path]) do
100
+ Dir.chdir(RailsPwnerer::Config[app_name, instance_name][:app_path]) do
101
101
  if File.exist? 'script/rails'
102
102
  Kernel.system 'rails dbconsole production --include-password'
103
103
  else
@@ -1,10 +1,10 @@
1
1
  # sets up the application gems
2
2
 
3
- class RailsPwnage::App::Gems
4
- include RailsPwnage::Base
3
+ class RailsPwnerer::App::Gems
4
+ include RailsPwnerer::Base
5
5
 
6
6
  def update(app_name, instance_name)
7
- app_config = RailsPwnage::Config[app_name, instance_name]
7
+ app_config = RailsPwnerer::Config[app_name, instance_name]
8
8
 
9
9
  Dir.chdir app_config[:app_path] do
10
10
  # Phase 1: app-directed install
@@ -1,11 +1,11 @@
1
- module RailsPwnage::App
1
+ module RailsPwnerer::App
2
2
  # internal method implementing magic instance names
3
3
  def self.instance_magic(app_name, instance_name)
4
4
  case instance_name
5
5
  when '*'
6
- RailsPwnage::Config.all_instances app_name { |i| yield app_name, i }
6
+ RailsPwnerer::Config.all_instances app_name { |i| yield app_name, i }
7
7
  when '.'
8
- yield app_name, RailsPwnage::Config[:host][:instance]
8
+ yield app_name, RailsPwnerer::Config[:host][:instance]
9
9
  else
10
10
  yield app_name, instance_name
11
11
  end
@@ -119,7 +119,7 @@ module RailsPwnage::App
119
119
  when :db_console
120
120
  Files.new.manage app, instance, action
121
121
  when :db_reset
122
- app_config = RailsPwnage::Config[app, instance]
122
+ app_config = RailsPwnerer::Config[app, instance]
123
123
  unless app_config[:enable_db_reset]
124
124
  print "Database resets are disabled for this instance.\n"
125
125
  print "If you truly want to reset, add the :enable_db_reset configuration key.\n"
@@ -1,11 +1,11 @@
1
1
  # builds the nginx configuration
2
2
 
3
- class RailsPwnage::App::NginxConfig
4
- include RailsPwnage::Base
3
+ class RailsPwnerer::App::NginxConfig
4
+ include RailsPwnerer::Base
5
5
 
6
6
  # writes the nginx configuration for this server
7
7
  def config_nginx(app_name, instance_name)
8
- app_config = RailsPwnage::Config[app_name, instance_name]
8
+ app_config = RailsPwnerer::Config[app_name, instance_name]
9
9
  first_port = app_config[:port0]
10
10
 
11
11
  # Can be specified as comma-separated string or array.
@@ -18,12 +18,12 @@ class RailsPwnage::App::NginxConfig
18
18
  default_app_port = app_config[:ssl_key] ? 443 : 80
19
19
  app_port = app_config[:port] || default_app_port
20
20
 
21
- nginx_config = File.join(RailsPwnage::Config.path_to(:nginx_configs),
21
+ nginx_config = File.join(RailsPwnerer::Config.path_to(:nginx_configs),
22
22
  app_name + '.' + instance_name)
23
23
  File.open(nginx_config, 'w') do |f|
24
24
  # link to the frontends
25
25
  f << " upstream #{app_name}_#{instance_name} {\n"
26
- RailsPwnage::Config.app_frontends(app_name, instance_name).times do |instance|
26
+ RailsPwnerer::Config.app_frontends(app_name, instance_name).times do |instance|
27
27
  f << " server 127.0.0.1:#{first_port + instance};\n"
28
28
  end
29
29
  f << " }\n\n"
@@ -68,13 +68,13 @@ NGINX_CONFIG
68
68
  end
69
69
 
70
70
  def remove_nginx_config(app_name, instance_name)
71
- nginx_config = File.join(RailsPwnage::Config.path_to(:nginx_configs), app_name + '.' + instance_name)
71
+ nginx_config = File.join(RailsPwnerer::Config.path_to(:nginx_configs), app_name + '.' + instance_name)
72
72
  File.delete nginx_config if File.exists? nginx_config
73
73
  end
74
74
 
75
75
  # removes the default configuration stub (so nginx doesn't stumble upon it)
76
76
  def remove_nginx_stub
77
- stub_file = File.join(RailsPwnage::Config.path_to(:nginx_configs), 'default')
77
+ stub_file = File.join(RailsPwnerer::Config.path_to(:nginx_configs), 'default')
78
78
  File.delete stub_file if File.exists?(stub_file)
79
79
  end
80
80
 
@@ -1,10 +1,10 @@
1
1
  # runs custom scripts on app events
2
2
 
3
- class RailsPwnage::App::Scripts
4
- include RailsPwnage::Base
3
+ class RailsPwnerer::App::Scripts
4
+ include RailsPwnerer::Base
5
5
 
6
6
  def run_script(app_name, instance_name, script_name)
7
- app_config = RailsPwnage::Config[app_name, instance_name]
7
+ app_config = RailsPwnerer::Config[app_name, instance_name]
8
8
  pwnerer_user = app_config[:pwnerer_user]
9
9
  pwnerer_uid = uid_for_username(pwnerer_user)
10
10
  pwnerer_gid = gid_for_username(pwnerer_user)
@@ -70,7 +70,7 @@ class RailsPwnage::App::Scripts
70
70
  end
71
71
 
72
72
  def control_all(action)
73
- RailsPwnage::Config.all_applications.each do |ai|
73
+ RailsPwnerer::Config.all_applications.each do |ai|
74
74
  run_script ai[0], ai[1], (case action
75
75
  when :pre_start then 'pre_start'
76
76
  when :post_start then 'post_start'