rsm 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 0.1.3 / September 04, 2011
2
+
3
+ * Using socket_per_worker in nginx upstream server config
4
+
5
+ # 0.1.2 / September 04, 2011
6
+
7
+ * Added support of Thin server: generate config, start/stop/restart
8
+ * Fixed domain from hostname
9
+
1
10
  # 0.1.1 / September 04, 2011
2
11
 
3
12
  * Added `rsm:bundle:install` and `rsm:bundle:update` tasks
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.3
data/lib/rsm/base.rb CHANGED
@@ -5,11 +5,19 @@ module Rsm
5
5
  include Thor::Actions
6
6
  include Actions
7
7
 
8
+ SERVERS = [:unicorn, :thin]
9
+
10
+ attr_reader :server, :worker_processes, :socket_per_worker
11
+
8
12
  argument :name
9
13
 
10
14
  class_option :apps_root, :default => "/var/www", :aliases => "-r", :desc => "Rails apps root"
11
15
  class_option :capistrano, :default => false, :aliases => "-c", :desc => "Application's Capistrano stage"
12
16
 
17
+ class_option :server, :aliases => "-s", :default => :unicorn, :desc => "What server we will use"
18
+ class_option :worker_processes, :type => :numeric, :default => 2, :aliases => "-w", :desc => "Worker processes of server we will use"
19
+ class_option :environment, :aliases => "-e", :default => "production"
20
+
13
21
  class_option :verbose, :default => false, :aliases => "-V", :desc => "Verbose output"
14
22
 
15
23
  def self.template_path
@@ -23,5 +31,15 @@ module Rsm
23
31
  def set_destination_root
24
32
  self.destination_root = application_root.to_s
25
33
  end
34
+
35
+ def set_server
36
+ @server = options[:server].to_sym
37
+ raise "Unknown server #{options[:server].inspect}. Available is #{SERVERS}" unless SERVERS.include?(server)
38
+ @socket_per_worker = (server == :thin)
39
+ end
40
+
41
+ def set_worker_processes
42
+ @worker_processes = options[:worker_processes]
43
+ end
26
44
  end
27
45
  end
@@ -5,7 +5,7 @@ module Rsm
5
5
 
6
6
  class_option :nginx_root, :default => "/etc/nginx", :aliases => "-n", :desc => "Nginx configuration root"
7
7
  class_option :domain, :aliases => "-d", :desc => "Server's domain"
8
- class_option :rewrite_www, :type => :boolean, :default => false, :desc => "Added www-subdomain rewriting"
8
+ class_option :rewrite_www, :type => :boolean, :default => false, :desc => "Use www-subdomain rewriting"
9
9
 
10
10
  class_option :auth_basic, :type => :boolean, :default => false, :aliases => "-a", :desc => "Use auth_basic"
11
11
  class_option :auth_basic_realm, :desc => "auth_basic realm or capitalized NAME unless set"
@@ -22,9 +22,12 @@ module Rsm
22
22
  end
23
23
  end
24
24
 
25
- def nginx_unicorn_config
25
+ def nginx_server_config
26
26
  @domain = options[:domain]
27
- @domain = "#{application_name}.`hostname -f`" unless @domain
27
+ unless @domain
28
+ @domain = `hostname -f`.strip
29
+ @domain = "#{name}.#{@domain}"
30
+ end
28
31
 
29
32
  @rewrite_www = options[:rewrite_www]
30
33
 
@@ -33,7 +36,7 @@ module Rsm
33
36
  @auth_basic_realm = name.to_s.capitalize unless @auth_basic_realm
34
37
  @auth_basic_user_file = options[:auth_basic_user_file]
35
38
 
36
- template "nginx-unicorn.conf.erb", "sites-available.d/#{name}.conf"
39
+ template "nginx-server.conf.erb", "sites-available.d/#{name}.conf"
37
40
  end
38
41
 
39
42
  def enable_nginx_site
@@ -1,7 +1,6 @@
1
1
  module Rsm
2
2
  module Install
3
3
  class Rails < Rsm::Base
4
- attr_reader :worker_processes
5
4
 
6
5
  class_option :user, :aliases => "-u", :default => "git", :desc => "Owners's user"
7
6
  class_option :group, :aliases => "-g", :default => "git", :desc => "Owners's group"
@@ -10,8 +9,6 @@ module Rsm
10
9
  class_option :tgz, :desc => "Install from TGZ (tar.gz)"
11
10
  class_option :tbz2, :desc => "Install from TBZ2 (tar.bz2)"
12
11
 
13
- class_option :worker_processes, :type => :numeric, :default => 2, :aliases => "-w", :desc => "Worker processes for use in Unicorn"
14
-
15
12
  def download
16
13
  empty_directory "."
17
14
  inside application_root do
@@ -39,9 +36,21 @@ module Rsm
39
36
  end
40
37
 
41
38
  def unicorn_config
42
- @worker_processes = options[:worker_processes]
43
39
  template "unicorn.rb.erb", "config/unicorn.rb"
44
40
  end
41
+ remove_task :unicorn_config
42
+
43
+ def thin_config
44
+ inside "." do
45
+ run_ruby_binary "thin config -C config/thin.yml -S tmp/sockets/thin.sock -s #{options[:worker_processes]} -e #{options[:environment]}"
46
+ end
47
+ end
48
+ remove_task :thin_config
49
+
50
+ def server_config
51
+ send("#{server}_config")
52
+ end
53
+
45
54
  end
46
55
  end
47
56
  end
@@ -0,0 +1,11 @@
1
+ module Rsm
2
+ module Thin
3
+ class Restart < Rsm::Base
4
+
5
+ def thin_restart
6
+ run_ruby_binary "thin restart -C #{application_root}/config/thin.yml"
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Rsm
2
+ module Thin
3
+ class Start < Rsm::Base
4
+
5
+ def thin_start
6
+ run_ruby_binary "thin start -C #{application_root}/config/thin.yml"
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Rsm
2
+ module Thin
3
+ class Stop < Rsm::Base
4
+
5
+ def thin_stop
6
+ run_ruby_binary "thin stop -C #{application_root}/config/thin.yml"
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -1,7 +1,6 @@
1
1
  module Rsm
2
2
  module Unicorn
3
3
  class Start < Rsm::Base
4
- class_option :environment, :aliases => "-e", :default => "production"
5
4
 
6
5
  def unicorn_rails
7
6
  run_ruby_binary "unicorn_rails -D -E #{options[:environment]} -c #{application_root.join("config", "unicorn.rb")}"
@@ -1,10 +1,16 @@
1
1
  upstream <%= name %>_server {
2
- server unix:<%= application_root %>/tmp/sockets/unicorn.sock fail_timeout=0; # socket path must be same with last one in #{application_root}/config/unicorn.rb
2
+ <%- if socket_per_worker -%>
3
+ <%- (0...worker_processes).each do |n| -%>
4
+ server unix:<%= application_root %>/tmp/sockets/<%= server %>.<%= n %>.sock fail_timeout=0; # socket path must be same with last one in #{application_root}/config/unicorn.rb
5
+ <%- end -%>
6
+ <%- else -%>
7
+ server unix:<%= application_root %>/tmp/sockets/<%= server %>.sock fail_timeout=0; # socket path must be same with last one in #{application_root}/config/unicorn.rb
8
+ <%- end -%>
3
9
  }
4
10
 
5
11
  server {
6
12
  listen <%= domain %>:80;
7
- server_name <%= domain %><%= if rewrite_www then "www.#{domain}" end -%>;
13
+ server_name <%= domain -%><%= if rewrite_www then " www.#{domain}" end -%>;
8
14
 
9
15
  client_max_body_size 1G;
10
16
  keepalive_timeout 5;
@@ -16,17 +22,17 @@ server {
16
22
  error_log <%= application_root %>/log/error.log;
17
23
 
18
24
  location @<%= name %> {
19
- <% if auth_basic -%>
25
+ <%- if auth_basic -%>
20
26
  auth_basic "<%= auth_basic_realm %>";
21
27
  auth_basic_user_file <%= auth_basic_user_file%>;
22
- <% end -%>
28
+ <%- end -%>
23
29
 
24
- <% if rewrite_www -%>
30
+ <%- if rewrite_www -%>
25
31
  if ($host ~* www\.(.*)) {
26
32
  set $host_without_www $1;
27
33
  rewrite ^(.*)$ http://$host_without_www$1 permanent; # $1 contains '/foo', not 'www.mydomain.com/foo'}
28
34
  }
29
- <% end -%>
35
+ <%- end -%>
30
36
 
31
37
  if (!-f $request_filename) {
32
38
  proxy_pass http://<%= name %>_server;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-09-04 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &81380070 !ruby/object:Gem::Requirement
16
+ requirement: &72444900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.14.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *81380070
24
+ version_requirements: *72444900
25
25
  description: Thor tasks for rapid deployment new rails apps on server
26
26
  email: a.ulyanitsky@gmail.com
27
27
  executables:
@@ -48,10 +48,13 @@ files:
48
48
  - lib/tasks/bundle/update.rb
49
49
  - lib/tasks/install/nginx.rb
50
50
  - lib/tasks/install/rails.rb
51
+ - lib/tasks/thin/restart.rb
52
+ - lib/tasks/thin/start.rb
53
+ - lib/tasks/thin/stop.rb
51
54
  - lib/tasks/unicorn/start.rb
52
55
  - lib/tasks/unicorn/stop.rb
53
56
  - rsm.gemspec
54
- - templates/rsm/install/nginx/nginx-unicorn.conf.erb
57
+ - templates/rsm/install/nginx/nginx-server.conf.erb
55
58
  - templates/rsm/install/rails/unicorn.rb.erb
56
59
  homepage: https://github.com/asux/rsm
57
60
  licenses: