capistrano3-nginx_unicorn 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ /vendor/ruby
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-nginx-unicorn.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Ivan Tkalin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,187 @@
1
+ # Capistrano3-NginxUnicorn
2
+
3
+ This is a capistrano v3 plugin that integrates Unicorn tasks and Nginx configuration into capistrano deployment scripts; it was forked from kalys/capistrano-nginx-unicorn
4
+
5
+ Capistrano tasks for configuration and management nginx+unicorn combo for zero downtime deployments of Rails applications.
6
+
7
+ Provides capistrano tasks to:
8
+
9
+ * easily add application to nginx and reload it's configuration
10
+ * create unicorn init script for application, so it will be automatically started when OS restarts
11
+ * start/stop unicorn (also can be done using `sudo service unicorn_<your_app> start/stop`)
12
+ * reload unicorn using `USR2` signal to load new application version with zero downtime
13
+ * creates logrotate record to rotate application logs
14
+
15
+ Provides several capistrano variables for easy customization.
16
+ Also, for full customization, all configs can be copied to the application using generators.
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ gem 'capistrano3-nginx_unicorn', group: :development
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install capistrano3-nginx_unicorn
31
+
32
+ ## Usage
33
+
34
+ Add this line to your `Capfile`
35
+
36
+ require 'capistrano/nginx_unicorn'
37
+
38
+ Note, that following capistrano variables should be defined:
39
+
40
+ application
41
+ current_path
42
+ shared_path
43
+ user
44
+
45
+ You can check that new tasks are available (`cap -T`):
46
+
47
+ for nginx:
48
+
49
+ # add and enable application to nginx
50
+ cap nginx:setup
51
+
52
+ # reload nginx configuration
53
+ cap nginx:reload
54
+
55
+ and for unicorn:
56
+
57
+ # create unicorn configuration and init script
58
+ cap unicorn:setup
59
+
60
+ # start unicorn
61
+ cap unicorn:start
62
+
63
+ # stop unicorn
64
+ cap unicorn:stop
65
+
66
+ # reload unicorn with no downtime
67
+ # old workers will process new request until new master is fully loaded
68
+ # then old workers will be automatically killed and new workers will start processing requests
69
+ cap unicorn:restart
70
+
71
+ and shared:
72
+
73
+ # create logrotate record to rotate application logs
74
+ cap logrotate
75
+
76
+ There is no need to execute any of these tasks manually.
77
+ They will be called automatically on different deploy stages:
78
+
79
+ * `nginx:setup`, `nginx:reload`, `unicorn:setup` and `logrotate` are hooked to `deploy:setup`
80
+ * `unicorn:restart` is hooked to `deploy:restart`
81
+
82
+ This means that if you run `cap deploy:setup`,
83
+ nginx and unicorn will be automatically configured.
84
+ And after each deploy, unicorn will be automatically reloaded.
85
+
86
+ However, if you changed variables or customized templates,
87
+ you can run any of these tasks to update configuration.
88
+
89
+ ## Customization
90
+
91
+ ### Using variables
92
+
93
+ You can customize nginx and unicorn configs using capistrano variables:
94
+
95
+
96
+ ```ruby
97
+ # path to customized templates (see below for details)
98
+ # default value: "config/deploy/templates"
99
+ set :templates_path, "config/deploy/templates"
100
+
101
+ # server name for nginx, default value: no (will be prompted if not set)
102
+ # set this to your site name as it is visible from outside
103
+ # this will allow 1 nginx to serve several sites with different `server_name`
104
+ set :nginx_server_name, "example.com"
105
+
106
+ # path, where unicorn pid file will be stored
107
+ # default value: `"#{current_path}/tmp/pids/unicorn.pid"`
108
+ set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"
109
+
110
+ # path, where unicorn config file will be stored
111
+ # default value: `"#{shared_path}/config/unicorn.rb"`
112
+ set :unicorn_config, "#{shared_path}/config/unicorn.rb"
113
+
114
+ # path, where unicorn log file will be stored
115
+ # default value: `"#{shared_path}/config/unicorn.rb"`
116
+ set :unicorn_log, "#{shared_path}/config/unicorn.rb"
117
+
118
+ # user name to run unicorn
119
+ # default value: `user` (user varibale defined in your `deploy.rb`)
120
+ set :unicorn_user, "user"
121
+
122
+ # number of unicorn workers
123
+ # default value: no (will be prompted if not set)
124
+ set :unicorn_workers, 4
125
+
126
+ # if set, nginx will be configured to 443 port and port 80 will be auto rewritten to 443
127
+ # also, on `nginx:setup`, paths to ssl certificate and key will be configured
128
+ # and certificate file and key will be copied to `/etc/ssl/certs` and `/etc/ssl/private/` directories
129
+ # default value: false
130
+ set :nginx_use_ssl, false
131
+
132
+ # if set, it will ask to upload certificates from a local path. Otherwise, it will expect
133
+ # the certificate and key defined in the next 2 variables to be already in the server.
134
+ set :nginx_upload_local_certificate, { true }
135
+
136
+ # remote file name of the certificate, only makes sense if `nginx_use_ssl` is set
137
+ # default value: `nginx_server_name + ".crt"`
138
+ set :nginx_ssl_certificate, "#{nginx_server_name}.crt"
139
+
140
+ # remote file name of the certificate, only makes sense if `nginx_use_ssl` is set
141
+ # default value: `nginx_server_name + ".key"`
142
+ set :nginx_ssl_certificate_key, "#{nginx_server_name}.key"
143
+
144
+ # local path to file with certificate, only makes sense if `nginx_use_ssl` is set
145
+ # this file will be copied to remote server
146
+ # default value: none (will be prompted if not set)
147
+ set :nginx_ssl_certificate_local_path, "/home/ivalkeen/ssl/myssl.cert"
148
+
149
+ # local path to file with certificate key, only makes sense if `nginx_use_ssl` is set
150
+ # this file will be copied to remote server
151
+ # default value: none (will be prompted if not set)
152
+ set :nginx_ssl_certificate_key_local_path, "/home/ivalkeen/ssl/myssl.key"
153
+ ```
154
+
155
+ For example, of you site name is `example.com` and you want to use 8 unicorn workers,
156
+ your `deploy.rb` will look like this:
157
+
158
+ ```ruby
159
+ set :server_name, "example.com"
160
+ set :unicorn_workers, 4
161
+ require 'capistrano-nginx-unicorn'
162
+ ```
163
+
164
+ ### Template Customization
165
+
166
+ If you want to change default templates, you can generate them using `rails generator`
167
+
168
+ rails g capistrano:nginx_unicorn:config
169
+
170
+ This will copy default templates to `config/deploy/templates` directory,
171
+ so you can customize them as you like, and capistrano tasks will use this templates instead of default.
172
+
173
+ You can also provide path, where to generate templates:
174
+
175
+ rails g capistrano:nginx_unicorn:config config/templates
176
+
177
+ # TODO:
178
+
179
+ * add tests
180
+
181
+ ## Contributing
182
+
183
+ 1. Fork it
184
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
185
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
186
+ 4. Push to the branch (`git push origin my-new-feature`)
187
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano3/nginx_unicorn/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "capistrano3-nginx_unicorn"
8
+ gem.version = Capistrano3::NginxUnicorn::VERSION
9
+ gem.authors = ["Ivan Tkalin", "Oleg Bavaev"]
10
+ gem.email = ["itkalin@gmail.com", "jesoba7@gmail.com"]
11
+ gem.description = %q{Capistrano v3 tasks for configuration and management nginx+unicorn combo for zero downtime deployments of Rails applications. Configs can be copied to the application using generators and easily customized.}
12
+ gem.summary = %q{Create and manage nginx+unicorn configs from capistrano v3}
13
+ gem.homepage = "https://github.com/jesson/capistrano3-nginx_unicorn"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'capistrano', '>= 3.0.0'
21
+
22
+ gem.add_development_dependency "rake"
23
+ end
File without changes
@@ -0,0 +1,2 @@
1
+ load File.expand_path("../tasks/nginx_unicorn.rake", __FILE__)
2
+
@@ -0,0 +1,5 @@
1
+ module Capistrano3
2
+ module NginxUnicorn
3
+ VERSION = "0.0.6"
4
+ end
5
+ end
@@ -0,0 +1,108 @@
1
+ require 'capistrano'
2
+
3
+ namespace :load do
4
+ task :defaults do
5
+ set :templates_path, "config/deploy/templates"
6
+
7
+ set :nginx_server_name, -> { "www.example.com" }
8
+ set :nginx_use_ssl, false
9
+ set :nginx_ssl_certificate, -> { "#{fetch(:nginx_server_name)}.crt" }
10
+ set :nginx_ssl_certificate_key, -> { "#{fetch(:nginx_server_name)}.key" }
11
+ set :nginx_upload_local_certificate, -> { true }
12
+ set :nginx_ssl_certificate_local_path, -> { "/etc/certificates/" }
13
+ set :nginx_ssl_certificate_key_local_path, -> { "/etc/certificates/keys" }
14
+
15
+ set :unicorn_pid, -> { "#{current_path}/tmp/pids/unicorn.pid" }
16
+ set :unicorn_config, -> { "#{shared_path}/config/unicorn.rb" }
17
+ set :unicorn_log, -> { "#{shared_path}/log/unicorn.log" }
18
+ set :unicorn_user, -> { fetch(:user) }
19
+ set :unicorn_workers, 4
20
+ end
21
+ end
22
+
23
+ namespace :nginx do
24
+ desc "Setup nginx configuration for this application"
25
+ task :setup do
26
+ on roles(:web) do
27
+ template("nginx_conf.erb", "/tmp/#{fetch(:application)}.conf")
28
+ execute "sudo mv /tmp/#{fetch(:application)}.conf /etc/nginx/sites-available/#{fetch(:application)}.conf"
29
+ execute "sudo ln -fs /etc/nginx/sites-available/#{fetch(:application)}.conf /etc/nginx/sites-enabled/#{fetch(:application)}.conf"
30
+
31
+ if fetch(:nginx_use_ssl)
32
+ if nginx_upload_local_certificate
33
+ put File.read(nginx_ssl_certificate_local_path), "/tmp/#{fetch(:nginx_ssl_certificate)}"
34
+ put File.read(nginx_ssl_certificate_key_local_path), "/tmp/#{fetch(:nginx_ssl_certificate_key)}"
35
+
36
+ execute "sudo mv /tmp/#{fetch(:nginx_ssl_certificate)} /etc/ssl/certs/#{fetch(:nginx_ssl_certificate)}"
37
+ execute "sudo mv /tmp/#{fetch(:nginx_ssl_certificate_key)} /etc/ssl/private/#{fetch(:nginx_ssl_certificate_key)}"
38
+ end
39
+
40
+ execute "sudo chown root:root /etc/ssl/certs/#{fetch(:nginx_ssl_certificate)}"
41
+ execute "sudo chown root:root /etc/ssl/private/#{fetch(:nginx_ssl_certificate_key)}"
42
+ end
43
+ end
44
+ end
45
+
46
+ desc "Reload nginx configuration"
47
+ task :reload do
48
+ on roles(:web) do
49
+ execute "mkdir -p #{shared_path}/log"
50
+ execute "sudo /etc/init.d/nginx reload"
51
+ end
52
+ end
53
+
54
+ after "deploy:check", "nginx:setup"
55
+ after "deploy:finished", "nginx:reload"
56
+
57
+ end
58
+
59
+ namespace :unicorn do
60
+ desc "Setup Unicorn initializer and app configuration"
61
+ task :setup do
62
+ on roles(:app) do
63
+ execute "mkdir -p #{shared_path}/config"
64
+ execute "mkdir -p #{shared_path}/tmp/pids"
65
+ template "unicorn.rb.erb", fetch(:unicorn_config)
66
+ template "unicorn_init.erb", "/tmp/unicorn_init"
67
+ execute "chmod +x /tmp/unicorn_init"
68
+ execute "sudo mv /tmp/unicorn_init /etc/init.d/unicorn_#{fetch(:application)}"
69
+ execute "sudo update-rc.d -f unicorn_#{fetch(:application)} defaults"
70
+ end
71
+ end
72
+
73
+ after "deploy:check", "unicorn:setup"
74
+
75
+ end
76
+
77
+ namespace :deploy do
78
+ %w[start stop restart].each do |command|
79
+ desc "#{command} unicorn"
80
+ task command do
81
+ on roles(:app) do
82
+ execute "service unicorn_#{fetch(:application)} #{command}"
83
+ end
84
+ end
85
+ end
86
+ after :publishing, "deploy:restart"
87
+ end
88
+
89
+ desc "Setup logs rotation for nginx and unicorn"
90
+ task :logrotate do
91
+ on roles([:web, :app]) do
92
+ template("logrotate.erb", "/tmp/#{fetch(:application)}_logrotate")
93
+ execute "sudo mv /tmp/#{fetch(:application)}_logrotate /etc/logrotate.d/#{fetch(:application)}"
94
+ execute "sudo chown root:root /etc/logrotate.d/#{fetch(:application)}"
95
+ end
96
+ end
97
+
98
+ after "deploy:check", "logrotate"
99
+
100
+ def template(template_name, target)
101
+ config_file = "#{fetch(:templates_path)}/#{template_name}"
102
+ # if no customized file, proceed with default
103
+ unless File.exists?(config_file)
104
+ config_file = File.join(File.dirname(__FILE__), "../../generators/capistrano3/nginx_unicorn/templates/#{template_name}")
105
+ end
106
+ upload! StringIO.new(ERB.new(File.read(config_file)).result(binding)), target
107
+ end
108
+
@@ -0,0 +1,9 @@
1
+ To create local nginx and unicorn configuration files call
2
+
3
+ rails generate capistrano:nginx_unicorn:config [path]
4
+
5
+ The default path is "config/deploy/templates". You can override it like so:
6
+
7
+ rails generate capistrano:nginx_unicorn:config "config/templates"
8
+
9
+ If you override templates path, don't forget to set "templates_path" variable in your deploy.rb
@@ -0,0 +1,20 @@
1
+ module Capistrano3
2
+ module NginxUnicorn
3
+ module Generators
4
+ class ConfigGenerator < Rails::Generators::Base
5
+ desc "Create local nginx and unicorn configuration files for customization"
6
+ source_root File.expand_path('../templates', __FILE__)
7
+ argument :templates_path, :type => :string,
8
+ :default => "config/deploy/templates",
9
+ :banner => "path to templates"
10
+
11
+ def copy_template
12
+ copy_file "nginx_conf.erb", "#{templates_path}/nginx_conf.erb"
13
+ copy_file "unicorn.rb.erb", "#{templates_path}/unicorn.rb.erb"
14
+ copy_file "unicorn_init.erb", "#{templates_path}/unicorn_init.erb"
15
+ copy_file "logrotate.erb", "#{templates_path}/logrotate.erb"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ <%= shared_path %>/log/*.log {
2
+ daily
3
+ missingok
4
+ rotate 180
5
+ compress
6
+ dateext
7
+ delaycompress
8
+
9
+ lastaction
10
+ pid=<%= fetch(:unicorn_pid) %>
11
+ test -s $pid && kill -USR1 "$(cat $pid)"
12
+ endscript
13
+
14
+ prerotate
15
+ if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
16
+ run-parts /etc/logrotate.d/httpd-prerotate; \
17
+ fi \
18
+ endscript
19
+
20
+ postrotate
21
+ [ ! -f /run/nginx.pid ] || kill -USR1 `cat /run/nginx.pid`
22
+ endscript
23
+ }
@@ -0,0 +1,85 @@
1
+ upstream unicorn_<%= fetch(:application) %> {
2
+ server unix:/tmp/unicorn.<%= fetch(:application) %>.sock fail_timeout=0;
3
+ }
4
+
5
+ <% if fetch(:nginx_use_ssl) %>
6
+ server {
7
+ listen 80;
8
+ rewrite ^(.*) https://$host$1 permanent;
9
+ }
10
+ <% end %>
11
+
12
+ server {
13
+ <% if fetch(:nginx_use_ssl) %>
14
+ listen 443;
15
+ ssl on;
16
+ ssl_certificate /etc/ssl/certs/<%= fetch(:nginx_ssl_certificate) %>;
17
+ ssl_certificate_key /etc/ssl/private/<%= fetch(:nginx_ssl_certificate_key) %>;
18
+ <% else %>
19
+ listen 80;
20
+ <% end %>
21
+
22
+ server_name <%= fetch(:nginx_server_name) %>;
23
+ root <%= current_path %>/public;
24
+ try_files $uri/index.html $uri @unicorn_<%= fetch(:application) %>;
25
+
26
+ location @unicorn_<%= fetch(:application) %> {
27
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
28
+ proxy_set_header Host $http_host;
29
+ proxy_redirect off;
30
+ <% if fetch(:nginx_use_ssl) %>
31
+ proxy_set_header X-Forwarded-Proto https;
32
+ <% end %>
33
+ proxy_pass http://unicorn_<%= fetch(:application) %>;
34
+ # limit_req zone=one;
35
+ access_log <%= shared_path %>/log/nginx.access.log;
36
+ error_log <%= shared_path %>/log/nginx.error.log;
37
+ }
38
+
39
+ location ~ ^/(assets|images|javascripts|stylesheets|swfs|system)/ {
40
+ gzip_static on;
41
+ expires max;
42
+ add_header Cache-Control public;
43
+ add_header Last-Modified "";
44
+ add_header ETag "";
45
+
46
+ open_file_cache max=1000 inactive=500s;
47
+ open_file_cache_valid 600s;
48
+ open_file_cache_errors on;
49
+ break;
50
+ }
51
+
52
+ client_max_body_size 4G;
53
+ keepalive_timeout 10;
54
+
55
+ error_page 500 502 504 /500.html;
56
+ error_page 503 @503;
57
+
58
+ location = /50x.html {
59
+ root html;
60
+ }
61
+
62
+ location = /404.html {
63
+ root html;
64
+ }
65
+
66
+ location @503 {
67
+ error_page 405 = /system/maintenance.html;
68
+ if (-f $document_root/system/maintenance.html) {
69
+ rewrite ^(.*)$ /system/maintenance.html break;
70
+ }
71
+ rewrite ^(.*)$ /503.html break;
72
+ }
73
+
74
+ if ($request_method !~ ^(GET|HEAD|PUT|POST|DELETE|OPTIONS)$ ){
75
+ return 405;
76
+ }
77
+
78
+ if (-f $document_root/system/maintenance.html) {
79
+ return 503;
80
+ }
81
+
82
+ location ~ \.(php|html)$ {
83
+ return 405;
84
+ }
85
+ }
@@ -0,0 +1,48 @@
1
+ working_directory "<%= current_path %>"
2
+ pid "<%= fetch(:unicorn_pid) %>"
3
+ stderr_path "<%= fetch(:unicorn_log) %>"
4
+ stdout_path "<%= fetch(:unicorn_log) %>"
5
+
6
+ listen "/tmp/unicorn.<%= fetch(:application) %>.sock"
7
+ worker_processes <%= fetch(:unicorn_workers) %>
8
+ timeout 30
9
+
10
+ preload_app true
11
+
12
+ before_exec do |server|
13
+ ENV["BUNDLE_GEMFILE"] = "<%= current_path %>/Gemfile"
14
+ end
15
+
16
+ before_fork do |server, worker|
17
+ # Disconnect since the database connection will not carry over
18
+ if defined? ActiveRecord::Base
19
+ ActiveRecord::Base.connection.disconnect!
20
+ end
21
+
22
+ # Quit the old unicorn process
23
+ old_pid = "#{server.config[:pid]}.oldbin"
24
+ if File.exists?(old_pid) && server.pid != old_pid
25
+ begin
26
+ Process.kill("QUIT", File.read(old_pid).to_i)
27
+ rescue Errno::ENOENT, Errno::ESRCH
28
+ # someone else did our job for us
29
+ end
30
+ end
31
+
32
+ if defined?(Resque)
33
+ Resque.redis.quit
34
+ end
35
+
36
+ sleep 1
37
+ end
38
+
39
+ after_fork do |server, worker|
40
+ # Start up the database connection again in the worker
41
+ if defined?(ActiveRecord::Base)
42
+ ActiveRecord::Base.establish_connection
43
+ end
44
+
45
+ if defined?(Resque)
46
+ Resque.redis = 'localhost:6379'
47
+ end
48
+ end
@@ -0,0 +1,92 @@
1
+ #!/bin/bash
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
+ APP_ROOT=<%= current_path %>
16
+ RVM_TYPE=<%= fetch(:rvm_type) %>
17
+ PID=<%= fetch(:unicorn_pid) %>
18
+
19
+ if [ "$RVM_TYPE" == "system" ]; then
20
+ CMD="cd <%= current_path %>; rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'default' -c 'bundle exec unicorn -D -c <%= fetch(:unicorn_config) %> -E <%= fetch(:rails_env) %>'"
21
+ else
22
+ CMD="cd <%= current_path %>; source \"/home/<%= fetch(:user) %>/.rvm/environments/default\"; bundle exec unicorn -D -c <%= fetch(:unicorn_config) %> -E <%= fetch(:rails_env) %>"
23
+ fi
24
+
25
+ AS_USER=<%= fetch(:unicorn_user) %>
26
+ set -u
27
+
28
+ OLD_PIN="$PID.oldbin"
29
+
30
+ sig () {
31
+ test -s "$PID" && kill -$1 `cat $PID`
32
+ }
33
+
34
+ oldsig () {
35
+ test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
36
+ }
37
+
38
+ run () {
39
+ if [ "$(id -un)" = "$AS_USER" ]; then
40
+ eval $1
41
+ else
42
+ su -c "$1" - $AS_USER
43
+ fi
44
+ }
45
+
46
+ case "$1" in
47
+ start)
48
+ sig 0 && echo >&2 "Already running" && exit 0
49
+ run "$CMD"
50
+ ;;
51
+ stop)
52
+ sig QUIT && exit 0
53
+ echo >&2 "Not running"
54
+ ;;
55
+ force-stop)
56
+ sig TERM && exit 0
57
+ echo >&2 "Not running"
58
+ ;;
59
+ restart|reload)
60
+ sig USR2 && echo reloaded OK && exit 0
61
+ echo >&2 "Couldn't reload, starting '$CMD' instead"
62
+ run "$CMD"
63
+ ;;
64
+ upgrade)
65
+ if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
66
+ then
67
+ n=$TIMEOUT
68
+ while test -s $OLD_PIN && test $n -ge 0
69
+ do
70
+ printf '.' && sleep 1 && n=$(( $n - 1 ))
71
+ done
72
+ echo
73
+
74
+ if test $n -lt 0 && test -s $OLD_PIN
75
+ then
76
+ echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
77
+ exit 1
78
+ fi
79
+ exit 0
80
+ fi
81
+ echo >&2 "Couldn't upgrade, starting '$CMD' instead"
82
+ run "$CMD"
83
+ ;;
84
+ reopen-logs)
85
+ sig USR1
86
+ ;;
87
+ *)
88
+ echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
89
+ exit 1
90
+ ;;
91
+ esac
92
+
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano3-nginx_unicorn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ivan Tkalin
9
+ - Oleg Bavaev
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-12-27 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: capistrano
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 3.0.0
31
+ - !ruby/object:Gem::Dependency
32
+ name: rake
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: Capistrano v3 tasks for configuration and management nginx+unicorn combo
48
+ for zero downtime deployments of Rails applications. Configs can be copied to the
49
+ application using generators and easily customized.
50
+ email:
51
+ - itkalin@gmail.com
52
+ - jesoba7@gmail.com
53
+ executables: []
54
+ extensions: []
55
+ extra_rdoc_files: []
56
+ files:
57
+ - .gitignore
58
+ - Gemfile
59
+ - LICENSE.txt
60
+ - README.md
61
+ - Rakefile
62
+ - capistrano3-nginx_unicorn.gemspec
63
+ - lib/capistrano3-nginx_unicorn.rb
64
+ - lib/capistrano3/nginx_unicorn.rb
65
+ - lib/capistrano3/nginx_unicorn/version.rb
66
+ - lib/capistrano3/tasks/nginx_unicorn.rake
67
+ - lib/generators/capistrano3/nginx_unicorn/USAGE
68
+ - lib/generators/capistrano3/nginx_unicorn/config_generator.rb
69
+ - lib/generators/capistrano3/nginx_unicorn/templates/logrotate.erb
70
+ - lib/generators/capistrano3/nginx_unicorn/templates/nginx_conf.erb
71
+ - lib/generators/capistrano3/nginx_unicorn/templates/unicorn.rb.erb
72
+ - lib/generators/capistrano3/nginx_unicorn/templates/unicorn_init.erb
73
+ homepage: https://github.com/jesson/capistrano3-nginx_unicorn
74
+ licenses: []
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 1.8.25
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Create and manage nginx+unicorn configs from capistrano v3
97
+ test_files: []
98
+ has_rdoc: