unicorn_deployer 0.0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +17 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/javascripts/unicorn_deployer/application.js +16 -0
  6. data/app/assets/stylesheets/unicorn_deployer/application.css +13 -0
  7. data/app/controllers/unicorn_deployer/application_controller.rb +4 -0
  8. data/app/helpers/unicorn_deployer/application_helper.rb +4 -0
  9. data/app/views/layouts/unicorn_deployer/application.html.erb +14 -0
  10. data/config/environment.rb +0 -0
  11. data/config/nginx.conf +27 -0
  12. data/config/routes.rb +2 -0
  13. data/config/unicorn.rb +10 -0
  14. data/config/unicorn_init.sh +85 -0
  15. data/lib/generators/deployer/USAGE +8 -0
  16. data/lib/generators/deployer/deployer_generator.rb +29 -0
  17. data/lib/generators/deployer/templates/deploy.rb +37 -0
  18. data/lib/generators/deployer/templates/nginx.conf.erb +27 -0
  19. data/lib/generators/deployer/templates/unicorn.rb.erb +10 -0
  20. data/lib/generators/deployer/templates/unicorn_init.sh.erb +85 -0
  21. data/lib/tasks/unicorn_deployer_tasks.rake +4 -0
  22. data/lib/unicorn_deployer.rb +4 -0
  23. data/lib/unicorn_deployer/engine.rb +5 -0
  24. data/lib/unicorn_deployer/version.rb +3 -0
  25. data/test/dummy/README.rdoc +28 -0
  26. data/test/dummy/Rakefile +6 -0
  27. data/test/dummy/app/assets/javascripts/application.js +16 -0
  28. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  29. data/test/dummy/app/controllers/application_controller.rb +5 -0
  30. data/test/dummy/app/helpers/application_helper.rb +2 -0
  31. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  32. data/test/dummy/bin/bundle +3 -0
  33. data/test/dummy/bin/rails +4 -0
  34. data/test/dummy/bin/rake +4 -0
  35. data/test/dummy/config.ru +4 -0
  36. data/test/dummy/config/application.rb +23 -0
  37. data/test/dummy/config/boot.rb +9 -0
  38. data/test/dummy/config/database.yml +25 -0
  39. data/test/dummy/config/environment.rb +5 -0
  40. data/test/dummy/config/environments/development.rb +27 -0
  41. data/test/dummy/config/environments/production.rb +80 -0
  42. data/test/dummy/config/environments/test.rb +36 -0
  43. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  44. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  45. data/test/dummy/config/initializers/inflections.rb +16 -0
  46. data/test/dummy/config/initializers/mime_types.rb +5 -0
  47. data/test/dummy/config/initializers/secret_token.rb +12 -0
  48. data/test/dummy/config/initializers/session_store.rb +3 -0
  49. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  50. data/test/dummy/config/locales/en.yml +23 -0
  51. data/test/dummy/config/routes.rb +4 -0
  52. data/test/dummy/public/404.html +27 -0
  53. data/test/dummy/public/422.html +26 -0
  54. data/test/dummy/public/500.html +26 -0
  55. data/test/dummy/public/favicon.ico +0 -0
  56. data/test/integration/navigation_test.rb +10 -0
  57. data/test/test_helper.rb +15 -0
  58. data/test/unicorn_deployer_test.rb +7 -0
  59. metadata +191 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e9d90d5dd280698c526b13b3aeb7384f8acf3736
4
+ data.tar.gz: 5808bfd37a8531793c6d276fa1d83c167aac240e
5
+ SHA512:
6
+ metadata.gz: 902b738caa123352e83453e5f12ff0591829dfb159f8b543f905ce1550f8492ec5fda56bfcf78bc197518f38e85f613b2f39ab63947c159d3e52bf9c650c7c1f
7
+ data.tar.gz: 801cb50e8941eeeee6b804fce168ddbe0df6ebf1313227a1b52d3d5a2277644269c2852c5539060610681f6bd0ae598dba71c72c7ed8f3d271bd716488418883
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ = UnicornDeployer
2
+
3
+ Installation:
4
+
5
+ gem 'unicorn_deployer'
6
+
7
+
8
+ rails g deployer application_name remote_user_name
9
+
10
+
11
+ There will come a conflict which you should accept with 'y'
12
+
13
+
14
+ Gem above will install capistrano and generator creates nginx site configuration and also generates unicorn configuration and also start up script for unicorn app server and capistrano deploy.rb files contains tasks for setting servers up which are called when you calls `cap deploy:setup`
15
+
16
+
17
+ This project uses MIT-LICENSE.
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'UnicornDeployer'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,16 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require turbolinks
16
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ module UnicornDeployer
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module UnicornDeployer
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>UnicornDeployer</title>
5
+ <%= stylesheet_link_tag "unicorn_deployer/application", media: "all" %>
6
+ <%= javascript_include_tag "unicorn_deployer/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
File without changes
@@ -0,0 +1,27 @@
1
+ upstream unicorn {
2
+ server unix:/tmp/unicorn.htc.sock fail_timeout=0;
3
+ }
4
+
5
+ server {
6
+ listen 80 default deferred;
7
+ # server_name example.com;
8
+ root /home/deploy/htc/current/public;
9
+
10
+ location ^~ /assets/ {
11
+ gzip_static on;
12
+ expires max;
13
+ add_header Cache-Control public;
14
+ }
15
+
16
+ try_files $uri/index.html $uri @unicorn;
17
+ location @unicorn {
18
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
19
+ proxy_set_header Host $http_host;
20
+ proxy_redirect off;
21
+ proxy_pass http://unicorn;
22
+ }
23
+
24
+ error_page 500 502 503 504 /500.html;
25
+ client_max_body_size 4G;
26
+ keepalive_timeout 10;
27
+ }
@@ -0,0 +1,2 @@
1
+ UnicornDeployer::Engine.routes.draw do
2
+ end
@@ -0,0 +1,10 @@
1
+
2
+ root = "/home/deploy/htc/current"
3
+ worker_processes 4
4
+ working_directory "/home/deploy/htc/current" # available in 0.94.0+
5
+ listen "/tmp/unicorn.htc.sock", :backlog => 64
6
+ listen 8080, :tcp_nopush => true
7
+ timeout 30
8
+ pid "/home/deploy/htc/current/tmp/pids/unicorn.pid"
9
+ stderr_path "/home/deploy/htc/current/log/unicorn.stderr.log"
10
+ stdout_path "/home/deploy/htc/current/log/unicorn.stdout.log"
@@ -0,0 +1,85 @@
1
+ #!/bin/sh
2
+ ### BEGIN INIT INFO
3
+ # Provides: unicorn
4
+ # Required-Start: $remote_fs $syslog
5
+ # Required-Stop: $remote_fs $syslog
6
+ # Default-Start: 2 3 4 5
7
+ # Default-Stop: 0 1 6
8
+ # Short-Description: Manage unicorn server
9
+ # Description: Start, stop, restart unicorn server for a specific application.
10
+ ### END INIT INFO
11
+ set -e
12
+
13
+ # Feel free to change any of the following variables for your app:
14
+ TIMEOUT=${TIMEOUT-60}
15
+
16
+ APP_ROOT=/home/deploy/htc/current
17
+ PID=$APP_ROOT/tmp/pids/unicorn.pid
18
+ CMD="cd $APP_ROOT ; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
19
+ AS_USER=deploy
20
+ set -u
21
+
22
+ OLD_PIN="$PID.oldbin"
23
+
24
+ sig () {
25
+ test -s "$PID" && kill -$1 `cat $PID`
26
+ }
27
+
28
+ oldsig () {
29
+ test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
30
+ }
31
+
32
+ run () {
33
+ if [ "$(id -un)" = "$AS_USER" ]; then
34
+ eval $1
35
+ else
36
+ su -c "$1" - $AS_USER
37
+ fi
38
+ }
39
+
40
+ case "$1" in
41
+ start)
42
+ sig 0 && echo >&2 "Already running" && exit 0
43
+ run "$CMD"
44
+ ;;
45
+ stop)
46
+ sig QUIT && exit 0
47
+ echo >&2 "Not running"
48
+ ;;
49
+ force-stop)
50
+ sig TERM && exit 0
51
+ echo >&2 "Not running"
52
+ ;;
53
+ restart|reload)
54
+ sig HUP && echo reloaded OK && exit 0
55
+ echo >&2 "Couldn't reload, starting '$CMD' instead"
56
+ run "$CMD"
57
+ ;;
58
+ upgrade)
59
+ if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
60
+ then
61
+ n=$TIMEOUT
62
+ while test -s $OLD_PIN && test $n -ge 0
63
+ do
64
+ printf '.' && sleep 1 && n=$(( $n - 1 ))
65
+ done
66
+ echo
67
+
68
+ if test $n -lt 0 && test -s $OLD_PIN
69
+ then
70
+ echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
71
+ exit 1
72
+ fi
73
+ exit 0
74
+ fi
75
+ echo >&2 "Couldn't upgrade, starting '$CMD' instead"
76
+ run "$CMD"
77
+ ;;
78
+ reopen-logs)
79
+ sig USR1
80
+ ;;
81
+ *)
82
+ echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
83
+ exit 1
84
+ ;;
85
+ esac
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate deployer Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,29 @@
1
+ class DeployerGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+ argument :user, :type => "string", :default => "deploy"
4
+
5
+ def generate_nginx_conf_file
6
+ @application = file_name
7
+ @user = user
8
+ template "nginx.conf.erb", "config/nginx.conf"
9
+ end
10
+
11
+ def generate_unicorn_rb_file
12
+ @application = file_name
13
+ @user = user
14
+ template "unicorn.rb.erb", "config/unicorn.rb"
15
+ end
16
+
17
+ def generate_unicorn_init_sh_file
18
+ @application = file_name
19
+ @user = user
20
+ template "unicorn_init.sh.erb", "config/unicorn_init.sh"
21
+ end
22
+
23
+ def generate_capistrano
24
+ capify!
25
+ @application = file_name
26
+ @user = user
27
+ template "deploy.rb", "config/deploy.rb"
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ require 'bundler/capistrano'
2
+ require 'rvm/capistrano'
3
+
4
+ set :application, '<%= @application %>'
5
+
6
+ set :scm, :git
7
+ set :repository, 'https://github.com/rubyonrails3/unicorn_deployer'
8
+ set :branch, :master
9
+
10
+ server 'localhost', :web, :app, :db, :primary => true
11
+
12
+ set :user, '<%= @user %>'
13
+ set :deploy_to, "/home/#{user}/#{application}"
14
+ set :use_sudo, false
15
+
16
+ set :deploy_via, :remote_cache
17
+
18
+ set :ssh_options, { :forward_agent => true }
19
+ default_run_options[:pty] = true
20
+
21
+
22
+ namespace :deploy do
23
+
24
+ %w[start stop restart].each do |command|
25
+ desc "#{command} unicorn server"
26
+ task command, :roles => :app, :except => { :no_release => true } do
27
+ run "/etc/init.d/unicorn_#{application} #{command}"
28
+ end
29
+ end
30
+
31
+ task :setup_config, :roles => :app do
32
+ run "#{sudo} ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
33
+ run "#{sudo} ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
34
+ end
35
+
36
+
37
+ end
@@ -0,0 +1,27 @@
1
+ upstream unicorn {
2
+ server unix:/tmp/unicorn.<%= @application %>.sock fail_timeout=0;
3
+ }
4
+
5
+ server {
6
+ listen 80 default deferred;
7
+ # server_name example.com;
8
+ root /home/<%= @user %>/<%= @application %>/current/public;
9
+
10
+ location ^~ /assets/ {
11
+ gzip_static on;
12
+ expires max;
13
+ add_header Cache-Control public;
14
+ }
15
+
16
+ try_files $uri/index.html $uri @unicorn;
17
+ location @unicorn {
18
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
19
+ proxy_set_header Host $http_host;
20
+ proxy_redirect off;
21
+ proxy_pass http://unicorn;
22
+ }
23
+
24
+ error_page 500 502 503 504 /500.html;
25
+ client_max_body_size 4G;
26
+ keepalive_timeout 10;
27
+ }
@@ -0,0 +1,10 @@
1
+ <% root = "/home/#{@user}/#{@application}/current" %>
2
+ <%= "root = \"#{root}\"" %>
3
+ worker_processes 4
4
+ working_directory "<%= root %>" # available in 0.94.0+
5
+ listen "/tmp/unicorn.<%= @application %>.sock", :backlog => 64
6
+ listen 8080, :tcp_nopush => true
7
+ timeout 30
8
+ pid "<%= root %>/tmp/pids/unicorn.pid"
9
+ stderr_path "<%= root %>/log/unicorn.stderr.log"
10
+ stdout_path "<%= root %>/log/unicorn.stdout.log"
@@ -0,0 +1,85 @@
1
+ #!/bin/sh
2
+ ### BEGIN INIT INFO
3
+ # Provides: unicorn
4
+ # Required-Start: $remote_fs $syslog
5
+ # Required-Stop: $remote_fs $syslog
6
+ # Default-Start: 2 3 4 5
7
+ # Default-Stop: 0 1 6
8
+ # Short-Description: Manage unicorn server
9
+ # Description: Start, stop, restart unicorn server for a specific application.
10
+ ### END INIT INFO
11
+ set -e
12
+
13
+ # Feel free to change any of the following variables for your app:
14
+ TIMEOUT=${TIMEOUT-60}
15
+
16
+ APP_ROOT=/home/<%= @user %>/<%= @application %>/current
17
+ PID=$APP_ROOT/tmp/pids/unicorn.pid
18
+ CMD="cd $APP_ROOT ; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
19
+ AS_USER=<%= @user %>
20
+ set -u
21
+
22
+ OLD_PIN="$PID.oldbin"
23
+
24
+ sig () {
25
+ test -s "$PID" && kill -$1 `cat $PID`
26
+ }
27
+
28
+ oldsig () {
29
+ test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
30
+ }
31
+
32
+ run () {
33
+ if [ "$(id -un)" = "$AS_USER" ]; then
34
+ eval $1
35
+ else
36
+ su -c "$1" - $AS_USER
37
+ fi
38
+ }
39
+
40
+ case "$1" in
41
+ start)
42
+ sig 0 && echo >&2 "Already running" && exit 0
43
+ run "$CMD"
44
+ ;;
45
+ stop)
46
+ sig QUIT && exit 0
47
+ echo >&2 "Not running"
48
+ ;;
49
+ force-stop)
50
+ sig TERM && exit 0
51
+ echo >&2 "Not running"
52
+ ;;
53
+ restart|reload)
54
+ sig HUP && echo reloaded OK && exit 0
55
+ echo >&2 "Couldn't reload, starting '$CMD' instead"
56
+ run "$CMD"
57
+ ;;
58
+ upgrade)
59
+ if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
60
+ then
61
+ n=$TIMEOUT
62
+ while test -s $OLD_PIN && test $n -ge 0
63
+ do
64
+ printf '.' && sleep 1 && n=$(( $n - 1 ))
65
+ done
66
+ echo
67
+
68
+ if test $n -lt 0 && test -s $OLD_PIN
69
+ then
70
+ echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
71
+ exit 1
72
+ fi
73
+ exit 0
74
+ fi
75
+ echo >&2 "Couldn't upgrade, starting '$CMD' instead"
76
+ run "$CMD"
77
+ ;;
78
+ reopen-logs)
79
+ sig USR1
80
+ ;;
81
+ *)
82
+ echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
83
+ exit 1
84
+ ;;
85
+ esac