capistrano-unicorn-nginx 2.1.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +23 -158
- data/lib/capistrano/tasks/nginx.rake +19 -2
- data/lib/capistrano/tasks/unicorn.rake +3 -2
- data/lib/capistrano/unicorn_nginx/version.rb +1 -1
- data/lib/generators/capistrano/unicorn_nginx/templates/nginx_conf.erb +6 -0
- data/lib/generators/capistrano/unicorn_nginx/templates/unicorn.rb.erb +5 -0
- data/lib/generators/capistrano/unicorn_nginx/templates/unicorn_init.erb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d07f364efb0a3c692f5a90e291944f3039f0a0a0
|
4
|
+
data.tar.gz: 261aa7183d26027881a31024196e536f478f59d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1afb2f016b9c6859c722daacc25ab981959dc87834da8d0a76f2add162587d3afaabff5ce3d7230446c43df74ba98a7cf0ceb5a5499310ff5975cbe46e562166
|
7
|
+
data.tar.gz: e0cd00708bb708bcedd7412b82c448815f6ef49702552ed5523e9a307a353a37cc3c71c0aa021196ad57f2e783f6f71234864755f7bae54061ca7b76f789b11c
|
data/CHANGELOG.md
CHANGED
@@ -2,17 +2,27 @@
|
|
2
2
|
|
3
3
|
### master
|
4
4
|
|
5
|
+
### v3.0.0, 2014-10-05
|
6
|
+
- enable setting unicorn app environment with `rails_env` option.
|
7
|
+
If `rails_env` is not set, `stage` option is used as until now. (@bruno-)
|
8
|
+
- add load balancing support (@rhomeister)
|
9
|
+
- config files are updated each time `setup` task is run (@rhomeister)
|
10
|
+
|
5
11
|
### v2.1.0, 2014-08-05
|
6
12
|
- add `nginx_location` option that specifies nginx installation dir
|
7
13
|
(@jordanyaker)
|
14
|
+
|
8
15
|
### v2.0.0, 2014-04-11
|
9
16
|
- all the work is moved to the `setup` task
|
17
|
+
|
10
18
|
### v1.0.2, 2014-03-30
|
11
19
|
- add `sudo_upload!` helper method for easier uploads
|
12
20
|
- improve the way how templates are handled
|
21
|
+
|
13
22
|
### v1.0.1, 2014-03-30
|
14
23
|
- refactor all unicorn and nginx paths to separate modules
|
15
24
|
- speed up `nginx:setup_ssl` task
|
16
25
|
- small README update
|
26
|
+
|
17
27
|
### v1.0.0, 2014-03-29
|
18
28
|
- @bruno- all the v1.0.0 features
|
data/README.md
CHANGED
@@ -7,30 +7,26 @@ Goals of this plugin:
|
|
7
7
|
* automatic unicorn and nginx configuration for Rails apps
|
8
8
|
* **no manual ssh** to the server required
|
9
9
|
* zero downtime deployments enabled
|
10
|
+
* support for single node as well as cluster deployments
|
10
11
|
|
11
12
|
Specifics:
|
12
13
|
|
13
|
-
* generates nginx config file on the server
|
14
|
-
* generates unicorn initializer and config files<br/>
|
14
|
+
* generates nginx config file on the server (web role)
|
15
|
+
* generates unicorn initializer and config files (app role)<br/>
|
15
16
|
application is started automatically after server restart
|
16
17
|
* capistrano tasks for server management, example: `unicorn:restart`<br/>
|
17
18
|
see below for all available tasks
|
19
|
+
* automatic load balancing setup when there are multiple `app` nodes
|
18
20
|
|
19
21
|
`capistrano-unicorn-nginx` works only with Capistrano 3!
|
20
22
|
|
21
|
-
This project was based on
|
22
|
-
[capistrano-nginx-unicorn](https://github.com/kalys/capistrano-nginx-unicorn).
|
23
|
-
I contributed a lot to Capistrano 3 version of that plugin. In the end I
|
24
|
-
decided to create my own project to bring in additional improvements, without
|
25
|
-
having to ask for permissions and wait for merging.
|
26
|
-
|
27
23
|
### Installation
|
28
24
|
|
29
25
|
Add this to `Gemfile`:
|
30
26
|
|
31
27
|
group :development do
|
32
|
-
gem 'capistrano', '~> 3.1'
|
33
|
-
gem 'capistrano-unicorn-nginx', '~>
|
28
|
+
gem 'capistrano', '~> 3.2.1'
|
29
|
+
gem 'capistrano-unicorn-nginx', '~> 3.0.0'
|
34
30
|
end
|
35
31
|
|
36
32
|
And then:
|
@@ -39,169 +35,38 @@ And then:
|
|
39
35
|
|
40
36
|
### Setup and usage
|
41
37
|
|
42
|
-
|
43
|
-
|
44
|
-
require 'capistrano/unicorn_nginx'
|
45
|
-
|
46
|
-
Only if you already have a domain for your app, set `nginx_server_name` in
|
47
|
-
stage file, example `config/deploy/production.rb`:
|
48
|
-
|
49
|
-
set :nginx_server_name, 'mydomain.com'
|
50
|
-
|
51
|
-
If you don't have a domain yet, you do not have to do anything
|
52
|
-
(`nginx_server_name` will use the default value - server IP).
|
53
|
-
|
54
|
-
**SSL only setup**
|
55
|
-
|
56
|
-
If you want to setup SSL for your page, add these options to stage file
|
57
|
-
(i.e. `config/deploy/production.rb`):
|
58
|
-
|
59
|
-
# ignore this if you do not need SSL
|
60
|
-
set :nginx_use_ssl, true
|
61
|
-
set :nginx_ssl_cert_local_path, "/path/to/ssl_cert.crt"
|
62
|
-
set :nginx_ssl_cert_key_local_path, "/path/to/ssl_cert.key"
|
63
|
-
|
64
|
-
And you're all set!
|
65
|
-
|
66
|
-
**Setup task**
|
67
|
-
|
68
|
-
Make sure the `deploy_to` path exists and has the right privileges on the
|
69
|
-
server (i.e. `/var/www/myapp`).<br/>
|
70
|
-
Or just install
|
71
|
-
[capistrano-safe-deploy-to](https://github.com/bruno-/capistrano-safe-deploy-to)
|
72
|
-
plugin and don't think about it.
|
38
|
+
Depending on your needs 2 general scenarios are covered:
|
73
39
|
|
74
|
-
|
75
|
-
|
76
|
-
|
40
|
+
- [single server setup](https://github.com/capistrano-plugins/capistrano-unicorn-nginx/wiki/Single-server-setup)<br/>
|
41
|
+
A scenario where you run the webserver (nginx) and application server
|
42
|
+
(unicorn) on the same node.
|
43
|
+
- [multiple server setup](https://github.com/capistrano-plugins/capistrano-unicorn-nginx/wiki/Multiple-server-setup)<br/>
|
44
|
+
Webserver (nginx) and application server (unicorn) run on different nodes.
|
77
45
|
|
78
46
|
### Configuration
|
79
47
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
You'll find the options and their defaults below.
|
84
|
-
|
85
|
-
In order to override the default, put the option in the stage file, for example:
|
86
|
-
|
87
|
-
# in config/deploy/production.rb
|
88
|
-
set :unicorn_workers, 4
|
89
|
-
|
90
|
-
**Nginx options**
|
91
|
-
|
92
|
-
Defaults are listed near option name in the first line.
|
93
|
-
|
94
|
-
- `set :nginx_server_name` # defaults to <server_IP><br/>
|
95
|
-
Your application's domain. The default is your server's IP address.
|
96
|
-
|
97
|
-
- `set :nginx_pid, "/run/nginx.pid"`<br/>
|
98
|
-
Path for nginx process pid file.
|
99
|
-
|
100
|
-
- `set :nginx_location, "/etc/nginx"`<br/>
|
101
|
-
Nginx installation directory.
|
102
|
-
|
103
|
-
SSL related options:
|
104
|
-
|
105
|
-
- `set :nginx_use_ssl, false`<br/>
|
106
|
-
If set to `true`, nginx will be configured to 443 port and port 80 will be auto
|
107
|
-
routed to 443. Also, on `nginx:setup`, paths to ssl certificate and key will be
|
108
|
-
configured. Certificate file and key will be uploaded to `/etc/ssl/certs/`
|
109
|
-
and `/etc/ssl/private/` directories on the server.
|
110
|
-
|
111
|
-
- `set :nginx_upload_local_cert, true`<br/>
|
112
|
-
If `true`, certificates will be uploaded from a local path. Otherwise, it
|
113
|
-
is expected for the certificate and key defined in the next 2 variables to be
|
114
|
-
already on the server.
|
115
|
-
|
116
|
-
- `set :nginx_ssl_cert, "#{fetch(:nginx_server_name)}.crt"`<br/>
|
117
|
-
Remote file name of the certificate. Only makes sense if `nginx_use_ssl` is set.
|
118
|
-
|
119
|
-
- `set :nginx_ssl_cert_key, "#{fetch(:nginx_server_name)}.key"`<br/>
|
120
|
-
Remote file name of the certificate. Only makes sense if `nginx_use_ssl` is set.
|
121
|
-
|
122
|
-
- `set :nginx_ssl_cert_local_path` # no default, required if
|
123
|
-
`nginx_use_ssl = true` and `nginx_upload_local_cert = true`<br/>
|
124
|
-
Local path to file with certificate. Only makes sense if `nginx_use_ssl` is
|
125
|
-
set. This file will be copied to remote server. Example value:
|
126
|
-
`set :nginx_ssl_cert_local_path, "/home/user/ssl/myssl.cert"`
|
127
|
-
|
128
|
-
- `set :nginx_ssl_cert_key_local_path` # no default<br/>
|
129
|
-
Local path to file with certificate key. Only makes sense if `nginx_use_ssl` is set.
|
130
|
-
This file will be copied to remote server. Example value:
|
131
|
-
`set :nginx_ssl_cert_key_local_path, "/home/user/ssl/myssl.key"`
|
132
|
-
|
133
|
-
**Unicorn options**
|
134
|
-
|
135
|
-
Defaults are listed near option name in the first line.
|
136
|
-
|
137
|
-
- `set :unicorn_service, "unicorn_#{fetch(:application)}_#{fetch(:stage)}`<br/>
|
138
|
-
Unicorn service name is `unicorn_myapp_production` by default.
|
139
|
-
|
140
|
-
- `set :unicorn_pid, shared_path.join("tmp/pids/unicorn.pid")`<br/>
|
141
|
-
Path for unicorn process pid file.
|
142
|
-
|
143
|
-
- `set :unicorn_config, shared_path.join("config/unicorn.rb")`<br/>
|
144
|
-
Path for unicorn config file.
|
145
|
-
|
146
|
-
- `set :unicorn_workers, 2`<br/>
|
147
|
-
Number of unicorn workers.
|
48
|
+
See the
|
49
|
+
[full options list on the wiki page](https://github.com/capistrano-plugins/capistrano-unicorn-nginx/wiki/Configuration).
|
50
|
+
Feel free to skip this unless you're looking for something specific.
|
148
51
|
|
149
52
|
### How it works
|
150
53
|
|
151
|
-
|
54
|
+
[How it works wiki page](https://github.com/capistrano-plugins/capistrano-unicorn-nginx/wiki/How-it-works)
|
55
|
+
contains the list of tasks that the plugin executes.
|
152
56
|
|
153
|
-
|
154
|
-
|
155
|
-
- `nginx:setup`<br/>
|
156
|
-
Generates and uploads nginx config file. Symlinks config file to
|
157
|
-
`/etc/nginx/sites-enabled`.
|
158
|
-
- `nginx:setup_ssl`<br/>
|
159
|
-
Performs SSL related tasks if `nginx_use_ssl` is true (false by default).
|
160
|
-
|
161
|
-
**Unicorn**
|
162
|
-
|
163
|
-
- `unicorn:setup_initializer`<br/>
|
164
|
-
Uploads unicorn initializer file.
|
165
|
-
- `unicorn:setup_app_config`<br/>
|
166
|
-
Generates unicorn application config file
|
167
|
-
|
168
|
-
**Capistrano `deploy` task**
|
169
|
-
|
170
|
-
This plugin also integrates seamlessly with Capistrano `deploy` task.
|
171
|
-
Here's what happens when you run `$ bundle exec cap production deploy`:
|
172
|
-
|
173
|
-
- `after :publishing, "nginx:reload"`<br/>
|
174
|
-
Reloads nginx.
|
175
|
-
- `after :publishing, "unicorn:restart"`<br/>
|
176
|
-
Restarts unicorn after new release.
|
57
|
+
You do not have to know this unless you want to learn more about the plugin internals.
|
177
58
|
|
178
59
|
### Template customization
|
179
60
|
|
180
|
-
|
181
|
-
`
|
182
|
-
|
183
|
-
$ bundle exec rails g capistrano:unicorn_nginx:config
|
184
|
-
|
185
|
-
This will copy default templates to `config/deploy/templates` directory, so you
|
186
|
-
can customize them as you like, and capistrano tasks will use this templates
|
187
|
-
instead of default.
|
61
|
+
[On template customization wiki page](https://github.com/capistrano-plugins/capistrano-unicorn-nginx/wiki/Template-customization)
|
62
|
+
see how to inspect, tweak and override templates for `nginx` and `unicorn`
|
63
|
+
config files.
|
188
64
|
|
189
|
-
|
190
|
-
|
191
|
-
$ bundle exec rails g capistrano:unicorn_nginx:config config/templates
|
65
|
+
Do not do this unless you have a specific need.
|
192
66
|
|
193
67
|
### More Capistrano automation?
|
194
68
|
|
195
|
-
|
196
|
-
these zero-configuration, plug-n-play plugins:
|
197
|
-
|
198
|
-
- [capistrano-postgresql](https://github.com/bruno-/capistrano-postgresql)<br/>
|
199
|
-
plugin that automates postgresql configuration and setup
|
200
|
-
- [capistrano-rbenv-install](https://github.com/bruno-/capistrano-rbenv-install)<br/>
|
201
|
-
would you like Capistrano to install rubies for you?
|
202
|
-
- [capistrano-safe-deploy-to](https://github.com/bruno-/capistrano-safe-deploy-to)<br/>
|
203
|
-
if you're annoyed that Capistrano does **not** create a deployment path for the
|
204
|
-
app on the server (default `/var/www/myapp`), this is what you need!
|
69
|
+
Check out [capistrano-plugins](https://github.com/capistrano-plugins) github org.
|
205
70
|
|
206
71
|
### Bug reports and pull requests
|
207
72
|
|
@@ -31,10 +31,27 @@ namespace :nginx do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
# this is needed when the web role is a non release role -> deploy directories are not created, and nginx log files
|
35
|
+
# are written to "#{deploy_path}/shared/log/"
|
36
|
+
desc "Create the nginx log directory"
|
37
|
+
task :create_log_dir do
|
38
|
+
on roles :web do
|
39
|
+
# create the deploy_to, shared_path and the directory in which the nginx_access_log_file resides.
|
40
|
+
# We need to be conservative and ensure that all are created with the correct ownership: it could happen that
|
41
|
+
# web does become a release role later, in which case the ownerships need to be correct.
|
42
|
+
[deploy_path, shared_path, File.dirname(nginx_access_log_file)].each do |dir|
|
43
|
+
next if file_exists? dir
|
44
|
+
sudo :mkdir, '-pv', dir
|
45
|
+
user = capture :id, '-un'
|
46
|
+
group = capture :id, '-gn'
|
47
|
+
sudo :chown, "#{user}:#{group}", dir
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
34
52
|
desc 'Setup nginx configuration'
|
35
|
-
task :
|
53
|
+
task setup: [:create_log_dir] do
|
36
54
|
on roles :web do
|
37
|
-
next if file_exists? nginx_sites_available_file
|
38
55
|
sudo_upload! template('nginx_conf.erb'), nginx_sites_available_file
|
39
56
|
sudo :ln, '-fs', nginx_sites_available_file, nginx_sites_enabled_file
|
40
57
|
end
|
@@ -11,6 +11,9 @@ namespace :load do
|
|
11
11
|
set :unicorn_pid, -> { unicorn_default_pid_file }
|
12
12
|
set :unicorn_config, -> { unicorn_default_config_file }
|
13
13
|
set :unicorn_workers, 2
|
14
|
+
set :unicorn_tcp_listen_port, 8080
|
15
|
+
set :unicorn_use_tcp, -> { roles(:app).count > 1} # use tcp if there are multiple app nodes
|
16
|
+
set :unicorn_app_env, -> { fetch(:rails_env) || fetch(:stage) }
|
14
17
|
# set :unicorn_user # default set in `unicorn:defaults` task
|
15
18
|
|
16
19
|
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids')
|
@@ -28,7 +31,6 @@ namespace :unicorn do
|
|
28
31
|
desc 'Setup Unicorn initializer'
|
29
32
|
task :setup_initializer do
|
30
33
|
on roles :app do
|
31
|
-
next if file_exists? unicorn_initd_file
|
32
34
|
sudo_upload! template('unicorn_init.erb'), unicorn_initd_file
|
33
35
|
execute :chmod, '+x', unicorn_initd_file
|
34
36
|
sudo 'update-rc.d', '-f', fetch(:unicorn_service), 'defaults'
|
@@ -38,7 +40,6 @@ namespace :unicorn do
|
|
38
40
|
desc 'Setup Unicorn app configuration'
|
39
41
|
task :setup_app_config do
|
40
42
|
on roles :app do
|
41
|
-
next if file_exists? fetch(:unicorn_config)
|
42
43
|
execute :mkdir, '-pv', File.dirname(fetch(:unicorn_config))
|
43
44
|
upload! template('unicorn.rb.erb'), fetch(:unicorn_config)
|
44
45
|
end
|
@@ -1,5 +1,11 @@
|
|
1
1
|
upstream unicorn_<%= fetch(:nginx_config_name) %> {
|
2
|
+
<% if fetch(:unicorn_use_tcp) %>
|
3
|
+
<% roles(:app).each do |role| %>
|
4
|
+
server <%= role.hostname %>:<%= fetch(:unicorn_tcp_listen_port)%> fail_timeout=0;
|
5
|
+
<% end %>
|
6
|
+
<% else %>
|
2
7
|
server unix:/tmp/unicorn.<%= fetch(:nginx_config_name) %>.sock fail_timeout=0;
|
8
|
+
<% end %>
|
3
9
|
}
|
4
10
|
|
5
11
|
<% if fetch(:nginx_use_ssl) %>
|
@@ -3,7 +3,12 @@ pid "<%= fetch(:unicorn_pid) %>"
|
|
3
3
|
stdout_path "<%= unicorn_log_file %>"
|
4
4
|
stderr_path "<%= unicorn_error_log_file %>"
|
5
5
|
|
6
|
+
<% if fetch(:unicorn_use_tcp) %>
|
7
|
+
listen <%= fetch(:unicorn_tcp_listen_port) %>
|
8
|
+
<% else %>
|
6
9
|
listen "/tmp/unicorn.<%= fetch(:nginx_config_name) %>.sock"
|
10
|
+
<% end %>
|
11
|
+
|
7
12
|
worker_processes <%= fetch(:unicorn_workers) %>
|
8
13
|
timeout 30
|
9
14
|
|
@@ -15,9 +15,9 @@ TIMEOUT=${TIMEOUT-60}
|
|
15
15
|
APP_ROOT=<%= current_path %>
|
16
16
|
PID=<%= fetch(:unicorn_pid) %>
|
17
17
|
|
18
|
-
CMD="cd $APP_ROOT && <%= bundle_unicorn("-D -c", fetch(:unicorn_config), "-E", fetch(:stage)) %>"
|
19
|
-
|
20
18
|
AS_USER=<%= fetch(:unicorn_user) %>
|
19
|
+
CMD="export HOME; true "${HOME:=$(getent passwd "$AS_USER" | cut -d: -f6;)}" ; cd $APP_ROOT && <%= bundle_unicorn("-D -c", fetch(:unicorn_config), "-E", fetch(:unicorn_app_env)) %>"
|
20
|
+
|
21
21
|
set -u
|
22
22
|
|
23
23
|
OLD_PIN="$PID.oldbin"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-unicorn-nginx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno Sutic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano
|