rsm 0.1.alpha1 → 0.1.alpha2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -0,0 +1,15 @@
1
+ 0.1.alpha2 (2011-08-28)
2
+ =======================
3
+ * Splitted Nginx and Rails application tasks
4
+ * Using relative paths
5
+ * Fixed application root in unicorn template
6
+
7
+ 0.1.alpha1 (2011-08-28)
8
+ =======================
9
+ * Created tasks:
10
+ - create Nginx virtual server config from template
11
+ - enable Nginx virtual server config
12
+ - clone or download and unpack Rails application from TGZ or TBZ2 archive
13
+ - set permission for Rails application
14
+ - create Unicorn config from template
15
+ - run unicorn server
data/README.md CHANGED
@@ -1,11 +1,43 @@
1
1
  RSM -- Rails Server Manger
2
2
  ==========================
3
3
 
4
+ RSM created for make easier some actons on server like:
5
+ - generation config file
6
+ - manipulation of files
7
+ - running commands
8
+ and other Rails application tasks.
9
+
10
+ This version can:
11
+ - create Nginx virtual server config from template
12
+ - enable Nginx virtual server config
13
+ - clone or download and unpack Rails application from TGZ or TBZ2 archive
14
+ - set permission for Rails application
15
+ - create Unicorn config from template
16
+ - run unicorn server
17
+
18
+ Homepage
19
+ --------
20
+
21
+ Project located at GitHub: https://github.com/asux/rsm
22
+
23
+ Author
24
+ ------
25
+
26
+ Created by Oleksandr (asux) Ulianytskyi
27
+
28
+ License
29
+ -------
30
+
31
+ Source code has MIT license
32
+
4
33
  Installation
5
34
  ------------
6
35
 
7
- Nginx
8
- -----
36
+ Install from RubyGems
37
+ # gem install rsm --pre # usually most operations requires super-user access
38
+
39
+ Documentation
40
+ -------------
9
41
 
10
- Unicorn
11
- -------
42
+ For detailed documentation read YARD docs at Rubydoc - http://rubydoc.info/gems/rsm/frames
43
+ or generated from GitHub - http://rubydoc.info/github/asux/rsm/master/frames
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.alpha1
1
+ 0.1.alpha2
data/bin/rsm CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib') unless $LOAD_PATH.include?(File.dirname(__FILE__) + '/../lib')
2
3
  require 'rubygems'
3
4
  require 'rsm'
4
5
 
@@ -0,0 +1,25 @@
1
+ module Rsm
2
+ module Actions
3
+ # relative downloaded filename
4
+ def downloaded_file(compressor)
5
+ "#{name}.tar.#{compressor}"
6
+ end
7
+
8
+ # download archive form +uri+ and temporary save it
9
+ # *compressor*:: +:gz+ or +:bz2+
10
+ def fetch_temporary_archive(uri, compressor)
11
+ get uri, downloaded_file(compressor)
12
+ end
13
+
14
+ # unpack temporary archive file
15
+ # *compressor*:: +:gz+ or +:bz2+
16
+ def unpack_compressed_archive(compressor)
17
+ tar_opts = {:gz => '-z', :bz2 => '-j'}
18
+ opt = tar_opts[compressor]
19
+ inside destination_root do
20
+ run "tar #{opt} -xf #{downloaded_file(compressor)}"
21
+ remove_file downloaded_file(compressor)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,40 @@
1
+ module Rsm
2
+ module Install
3
+ class Nginx < Thor::Group
4
+ include Thor::Actions
5
+
6
+ attr_reader :domain
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
+ def self.source_root
14
+ File.expand_path('../../../..', __FILE__)
15
+ end
16
+
17
+ def set_destination_root
18
+ self.destination_root = options[:nginx_root]
19
+ end
20
+
21
+ def nginx_conf_include
22
+ include_str = "include sites-enabled.d/*.conf;\n\t"
23
+ unless File.read("#{options[:nginx_root]}/nginx.conf").include?(include_str)
24
+ inject_into_file "nginx.conf", include_str, :before => "server {"
25
+ end
26
+ end
27
+
28
+ def nginx_config
29
+ @domain = options[:domain]
30
+ @domain = `hostname` unless @domain
31
+ template "templates/nginx-vhost.conf.erb", "sites-available.d/#{name}.conf"
32
+ end
33
+
34
+ def enable_nginx_site
35
+ link_file "#{options[:nginx_root]}/sites-available.d/#{name}.conf", "sites-enabled.d/#{name}.conf"
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,62 @@
1
+ module Rsm
2
+ module Install
3
+ class Rails < Thor::Group
4
+ include Thor::Actions
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)"
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
+ @application_root = "#{options[:apps_root]}/#{name}"
28
+ self.destination_root = @application_root
29
+ end
30
+
31
+ def download
32
+ empty_directory "."
33
+ if options[:git]
34
+ run "git clone #{options[:git]} #{application_root}"
35
+ elsif options[:tgz]
36
+ fetch_temporary_archive(options[:tgz], :gz)
37
+ unpack_compressed_archive(:gz)
38
+ elsif options[:tbz2]
39
+ fetch_temporary_archive(options[:tbz2], :bz2)
40
+ unpack_compessed_archive(:bz2)
41
+ else
42
+ say "No source URI specified. Use --git, --tgz or --tbz2 option with URI passed"
43
+ exit 1
44
+ end
45
+ end
46
+
47
+ def permissions
48
+ inside destination_root do
49
+ empty_directory "log"
50
+ empty_directory "tmp"
51
+ run "chown #{options[:user]}:#{options[:group]} -R ."
52
+ run "chmod 755 log tmp"
53
+ end
54
+ end
55
+
56
+ def unicorn_config
57
+ @worker_processes = options[:worker_processes]
58
+ template "templates/unicorn.rb.erb", "config/unicorn.rb"
59
+ end
60
+ end
61
+ end
62
+ end
data/lib/rsm/install.rb CHANGED
@@ -1,75 +1,2 @@
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
1
+ require 'rsm/install/nginx'
2
+ require 'rsm/install/rails'
data/lib/rsm/runner.rb CHANGED
@@ -1,18 +1,22 @@
1
- require "pathname"
2
- require "thor"
3
-
4
1
  module Rsm
5
2
  class Runner < Thor
6
3
  include Thor::Actions
7
4
 
8
- register Rsm::Install, "install", "install NAME", "Install Rails application"
9
-
10
5
  def self.source_root
11
6
  File.expand_path("../..", __FILE__)
12
7
  end
13
8
 
14
9
  class_option :apps_root, :defualt => "/var/www", :aliases => "-r", :desc => "Rails apps root (default: /var/www)"
15
10
 
11
+ register Rsm::Install::Nginx, "install:nginx", "install:nginx NAME", "Install Nginx config"
12
+ register Rsm::Install::Rails, "install:rails", "install:rails NAME", "Install Rails application"
13
+
14
+ desc "install NAME", "Install Nginx config and Rails application"
15
+ def install(name)
16
+ invoke "install:nginx"
17
+ invoke "install:rails"
18
+ end
19
+
16
20
  desc "unicorn NAME", "Run Unicorn server"
17
21
  def unicorn(name)
18
22
  app_root = Pathname.new("#{options[:apps_root]}/#{name}")
@@ -20,7 +24,7 @@ module Rsm
20
24
  if rvmrc.exist?
21
25
  ruby_cmd = File.new(rvmrc).readline.strip + " exec"
22
26
  else
23
- ruby_cmd = "ruby -S"
27
+ ruby_cmd = "#{Thor::Util.ruby_command} -S"
24
28
  end
25
29
  run "#{ruby_cmd} unicorn_rails -D -c #{app_root.join("config", "unicorn.rb")}"
26
30
  end
@@ -0,0 +1,3 @@
1
+ module Rsm
2
+ VERSION = File.read(File.expand_path('../../../VERSION', __FILE__))
3
+ end
data/lib/rsm.rb CHANGED
@@ -1,2 +1,7 @@
1
+ require 'pathname'
2
+ require 'thor'
3
+ require 'thor/group'
4
+ require 'thor/util'
5
+ require 'rsm/actions'
1
6
  require 'rsm/install'
2
7
  require 'rsm/runner'
data/rsm.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ require File.expand_path('lib/rsm/version', File.dirname(__FILE__))
2
+
1
3
  Gem::Specification.new do |s|
2
4
  s.name = 'rsm'
3
5
  s.summary = 'Rails server manager'
@@ -5,12 +7,12 @@ Gem::Specification.new do |s|
5
7
  s.homepage = 'https://github.com/asux/rsm'
6
8
  s.email = 'a.ulyanitsky@gmail.com'
7
9
  s.author = 'Oleksandr Ulianytskyi'
8
- s.version = File.read('VERSION')
10
+ s.version = Rsm::VERSION
9
11
  s.files = `git ls-files`.split("\n")
10
- s.date = File.mtime('VERSION')
12
+ s.date = File.mtime(File.expand_path('VERSION', File.dirname(__FILE__)))
11
13
  s.executables = Dir['bin/*'].map{|f| File.basename(f)}
12
14
  s.default_executable = 'rsm'
13
- s.extra_rdoc_files = ['README.md', 'CHANGES.md']
15
+ s.extra_rdoc_files = ['README.md', 'CHANGES.md', 'VERSION']
14
16
  s.license = 'MIT'
15
17
  s.rdoc_options << '--main' << 'README.md' << '--line-numbers'
16
18
  s.requirements << 'A coreutils installed'
@@ -21,24 +21,24 @@ worker_processes <%= worker_processes %>
21
21
 
22
22
  # Help ensure your application will always spawn in the symlinked
23
23
  # "current" directory that Capistrano sets up.
24
- working_directory "/var/www/<%= name %>/" # available in 0.94.0+
24
+ working_directory "<%= application_root %>/" # available in 0.94.0+
25
25
 
26
26
  # listen on both a Unix domain socket and a TCP port,
27
27
  # we use a shorter backlog for quicker failover when busy
28
- listen "/var/www/<%= name %>/tmp/sockets/unicorn.sock", :backlog => 64
28
+ listen "<%= application_root %>/tmp/sockets/unicorn.sock", :backlog => 64
29
29
  #listen "127.0.0.1:8080", :tcp_nopush => true
30
30
 
31
31
  # nuke workers after 30 seconds instead of 60 seconds (the default)
32
32
  timeout 30
33
33
 
34
34
  # feel free to point this anywhere accessible on the filesystem
35
- pid "/var/www/<%= name %>/tmp/pids/unicorn.pid"
35
+ pid "<%= application_root %>/tmp/pids/unicorn.pid"
36
36
 
37
37
  # By default, the Unicorn logger will write to stderr.
38
38
  # Additionally, ome applications/frameworks log to stderr or stdout,
39
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"
40
+ stderr_path "<%= application_root %>/log/unicorn.stderr.log"
41
+ stdout_path "<%= application_root %>/log/unicorn.stdout.log"
42
42
 
43
43
  # combine REE with "preload_app true" for memory savings
44
44
  # http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
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: 592303015
4
+ hash: 592303009
5
5
  prerelease: 4
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
9
  - alpha
10
- - 1
11
- version: 0.1.alpha1
10
+ - 2
11
+ version: 0.1.alpha2
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-28 00:00:00 Z
19
+ date: 2011-08-29 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: thor
@@ -41,6 +41,7 @@ extensions: []
41
41
  extra_rdoc_files:
42
42
  - README.md
43
43
  - CHANGES.md
44
+ - VERSION
44
45
  files:
45
46
  - .gitignore
46
47
  - .rvmrc
@@ -48,10 +49,13 @@ files:
48
49
  - README.md
49
50
  - VERSION
50
51
  - bin/rsm
51
- - config/unicorn.rb
52
52
  - lib/rsm.rb
53
+ - lib/rsm/actions.rb
53
54
  - lib/rsm/install.rb
55
+ - lib/rsm/install/nginx.rb
56
+ - lib/rsm/install/rails.rb
54
57
  - lib/rsm/runner.rb
58
+ - lib/rsm/version.rb
55
59
  - rsm.gemspec
56
60
  - templates/nginx-vhost.conf.erb
57
61
  - templates/unicorn.rb.erb
data/config/unicorn.rb DELETED
File without changes