rsm 0.1.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rvmrc +1 -0
- data/CHANGES.md +0 -0
- data/README.md +11 -0
- data/VERSION +1 -0
- data/bin/rsm +7 -0
- data/config/unicorn.rb +0 -0
- data/lib/rsm/install.rb +75 -0
- data/lib/rsm/runner.rb +28 -0
- data/lib/rsm.rb +2 -0
- data/rsm.gemspec +21 -0
- data/templates/nginx-vhost.conf.erb +30 -0
- data/templates/unicorn.rb.erb +94 -0
- metadata +99 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.8.7
|
data/CHANGES.md
ADDED
File without changes
|
data/README.md
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.alpha1
|
data/bin/rsm
ADDED
data/config/unicorn.rb
ADDED
File without changes
|
data/lib/rsm/install.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'thor/group'
|
3
|
+
|
4
|
+
module Rsm
|
5
|
+
class Install < Thor::Group
|
6
|
+
include Thor::Actions
|
7
|
+
|
8
|
+
argument :name
|
9
|
+
|
10
|
+
class_option :nginx_root, :default => "/etc/nginx", :aliases => "-n", :desc => "Nginx configuration root"
|
11
|
+
class_option :domain, :aliases => "-d", :desc => "Server's domain"
|
12
|
+
|
13
|
+
class_option :user, :aliases => "-u", :default => "git", :desc => "Owners's user"
|
14
|
+
class_option :group, :aliases => "-g", :default => "git", :desc => "Owners's group"
|
15
|
+
|
16
|
+
class_option :git, :desc => "Git repository URL"
|
17
|
+
class_option :tgz, :desc => "Install from TGZ (tar.gz)"
|
18
|
+
class_option :tbz2, :desc => "Install from TBZ2 (tar.bz2)"
|
19
|
+
|
20
|
+
class_option :worker_processes, :type => :numeric, :default => 2, :aliases => "-w", :desc => "Worker processes for use in Unicorn"
|
21
|
+
|
22
|
+
def self.source_root
|
23
|
+
File.expand_path('../../..', __FILE__)
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_destination_root
|
27
|
+
destination_root = "#{options[:apps_root]}/#{name}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def nginx_conf_include
|
31
|
+
nginx_conf = "#{options[:nginx_root]}/nginx.conf"
|
32
|
+
include_str = "include sites-enabled.d/*.conf;\n"
|
33
|
+
unless File.read(nginx_conf).include?(include_str)
|
34
|
+
insert_into_file nginx_conf, include_str, :before => "server {\n"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def nginx_config
|
39
|
+
domain = options[:domain]
|
40
|
+
domain = `hostname` unless domain
|
41
|
+
template "templates/nginx-vhost.conf.erb", "#{options[:nginx_root]}/sites-available.d/#{name}.conf"
|
42
|
+
end
|
43
|
+
|
44
|
+
def enable_nginx_site
|
45
|
+
create_link "#{options[:nginx_root]}/sites-enabled.d/#{name}.conf", "#{options[:nginx_root]}/sites-available.d/#{name}.conf"
|
46
|
+
end
|
47
|
+
|
48
|
+
def download
|
49
|
+
app_root = "#{options[:apps_root]}/#{name}"
|
50
|
+
if options[:git]
|
51
|
+
run "git clone #{options[:git]} #{apps_root}"
|
52
|
+
elsif options[:tgz]
|
53
|
+
get options[:tgz], "/tmp/#{name}.tgz"
|
54
|
+
run "tar -xzf /tmp/#{name}.tgz -C #{options[:apps_root]}"
|
55
|
+
elsif options[:tbz2]
|
56
|
+
get options[:tbz2], "/tmp/#{name}.tbz2"
|
57
|
+
run "tar -xjf /tmp/#{name}.tbz2 -C #{options[:apps_root]}"
|
58
|
+
else
|
59
|
+
say "No source specified. Use --git, --tgz or --tbz2 option"
|
60
|
+
exit 1
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def permissions
|
65
|
+
app_root = "#{options[:apps_root]}/#{name}"
|
66
|
+
run "chown #{opions[:user]}:#{options[:group]} -R #{apps_root}"
|
67
|
+
run "chmod 755 -R #{apps_root}/{log,tmp}"
|
68
|
+
end
|
69
|
+
|
70
|
+
def unicorn_config
|
71
|
+
worker_processes = options[:worker_processes]
|
72
|
+
template "templates/unicorn.rb.erb", "config/unicorn.rb"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/rsm/runner.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "pathname"
|
2
|
+
require "thor"
|
3
|
+
|
4
|
+
module Rsm
|
5
|
+
class Runner < Thor
|
6
|
+
include Thor::Actions
|
7
|
+
|
8
|
+
register Rsm::Install, "install", "install NAME", "Install Rails application"
|
9
|
+
|
10
|
+
def self.source_root
|
11
|
+
File.expand_path("../..", __FILE__)
|
12
|
+
end
|
13
|
+
|
14
|
+
class_option :apps_root, :defualt => "/var/www", :aliases => "-r", :desc => "Rails apps root (default: /var/www)"
|
15
|
+
|
16
|
+
desc "unicorn NAME", "Run Unicorn server"
|
17
|
+
def unicorn(name)
|
18
|
+
app_root = Pathname.new("#{options[:apps_root]}/#{name}")
|
19
|
+
rvmrc = app_root.join(".rvmrc")
|
20
|
+
if rvmrc.exist?
|
21
|
+
ruby_cmd = File.new(rvmrc).readline.strip + " exec"
|
22
|
+
else
|
23
|
+
ruby_cmd = "ruby -S"
|
24
|
+
end
|
25
|
+
run "#{ruby_cmd} unicorn_rails -D -c #{app_root.join("config", "unicorn.rb")}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/rsm.rb
ADDED
data/rsm.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'rsm'
|
3
|
+
s.summary = 'Rails server manager'
|
4
|
+
s.description = 'Thor tasks for rapid deployment new rails apps on server'
|
5
|
+
s.homepage = 'https://github.com/asux/rsm'
|
6
|
+
s.email = 'a.ulyanitsky@gmail.com'
|
7
|
+
s.author = 'Oleksandr Ulianytskyi'
|
8
|
+
s.version = File.read('VERSION')
|
9
|
+
s.files = `git ls-files`.split("\n")
|
10
|
+
s.date = File.mtime('VERSION')
|
11
|
+
s.executables = Dir['bin/*'].map{|f| File.basename(f)}
|
12
|
+
s.default_executable = 'rsm'
|
13
|
+
s.extra_rdoc_files = ['README.md', 'CHANGES.md']
|
14
|
+
s.license = 'MIT'
|
15
|
+
s.rdoc_options << '--main' << 'README.md' << '--line-numbers'
|
16
|
+
s.requirements << 'A coreutils installed'
|
17
|
+
s.requirements << 'A Git installed'
|
18
|
+
s.requirements << 'A Nginx installed'
|
19
|
+
s.requirements << 'You must have super-user access'
|
20
|
+
s.add_dependency 'thor'
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
upstream <%= name %>_server {
|
2
|
+
server unix:/var/www/<%= name %>/tmp/sockets/unicorn.sock fail_timeout=0; # Местоположение сокета должно совпадать с настройками файла config/unicorn.rb от корня вашего приложения.
|
3
|
+
}
|
4
|
+
|
5
|
+
server {
|
6
|
+
listen 80; # Опять же, если на одном и том же ip находится несколько серверов, то эта строка будет выглядеть как-то так myapp.mydomain.ru:80
|
7
|
+
server_name <%= name %>.<%= domain %>; # Имя сервера
|
8
|
+
|
9
|
+
client_max_body_size 1G; # Максимальный размер тела запроса (а простым языком - ограничение на размер заливаемого на сервер файла).
|
10
|
+
keepalive_timeout 5;
|
11
|
+
root /var/www/<%= name %>/public; # Эта строка всегда должна указывать в директорию public Rails приложения. А current там потому что деплой происходит через Capistrano
|
12
|
+
|
13
|
+
try_files $uri/index.html $uri.html $uri @<%= name %>; # Имя переменной не важно - главное, чтобы в блоке location ниже было аналогичное
|
14
|
+
|
15
|
+
access_log /var/www/<%= name %>/log/access.log;
|
16
|
+
error_log /var/www/<%= name %>/log/error.log;
|
17
|
+
|
18
|
+
location @<%= name %> {
|
19
|
+
proxy_pass http://<%= name %>_server; # Часть после http:// должна полностью соответствовать имени в блоке upstream выше.
|
20
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
21
|
+
proxy_set_header Host $http_host;
|
22
|
+
proxy_redirect off;
|
23
|
+
}
|
24
|
+
|
25
|
+
error_page 500 502 503 504 /500.html;
|
26
|
+
location = /500.html {
|
27
|
+
root /var/www/<%= name %>/public;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# Sample verbose configuration file for Unicorn (not Rack)
|
2
|
+
#
|
3
|
+
# This configuration file documents many features of Unicorn
|
4
|
+
# that may not be needed for some applications. See
|
5
|
+
# http://unicorn.bogomips.org/examples/unicorn.conf.minimal.rb
|
6
|
+
# for a much simpler configuration file.
|
7
|
+
#
|
8
|
+
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
|
9
|
+
# documentation.
|
10
|
+
|
11
|
+
# Use at least one worker per core if you're on a dedicated server,
|
12
|
+
# more will usually help for _short_ waits on databases/caches.
|
13
|
+
worker_processes <%= worker_processes %>
|
14
|
+
|
15
|
+
# Since Unicorn is never exposed to outside clients, it does not need to
|
16
|
+
# run on the standard HTTP port (80), there is no reason to start Unicorn
|
17
|
+
# as root unless it's from system init scripts.
|
18
|
+
# If running the master process as root and the workers as an unprivileged
|
19
|
+
# user, do this to switch euid/egid in the workers (also chowns logs):
|
20
|
+
# user "unprivileged_user", "unprivileged_group"
|
21
|
+
|
22
|
+
# Help ensure your application will always spawn in the symlinked
|
23
|
+
# "current" directory that Capistrano sets up.
|
24
|
+
working_directory "/var/www/<%= name %>/" # available in 0.94.0+
|
25
|
+
|
26
|
+
# listen on both a Unix domain socket and a TCP port,
|
27
|
+
# we use a shorter backlog for quicker failover when busy
|
28
|
+
listen "/var/www/<%= name %>/tmp/sockets/unicorn.sock", :backlog => 64
|
29
|
+
#listen "127.0.0.1:8080", :tcp_nopush => true
|
30
|
+
|
31
|
+
# nuke workers after 30 seconds instead of 60 seconds (the default)
|
32
|
+
timeout 30
|
33
|
+
|
34
|
+
# feel free to point this anywhere accessible on the filesystem
|
35
|
+
pid "/var/www/<%= name %>/tmp/pids/unicorn.pid"
|
36
|
+
|
37
|
+
# By default, the Unicorn logger will write to stderr.
|
38
|
+
# Additionally, ome applications/frameworks log to stderr or stdout,
|
39
|
+
# so prevent them from going to /dev/null when daemonized here:
|
40
|
+
stderr_path "/var/www/<%= name %>/log/unicorn.stderr.log"
|
41
|
+
stdout_path "/var/www/<%= name %>/log/unicorn.stdout.log"
|
42
|
+
|
43
|
+
# combine REE with "preload_app true" for memory savings
|
44
|
+
# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
|
45
|
+
preload_app true
|
46
|
+
GC.respond_to?(:copy_on_write_friendly=) and
|
47
|
+
GC.copy_on_write_friendly = true
|
48
|
+
|
49
|
+
before_fork do |server, worker|
|
50
|
+
# the following is highly recomended for Rails + "preload_app true"
|
51
|
+
# as there's no need for the master process to hold a connection
|
52
|
+
defined?(ActiveRecord::Base) and
|
53
|
+
ActiveRecord::Base.connection.disconnect!
|
54
|
+
|
55
|
+
# The following is only recommended for memory/DB-constrained
|
56
|
+
# installations. It is not needed if your system can house
|
57
|
+
# twice as many worker_processes as you have configured.
|
58
|
+
#
|
59
|
+
# # This allows a new master process to incrementally
|
60
|
+
# # phase out the old master process with SIGTTOU to avoid a
|
61
|
+
# # thundering herd (especially in the "preload_app false" case)
|
62
|
+
# # when doing a transparent upgrade. The last worker spawned
|
63
|
+
# # will then kill off the old master process with a SIGQUIT.
|
64
|
+
# old_pid = "#{server.config[:pid]}.oldbin"
|
65
|
+
# if old_pid != server.pid
|
66
|
+
# begin
|
67
|
+
# sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
|
68
|
+
# Process.kill(sig, File.read(old_pid).to_i)
|
69
|
+
# rescue Errno::ENOENT, Errno::ESRCH
|
70
|
+
# end
|
71
|
+
# end
|
72
|
+
#
|
73
|
+
# Throttle the master from forking too quickly by sleeping. Due
|
74
|
+
# to the implementation of standard Unix signal handlers, this
|
75
|
+
# helps (but does not completely) prevent identical, repeated signals
|
76
|
+
# from being lost when the receiving process is busy.
|
77
|
+
# sleep 1
|
78
|
+
end
|
79
|
+
|
80
|
+
after_fork do |server, worker|
|
81
|
+
# per-process listener ports for debugging/admin/migrations
|
82
|
+
# addr = "127.0.0.1:#{9293 + worker.nr}"
|
83
|
+
# server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
|
84
|
+
|
85
|
+
# the following is *required* for Rails + "preload_app true",
|
86
|
+
defined?(ActiveRecord::Base) and
|
87
|
+
ActiveRecord::Base.establish_connection
|
88
|
+
|
89
|
+
# if preload_app is true, then you may also want to check and
|
90
|
+
# restart any other shared sockets/descriptors such as Memcached,
|
91
|
+
# and Redis. TokyoCabinet file handles are safe to reuse
|
92
|
+
# between any number of forked children (assuming your kernel
|
93
|
+
# correctly implements pread()/pwrite() system calls)
|
94
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rsm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 592303015
|
5
|
+
prerelease: 4
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- alpha
|
10
|
+
- 1
|
11
|
+
version: 0.1.alpha1
|
12
|
+
platform: ruby
|
13
|
+
authors:
|
14
|
+
- Oleksandr Ulianytskyi
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-08-28 00:00:00 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: thor
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Thor tasks for rapid deployment new rails apps on server
|
36
|
+
email: a.ulyanitsky@gmail.com
|
37
|
+
executables:
|
38
|
+
- rsm
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.md
|
43
|
+
- CHANGES.md
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- .rvmrc
|
47
|
+
- CHANGES.md
|
48
|
+
- README.md
|
49
|
+
- VERSION
|
50
|
+
- bin/rsm
|
51
|
+
- config/unicorn.rb
|
52
|
+
- lib/rsm.rb
|
53
|
+
- lib/rsm/install.rb
|
54
|
+
- lib/rsm/runner.rb
|
55
|
+
- rsm.gemspec
|
56
|
+
- templates/nginx-vhost.conf.erb
|
57
|
+
- templates/unicorn.rb.erb
|
58
|
+
homepage: https://github.com/asux/rsm
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --main
|
64
|
+
- README.md
|
65
|
+
- --line-numbers
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 25
|
83
|
+
segments:
|
84
|
+
- 1
|
85
|
+
- 3
|
86
|
+
- 1
|
87
|
+
version: 1.3.1
|
88
|
+
requirements:
|
89
|
+
- A coreutils installed
|
90
|
+
- A Git installed
|
91
|
+
- A Nginx installed
|
92
|
+
- You must have super-user access
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.8.6
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Rails server manager
|
98
|
+
test_files: []
|
99
|
+
|