rsm 0.1.beta1 → 0.1.beta2
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/CHANGES.md +8 -0
- data/VERSION +1 -1
- data/lib/rsm/base.rb +32 -0
- data/lib/rsm/install/nginx.rb +8 -16
- data/lib/rsm/install/rails.rb +7 -20
- data/lib/rsm/runner.rb +5 -16
- data/lib/rsm/unicorn.rb +13 -0
- data/lib/rsm.rb +2 -0
- data/templates/{nginx-vhost.conf.erb → nginx-unicorn.conf.erb} +5 -5
- metadata +7 -5
data/CHANGES.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
# 0.1.beta2 / August 31, 2011
|
2
|
+
|
3
|
+
* Some code moved to `Rsm::Install::Base`
|
4
|
+
* Nginx config template uses `application_root` variable
|
5
|
+
* Changed injection in nginx.conf
|
6
|
+
* Command `unicorn` accepts environment option
|
7
|
+
* Capistrano-aware `application_root`
|
8
|
+
|
1
9
|
# 0.1.beta1 / August 30, 2011
|
2
10
|
|
3
11
|
* Methods in `Rsm::Actions` use `name` attribute
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.beta2
|
data/lib/rsm/base.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module Rsm
|
4
|
+
class Base < Thor::Group
|
5
|
+
include Thor::Actions
|
6
|
+
include Actions
|
7
|
+
|
8
|
+
argument :name
|
9
|
+
|
10
|
+
class_option :apps_root, :defualt => "/var/www", :aliases => "-r", :desc => "Rails apps root (default: /var/www)"
|
11
|
+
class_option :capistrano, :defualt => false, :aliases => "-c", :desc => "Application's Capistrano stage"
|
12
|
+
|
13
|
+
def self.source_root
|
14
|
+
File.expand_path('../../../templates', __FILE__)
|
15
|
+
end
|
16
|
+
|
17
|
+
def application_root
|
18
|
+
unless @application_root
|
19
|
+
@application_root = if options[:capistrano]
|
20
|
+
"#{options[:apps_root]}/#{name}/#{options[:capistrano]}/current"
|
21
|
+
else
|
22
|
+
"#{options[:apps_root]}/#{name}"
|
23
|
+
end
|
24
|
+
@application_root = Pathname.new(@application_root)
|
25
|
+
say "Application root: #{@application_root}"
|
26
|
+
end
|
27
|
+
@application_root
|
28
|
+
end
|
29
|
+
remove_task :application_root
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
data/lib/rsm/install/nginx.rb
CHANGED
@@ -1,38 +1,30 @@
|
|
1
1
|
module Rsm
|
2
2
|
module Install
|
3
|
-
class Nginx <
|
4
|
-
include Thor::Actions
|
5
|
-
|
3
|
+
class Nginx < Rsm::Base
|
6
4
|
attr_reader :domain
|
7
5
|
|
8
|
-
argument :name
|
9
|
-
|
10
6
|
class_option :nginx_root, :default => "/etc/nginx", :aliases => "-n", :desc => "Nginx configuration root"
|
11
7
|
class_option :domain, :aliases => "-d", :desc => "Server's domain"
|
12
8
|
|
13
|
-
def self.source_root
|
14
|
-
File.expand_path('../../../..', __FILE__)
|
15
|
-
end
|
16
|
-
|
17
9
|
def set_destination_root
|
18
10
|
self.destination_root = options[:nginx_root]
|
19
11
|
end
|
20
12
|
|
21
|
-
def
|
22
|
-
include_str = "include sites-enabled.d/*.conf
|
23
|
-
unless File.read("#{
|
24
|
-
inject_into_file "nginx.conf", include_str, :
|
13
|
+
def nginx_config_include_vhosts
|
14
|
+
include_str = "include sites-enabled.d/*.conf;"
|
15
|
+
unless File.read("#{destination_root}/nginx.conf").include?(include_str)
|
16
|
+
inject_into_file "nginx.conf", "#{include_str}\n", :after => "index index.html;\n"
|
25
17
|
end
|
26
18
|
end
|
27
19
|
|
28
|
-
def
|
20
|
+
def nginx_unicorn_config
|
29
21
|
@domain = options[:domain]
|
30
22
|
@domain = `hostname` unless @domain
|
31
|
-
template "
|
23
|
+
template "nginx-unicorn.conf.erb", "sites-available.d/#{name}.conf"
|
32
24
|
end
|
33
25
|
|
34
26
|
def enable_nginx_site
|
35
|
-
link_file "#{
|
27
|
+
link_file "#{destination_root}/sites-available.d/#{name}.conf", "sites-enabled.d/#{name}.conf"
|
36
28
|
end
|
37
29
|
|
38
30
|
end
|
data/lib/rsm/install/rails.rb
CHANGED
@@ -1,14 +1,7 @@
|
|
1
1
|
module Rsm
|
2
2
|
module Install
|
3
|
-
class Rails <
|
4
|
-
|
5
|
-
include Actions
|
6
|
-
|
7
|
-
attr_reader :application_root, :worker_processes
|
8
|
-
|
9
|
-
argument :name
|
10
|
-
|
11
|
-
class_option :apps_root, :defualt => "/var/www", :aliases => "-r", :desc => "Rails apps root (default: /var/www)"
|
3
|
+
class Rails < Rsm::Base
|
4
|
+
attr_reader :worker_processes
|
12
5
|
|
13
6
|
class_option :user, :aliases => "-u", :default => "git", :desc => "Owners's user"
|
14
7
|
class_option :group, :aliases => "-g", :default => "git", :desc => "Owners's group"
|
@@ -19,17 +12,12 @@ module Rsm
|
|
19
12
|
|
20
13
|
class_option :worker_processes, :type => :numeric, :default => 2, :aliases => "-w", :desc => "Worker processes for use in Unicorn"
|
21
14
|
|
22
|
-
def self.source_root
|
23
|
-
File.expand_path('../../../..', __FILE__)
|
24
|
-
end
|
25
|
-
|
26
15
|
def set_destination_root
|
27
|
-
|
28
|
-
self.destination_root = @application_root
|
16
|
+
self.destination_root = application_root.to_s
|
29
17
|
end
|
30
18
|
|
31
19
|
def download
|
32
|
-
empty_directory
|
20
|
+
empty_directory "."
|
33
21
|
inside application_root do
|
34
22
|
if options[:git]
|
35
23
|
run "git clone #{options[:git]} ."
|
@@ -40,14 +28,13 @@ module Rsm
|
|
40
28
|
fetch_temporary_archive(name, options[:tbz2], :bz2)
|
41
29
|
unpack_compessed_archive(name, :bz2)
|
42
30
|
else
|
43
|
-
say "No source URI specified
|
44
|
-
exit 1
|
31
|
+
say "No source URI specified - skip download"
|
45
32
|
end
|
46
33
|
end
|
47
34
|
end
|
48
35
|
|
49
36
|
def permissions
|
50
|
-
inside
|
37
|
+
inside "." do
|
51
38
|
empty_directory "log"
|
52
39
|
empty_directory "tmp"
|
53
40
|
run "chown #{options[:user]}:#{options[:group]} -R ."
|
@@ -57,7 +44,7 @@ module Rsm
|
|
57
44
|
|
58
45
|
def unicorn_config
|
59
46
|
@worker_processes = options[:worker_processes]
|
60
|
-
template "
|
47
|
+
template "unicorn.rb.erb", "config/unicorn.rb"
|
61
48
|
end
|
62
49
|
end
|
63
50
|
end
|
data/lib/rsm/runner.rb
CHANGED
@@ -2,14 +2,9 @@ module Rsm
|
|
2
2
|
class Runner < Thor
|
3
3
|
include Thor::Actions
|
4
4
|
|
5
|
-
def self.source_root
|
6
|
-
File.expand_path("../..", __FILE__)
|
7
|
-
end
|
8
|
-
|
9
|
-
class_option :apps_root, :defualt => "/var/www", :aliases => "-r", :desc => "Rails apps root (default: /var/www)"
|
10
|
-
|
11
5
|
register Rsm::Install::Nginx, "install:nginx", "install:nginx NAME", "Install Nginx config"
|
12
6
|
register Rsm::Install::Rails, "install:rails", "install:rails NAME", "Install Rails application"
|
7
|
+
register Rsm::Unicorn, "unicorn", "unicorn NAME", "Run Unicorn server"
|
13
8
|
|
14
9
|
desc "install NAME", "Install Nginx config and Rails application"
|
15
10
|
def install(name)
|
@@ -17,16 +12,10 @@ module Rsm
|
|
17
12
|
invoke "install:rails"
|
18
13
|
end
|
19
14
|
|
20
|
-
desc "
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
if rvmrc.exist?
|
25
|
-
ruby_cmd = File.new(rvmrc).readline.strip + " exec"
|
26
|
-
else
|
27
|
-
ruby_cmd = "#{Thor::Util.ruby_command} -S"
|
28
|
-
end
|
29
|
-
run "#{ruby_cmd} unicorn_rails -D -c #{app_root.join("config", "unicorn.rb")}"
|
15
|
+
desc "version", "RSM gem version"
|
16
|
+
def version
|
17
|
+
require 'rsm/version'
|
18
|
+
say "RSM version #{Rsm::VERSION}"
|
30
19
|
end
|
31
20
|
end
|
32
21
|
end
|
data/lib/rsm/unicorn.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Rsm
|
2
|
+
class Unicorn < Base
|
3
|
+
def unicorn_rails
|
4
|
+
rvmrc = application_root.join(".rvmrc")
|
5
|
+
if rvmrc.exist?
|
6
|
+
ruby_cmd = File.new(rvmrc).readline.strip + " exec"
|
7
|
+
else
|
8
|
+
ruby_cmd = "#{Thor::Util.ruby_command} -S"
|
9
|
+
end
|
10
|
+
run "#{ruby_cmd} unicorn_rails -D -E production -c #{application_root.join("config", "unicorn.rb")}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/rsm.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
upstream <%= name %>_server {
|
2
|
-
server unix
|
2
|
+
server unix:<%= application_root %>/tmp/sockets/unicorn.sock fail_timeout=0; # Местоположение сокета должно совпадать с настройками файла config/unicorn.rb от корня вашего приложения.
|
3
3
|
}
|
4
4
|
|
5
5
|
server {
|
@@ -8,12 +8,12 @@ server {
|
|
8
8
|
|
9
9
|
client_max_body_size 1G; # Максимальный размер тела запроса (а простым языком - ограничение на размер заливаемого на сервер файла).
|
10
10
|
keepalive_timeout 5;
|
11
|
-
root
|
11
|
+
root <%= application_root %>/public; # Эта строка всегда должна указывать в директорию public Rails приложения. А current там потому что деплой происходит через Capistrano
|
12
12
|
|
13
13
|
try_files $uri/index.html $uri.html $uri @<%= name %>; # Имя переменной не важно - главное, чтобы в блоке location ниже было аналогичное
|
14
14
|
|
15
|
-
access_log
|
16
|
-
error_log
|
15
|
+
access_log <%= application_root %>/log/access.log;
|
16
|
+
error_log <%= application_root %>/log/error.log;
|
17
17
|
|
18
18
|
location @<%= name %> {
|
19
19
|
proxy_pass http://<%= name %>_server; # Часть после http:// должна полностью соответствовать имени в блоке upstream выше.
|
@@ -24,7 +24,7 @@ server {
|
|
24
24
|
|
25
25
|
error_page 500 502 503 504 /500.html;
|
26
26
|
location = /500.html {
|
27
|
-
root
|
27
|
+
root <%= application_root %>/public;
|
28
28
|
}
|
29
29
|
}
|
30
30
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 62196319
|
5
5
|
prerelease: 4
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
9
|
- beta
|
10
|
-
-
|
11
|
-
version: 0.1.
|
10
|
+
- 2
|
11
|
+
version: 0.1.beta2
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Oleksandr Ulianytskyi
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-08-
|
19
|
+
date: 2011-08-31 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: thor
|
@@ -55,12 +55,14 @@ files:
|
|
55
55
|
- bin/rsm
|
56
56
|
- lib/rsm.rb
|
57
57
|
- lib/rsm/actions.rb
|
58
|
+
- lib/rsm/base.rb
|
58
59
|
- lib/rsm/install/nginx.rb
|
59
60
|
- lib/rsm/install/rails.rb
|
60
61
|
- lib/rsm/runner.rb
|
62
|
+
- lib/rsm/unicorn.rb
|
61
63
|
- lib/rsm/version.rb
|
62
64
|
- rsm.gemspec
|
63
|
-
- templates/nginx-
|
65
|
+
- templates/nginx-unicorn.conf.erb
|
64
66
|
- templates/unicorn.rb.erb
|
65
67
|
homepage: https://github.com/asux/rsm
|
66
68
|
licenses:
|