rails_pwnerer 0.5.19 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.6.0. Replaced mongrel with thin, for better performance.
2
+
1
3
  v0.5.19. Bugfix: the nginx configuration is set up for static serving out of public/
2
4
 
3
5
  v0.5.18. Bugfix: removal scripts are called at the right time too.
data/README CHANGED
@@ -19,8 +19,9 @@ Read a couple more 20-page guides, and learn to push newer versions
19
19
  of your application. You'll become lazy, and take shortcuts, like having
20
20
  production passwords in the repository, or insecure file permissions, or
21
21
  you'll forget to delete cached javascripts and stylesheets from public/.
22
- I won't even mention backups. Or scripts to recover your mongrels
23
- properly from power outages. Or a staging server of your application.
22
+ I won't even mention backups. Or scripts to recover your frontends
23
+ (mongrel / thin) properly from power outages. Or a staging server of your
24
+ application.
24
25
 
25
26
  Life with +rails_pwnerer+:
26
27
 
@@ -109,12 +110,12 @@ overrides will be version-controlled). In your Rails directory
109
110
  * Set the DNS name that your app responds to:
110
111
  rpwndev set dns-name your.dns.name
111
112
 
112
- * Tweak the number of mongrels for an instance:
113
- rpwndev setnum mongrels 8 your_instance
113
+ * Tweak the number of frontends for an instance:
114
+ rpwndev setnum frontends 8 your_instance
114
115
 
115
116
  * Delete the previous tweak and apply it to all instances:
116
- rpwndev del mongrels your_instance;
117
- rpwndev setnum mongrels
117
+ rpwndev del frontends your_instance;
118
+ rpwndev setnum frontends
118
119
 
119
120
  The overrides are YAML files in +config/rails_pwnage+, so you
120
121
  can view and edit them by hand. rpwndev is just a handy tool,
@@ -1,4 +1,4 @@
1
- # builds the mongrel cluster configuration
1
+ # builds the frontend cluster configuration
2
2
 
3
3
  require 'fileutils'
4
4
 
@@ -26,52 +26,39 @@ class RailsPwnage::App::ClusterConfig
26
26
 
27
27
  def manage_ports(app_name, instance_name, action)
28
28
  app_config = RailsPwnage::Config[app_name, instance_name]
29
- return unless app_config and app_config[:port0] and app_config[:mongrels]
29
+ return unless app_config and app_config[:port0] and app_config[:frontends]
30
30
 
31
31
  case action
32
32
  when :alloc
33
- app_config[:port0] = RailsPwnage::Config.alloc_ports app_config[:mongrels]
33
+ app_config[:port0] = RailsPwnage::Config.alloc_ports app_config[:frontends]
34
34
  when :free
35
35
  return if app_config[:port0] == 0 # do not release if ports have already been released
36
- RailsPwnage::Config.free_ports app_config[:port0], app_config[:mongrels]
36
+ RailsPwnage::Config.free_ports app_config[:port0], app_config[:frontends]
37
37
  app_config[:port0] = 0
38
38
  end
39
39
  RailsPwnage::Config.flush_db RailsPwnage::Config.app_db_name(app_name, instance_name)
40
40
  end
41
41
 
42
-
43
- def configure_mongrels(app_name, instance_name)
44
- app_config = RailsPwnage::Config[app_name, instance_name]
45
-
46
- app_path, pwnerer_user = app_config[:app_path], app_config[:pwnerer_user]
47
- pwnerer_group = group_for_username(pwnerer_user)
48
-
49
- mongrels, first_port = app_config[:mongrels], app_config[:port0]
50
-
51
- Dir.chdir(app_path) do
52
- # create the mongrel_cluster configuration
53
- Kernel.system("mongrel_rails cluster::configure -e production" +
54
- " -N #{mongrels} -p #{first_port} -a 127.0.0.1 -c #{app_path}" +
55
- " --user #{pwnerer_user} --group #{pwnerer_group}")
56
- end
57
- end
58
-
59
- def remove_mongrels(app_name, instance_name)
60
- # bomb the configuration from the launch directory
61
- launch_config = File.join RailsPwnage::Config.path_to(:mongrel_configs), "#{app_name}.#{instance_name}.yml"
62
- File.delete launch_config if File.exists? launch_config
63
- end
64
-
65
42
  def stop(app_name, instance_name)
66
43
  app_config = RailsPwnage::Config[app_name, instance_name]
67
44
  # silently die if the app was completely busted
68
45
  return unless app_config and File.exists? app_config[:app_path]
69
46
 
70
- cmdline_patterns = ['mongrel', app_config[:app_path] + ' ', 'tmp/pids/mongrel', 'log/mongrel']
47
+ app_path = app_config[:app_path]
48
+ frontends, first_port = app_config[:frontends], app_config[:port0]
49
+
50
+ cmdline_patterns = ['thin', nil]
71
51
 
72
- Dir.chdir app_config[:app_path] do
73
- RailsPwnage::Util.kill_process_set('mongrel_rails cluster::stop',
74
- 'tmp/pids/*.pid', cmdline_patterns, :verbose => false, :sleep_delay => 0.5)
52
+ Dir.chdir app_path do
53
+ # TODO: stop processes in parallel
54
+ frontends.times do |f|
55
+ fe_port = first_port + f
56
+ cmdline = "thin stop -a 127.0.0.1 -p #{fe_port} -d -P tmp/pids/fe.#{fe_port}.pid"
57
+ cmdline_patterns[1] = "(127.0.0.1:#{fe_port})"
58
+ RailsPwnage::Util.kill_process_set(cmdline, "tmp/pids/fe.#{fe_port}.pid",
59
+ cmdline_patterns, :verbose => false, :sleep_delay => 0.2)
60
+ end
61
+
75
62
  end
76
63
  end
77
64
 
@@ -80,23 +67,34 @@ class RailsPwnage::App::ClusterConfig
80
67
  # silently die if the app was completely busted
81
68
  return unless app_config and File.exists? app_config[:app_path]
82
69
 
70
+ app_path, pwnerer_user = app_config[:app_path], app_config[:pwnerer_user]
71
+ pwnerer_group = group_for_username(pwnerer_user)
72
+ frontends, first_port = app_config[:frontends], app_config[:port0]
73
+
83
74
  stop app_name, instance_name
84
75
 
85
76
  # alloc a port if somehow that slipped through the cracks
86
- if app_config[:port0] == 0
77
+ if first_port == 0
87
78
  manage_ports app_name, instance_name, :alloc
88
- configure_mongrels app_name, instance_name
79
+ first_port = app_config[:port0]
89
80
  RailsPwnage::App::NginxConfig.new.update app_name, instance_name
90
81
  end
91
82
 
83
+ static_cmd = "thin start -a 127.0.0.1 -A rails -c #{app_path} -d -u #{pwnerer_user}" +
84
+ " -g #{pwnerer_group} -e production "
85
+
86
+ # TODO: start the servers simultaneously
92
87
  Dir.chdir app_config[:app_path] do
93
- Kernel.system 'mongrel_rails cluster::start'
94
- end
88
+ frontends.times do |f|
89
+ fe_port = first_port + f
90
+ cmd = static_cmd + "-p #{fe_port} -l logs/fe.#{fe_port}.log -P tmp/pids/fe.#{fe_port}.pid"
91
+ Kernel.system cmd
92
+ end
93
+ end
95
94
  end
96
95
 
97
96
  def setup(app_name, instance_name)
98
97
  manage_ports app_name, instance_name, :alloc
99
- configure_mongrels app_name, instance_name
100
98
  fix_permissions app_name, instance_name
101
99
  # no need to configure nginx here, it'll be done by the executor
102
100
  end
@@ -106,12 +104,10 @@ class RailsPwnage::App::ClusterConfig
106
104
  end
107
105
  def post_update(app_name, instance_name)
108
106
  manage_ports app_name, instance_name, :alloc
109
- configure_mongrels app_name, instance_name
110
107
  fix_permissions app_name, instance_name
111
108
  end
112
109
 
113
110
  def remove(app_name, instance_name)
114
- remove_mongrels app_name, instance_name
115
111
  manage_ports app_name, instance_name, :free
116
112
  end
117
113
 
@@ -120,7 +116,6 @@ class RailsPwnage::App::ClusterConfig
120
116
  when :checkpoint
121
117
  # nothing to do here
122
118
  when :rollback
123
- configure_mongrels app_name, instance_name
124
119
  fix_permissions app_name, instance_name
125
120
  end
126
121
  end
@@ -19,8 +19,8 @@ class RailsPwnage::App::Config
19
19
 
20
20
  # the user which will receive the "keys" to the production system
21
21
  app_db[:pwnerer_user] = 'victor'
22
- # the number of mongrel instances for the application instance
23
- app_db[:mongrels] = 4
22
+ # the number of frontends for the application instance
23
+ app_db[:frontends] = 4
24
24
  # the first internal port for the application instance
25
25
  app_db[:port0] = 0 # will be overwritten during allocation
26
26
  # the name of the database for the application instance
@@ -11,9 +11,9 @@ class RailsPwnage::App::NginxConfig
11
11
 
12
12
  nginx_config = File.join(RailsPwnage::Config.path_to(:nginx_configs), app_name + '.' + instance_name)
13
13
  File.open(nginx_config, 'w') do |f|
14
- # link to the mongrels
14
+ # link to the frontends
15
15
  f << " upstream #{app_name}_#{instance_name} {\n"
16
- app_config[:mongrels].times do |instance|
16
+ app_config[:frontends].times do |instance|
17
17
  f << " server 127.0.0.1:#{first_port + instance};\n"
18
18
  end
19
19
  f << " }\n\n"
@@ -7,8 +7,6 @@ class RailsPwnage::Scaffolds::Config
7
7
  def run
8
8
  # paths
9
9
  paths_db = RailsPwnage::Config.create_db :paths
10
- # the directory containing the mongrel_cluster config files
11
- paths_db[:mongrel_configs] = '/etc/mongrel_cluster'
12
10
  # the directory containing the nginx config files
13
11
  paths_db[:nginx_configs] = '/etc/nginx/sites-enabled'
14
12
  # the directory containing the ddclient configuration
@@ -9,7 +9,7 @@ class RailsPwnage::Scaffolds::Gems
9
9
  end
10
10
 
11
11
  def install_servers
12
- install_gems %w(rails mongrel mongrel_cluster)
12
+ install_gems %w(rails thin)
13
13
  end
14
14
 
15
15
  def install_dbi
@@ -17,7 +17,7 @@ class RailsPwnage::Scaffolds::Gems
17
17
  end
18
18
 
19
19
  def install_tools
20
- # we need this to do controlled mongrel startups
20
+ # we need this to do controlled app container startups
21
21
  install_gems %w(sys-proctable)
22
22
 
23
23
  # TODO: an application should have its own tools
@@ -1,18 +1,18 @@
1
1
 
2
- # Gem::Specification for Rails_pwnerer-0.5.19
2
+ # Gem::Specification for Rails_pwnerer-0.6.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.5.19
8
+ version: 0.6.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-30 00:00:00 -04:00
15
+ date: 2008-09-02 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.5.19
4
+ version: 0.6.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-30 00:00:00 -04:00
12
+ date: 2008-09-02 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency