capistrano-nginx-unicorn 0.0.8 → 0.1.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/CHANGELOG.md +8 -0
- data/capistrano-nginx-unicorn.gemspec +1 -1
- data/lib/capistrano-nginx-unicorn.rb +0 -2
- data/lib/capistrano/nginx_unicorn.rb +9 -0
- data/lib/capistrano/nginx_unicorn/defaults.rb +20 -0
- data/lib/capistrano/nginx_unicorn/helpers.rb +18 -0
- data/lib/capistrano/nginx_unicorn/version.rb +1 -1
- data/lib/capistrano/tasks/logrotate.rake +12 -0
- data/lib/capistrano/tasks/nginx.rake +48 -0
- data/lib/capistrano/tasks/unicorn.rake +38 -0
- data/lib/generators/capistrano/nginx_unicorn/templates/logrotate.erb +2 -2
- data/lib/generators/capistrano/nginx_unicorn/templates/nginx_conf.erb +11 -11
- data/lib/generators/capistrano/nginx_unicorn/templates/unicorn.rb.erb +5 -5
- data/lib/generators/capistrano/nginx_unicorn/templates/unicorn_init.erb +11 -4
- metadata +16 -10
- data/lib/capistrano/nginx_unicorn/tasks.rb +0 -102
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZWRmOGM1OTRjZTlhYTA2ZjFkNmViMmUwZjZjYmFkOWYxMWMyOWJkZA==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 59fd37b04eff080056157c4c3664c58721c4e397
|
4
|
+
data.tar.gz: bd445ae9e88bdb9b9fe1ccc8a21e8030674593fe
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZWI4NTg4N2E2MGMxNWQ1MjAyN2I5NjYyZTUyZjgwZDg4MjQxM2VlZGQ3Yjc2
|
11
|
-
YTM3YjNlNjUxMmExMzZiYzUwZTZhNTViMjc1YWE0YjgxYWY4NzE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MmQ3MTM4NzhkMmEwZmM5NjZlNWExYzhlMzRkNWQ2ZmMyM2M0MmNjZWI2YjA3
|
14
|
-
NzM4ZWQ1NWFmOTJjMzFlZTg5ZWQyMDIyN2IxZDFhMTM5MjEwNjM5YTRlY2Mz
|
15
|
-
ZWVlOWJhMWY3Y2M3ZjJmNjFhMTZlYTJiNTdhZTU3OGRhYTRkNDc=
|
6
|
+
metadata.gz: 6ecaf78c0a4a7bf9a1ddb6d9cf457222528686b532271c1029b80ad49c37b37699581db41f9515e53732f80295358677ca465aa72f92c5eac764a6c6a3d03a7e
|
7
|
+
data.tar.gz: a9a6196efe630e26f489ad56bb803f4552e3fe9bf5b942b492c8537b2e2ea934e2f0e60a3d2f2e90eb103ac029d7479aa8e6665fab5eb6b9d73439910ba7a34a
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
### From 0.0.8 to 0.1.0
|
2
|
+
|
3
|
+
* Separate nginx and unicorn tasks into the appropriate files.
|
4
|
+
* Encapsulate default settings in namespace.
|
5
|
+
* Rename nginx config file so it has .conf extension.
|
6
|
+
* Remove nginx server name prompt.
|
7
|
+
* Add nginx_unicorn:setup task.
|
8
|
+
* Add several options of starting unicorn (rvm, rbenv).
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_dependency 'capistrano', '~>
|
20
|
+
gem.add_dependency 'capistrano', '~> 3.0'
|
21
21
|
|
22
22
|
gem.add_development_dependency "rake"
|
23
23
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
load File.expand_path("../tasks/nginx.rake", __FILE__)
|
2
|
+
load File.expand_path("../tasks/unicorn.rake", __FILE__)
|
3
|
+
load File.expand_path("../tasks/logrotate.rake", __FILE__)
|
4
|
+
|
5
|
+
namespace :load do
|
6
|
+
task :defaults do
|
7
|
+
load 'capistrano/nginx_unicorn/defaults.rb'
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
set :templates_path, "config/deploy/templates"
|
2
|
+
set :nginx_server_name, -> { "localhost #{fetch(:application)}.local" }
|
3
|
+
set :nginx_config_name, -> { "#{fetch(:application)}_#{fetch(:stage)}" }
|
4
|
+
set :nginx_use_ssl, false
|
5
|
+
set :nginx_pid, "/run/nginx.pid"
|
6
|
+
set :nginx_ssl_certificate, -> { "#{fetch(:nginx_server_name)}.crt" }
|
7
|
+
set :nginx_ssl_certificate_key, -> { "#{fetch(:nginx_server_name)}.key" }
|
8
|
+
set :nginx_upload_local_certificate, true
|
9
|
+
set :nginx_ssl_certificate_local_path, -> { ask(:nginx_ssl_certificate_local_path, "Local path to ssl certificate: ") }
|
10
|
+
set :nginx_ssl_certificate_key_local_path, -> { ask(:nginx_ssl_certificate_key_local_path, "Local path to ssl certificate key: ") }
|
11
|
+
set :nginx_config_path, "/etc/nginx/sites-available"
|
12
|
+
|
13
|
+
set :unicorn_service_name, -> { "unicorn_#{fetch(:application)}_#{fetch(:stage)}" }
|
14
|
+
set :templates_path, "config/deploy/templates"
|
15
|
+
set :unicorn_pid, -> { shared_path.join("pids/unicorn.pid") }
|
16
|
+
set :unicorn_config, -> { shared_path.join("config/unicorn.rb") }
|
17
|
+
set :unicorn_log, -> { shared_path.join("log/unicorn.log") }
|
18
|
+
set :unicorn_user, -> { fetch(:user) }
|
19
|
+
set :unicorn_workers, 2
|
20
|
+
set :sudo, "sudo"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module NginxUnicorn
|
5
|
+
module Helpers
|
6
|
+
|
7
|
+
def template(template_name, target)
|
8
|
+
config_file = "#{fetch(:templates_path)}/#{template_name}"
|
9
|
+
# if no customized file, proceed with default
|
10
|
+
unless File.exists?(config_file)
|
11
|
+
config_file = File.join(File.dirname(__FILE__), "../../generators/capistrano/nginx_unicorn/templates/#{template_name}")
|
12
|
+
end
|
13
|
+
config_stream = StringIO.new(ERB.new(File.read(config_file)).result(binding))
|
14
|
+
upload! config_stream, target
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
namespace :logrotate do
|
2
|
+
desc "Setup logs rotation for nginx and unicorn"
|
3
|
+
task :setup do
|
4
|
+
on roles(:web, :app) do
|
5
|
+
logrotate_config = "#{fetch(:application)}_#{fetch(:stage)}"
|
6
|
+
|
7
|
+
template("logrotate.erb", "/tmp/#{logrotate_config}_logrotate")
|
8
|
+
sudo :mv, "/tmp/#{logrotate_config}_logrotate /etc/logrotate.d/#{logrotate_config}"
|
9
|
+
sudo :chown, "root:root", "/etc/logrotate.d/#{logrotate_config}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'capistrano/nginx_unicorn/helpers'
|
2
|
+
|
3
|
+
include Capistrano::NginxUnicorn::Helpers
|
4
|
+
|
5
|
+
namespace :nginx do
|
6
|
+
desc "Setup nginx configuration"
|
7
|
+
task :setup do
|
8
|
+
on roles(:web) do
|
9
|
+
execute :mkdir, "-p", shared_path.join("log")
|
10
|
+
template("nginx_conf.erb", "/tmp/nginx_#{fetch(:nginx_config_name)}")
|
11
|
+
if fetch(:nginx_config_path) == "/etc/nginx/sites-available"
|
12
|
+
sudo :mv, "/tmp/nginx_#{fetch(:nginx_config_name)} /etc/nginx/sites-available/#{fetch(:nginx_config_name)}"
|
13
|
+
sudo :ln, "-fs", "/etc/nginx/sites-available/#{fetch(:nginx_config_name)} /etc/nginx/sites-enabled/#{fetch(:nginx_config_name)}"
|
14
|
+
else
|
15
|
+
sudo :mv, "/tmp/#{fetch(:nginx_config_name)} #{fetch(:nginx_config_path)}/#{fetch(:nginx_config_name)}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Setup nginx ssl certs"
|
21
|
+
task :setup_ssl do
|
22
|
+
on roles(:web) do
|
23
|
+
if fetch(:nginx_use_ssl)
|
24
|
+
if fetch(:nginx_upload_local_certificate)
|
25
|
+
upload! fetch(:nginx_ssl_certificate_local_path), "/tmp/#{fetch(:nginx_ssl_certificate)}"
|
26
|
+
upload! fetch(:nginx_ssl_certificate_key_local_path), "/tmp/#{fetch(:nginx_ssl_certificate_key)}"
|
27
|
+
|
28
|
+
sudo :mv, "/tmp/#{fetch(:nginx_ssl_certificate)} /etc/ssl/certs/#{fetch(:nginx_ssl_certificate)}"
|
29
|
+
sudo :mv, "/tmp/#{fetch(:nginx_ssl_certificate_key)} /etc/ssl/private/#{fetch(:nginx_ssl_certificate_key)}"
|
30
|
+
end
|
31
|
+
|
32
|
+
sudo :chown, "root:root /etc/ssl/certs/#{fetch(:nginx_ssl_certificate)}"
|
33
|
+
sudo :chown, "root:root /etc/ssl/private/#{fetch(:nginx_ssl_certificate_key)}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Reload nginx configuration"
|
39
|
+
task :reload do
|
40
|
+
on roles(:web) do
|
41
|
+
sudo "/etc/init.d/nginx reload"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
namespace :deploy do
|
47
|
+
after :publishing, "nginx:reload"
|
48
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'capistrano/nginx_unicorn/helpers'
|
2
|
+
|
3
|
+
include Capistrano::NginxUnicorn::Helpers
|
4
|
+
|
5
|
+
namespace :unicorn do
|
6
|
+
desc "Setup Unicorn initializer"
|
7
|
+
task :setup_initializer do
|
8
|
+
on roles(:app) do
|
9
|
+
template "unicorn_init.erb", "/tmp/unicorn_init"
|
10
|
+
execute :chmod, "+x", "/tmp/unicorn_init"
|
11
|
+
sudo :mv, "/tmp/unicorn_init /etc/init.d/#{fetch(:unicorn_service_name)}"
|
12
|
+
sudo "update-rc.d -f #{fetch(:unicorn_service_name)} defaults"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Setup Unicorn app configuration"
|
17
|
+
task :setup_app_config do
|
18
|
+
on roles(:app) do
|
19
|
+
execute :mkdir, "-p", shared_path.join("config")
|
20
|
+
execute :mkdir, "-p", shared_path.join("log")
|
21
|
+
execute :mkdir, "-p", shared_path.join("pids")
|
22
|
+
template "unicorn.rb.erb", fetch(:unicorn_config)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
%w[start stop restart].each do |command|
|
27
|
+
desc "#{command} unicorn"
|
28
|
+
task command do
|
29
|
+
on roles(:app) do
|
30
|
+
sudo "service #{fetch(:unicorn_service_name)} #{command}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
namespace :deploy do
|
37
|
+
after :publishing, "unicorn:restart"
|
38
|
+
end
|
@@ -7,7 +7,7 @@
|
|
7
7
|
delaycompress
|
8
8
|
|
9
9
|
lastaction
|
10
|
-
pid=<%= unicorn_pid %>
|
10
|
+
pid=<%= fetch(:unicorn_pid) %>
|
11
11
|
test -s $pid && kill -USR1 "$(cat $pid)"
|
12
12
|
endscript
|
13
13
|
|
@@ -18,7 +18,7 @@
|
|
18
18
|
endscript
|
19
19
|
|
20
20
|
postrotate
|
21
|
-
nginx_pid=<%= nginx_pid %>
|
21
|
+
nginx_pid=<%= fetch(:nginx_pid) %>
|
22
22
|
[ ! -f $nginx_pid ] || kill -USR1 `cat $nginx_pid`
|
23
23
|
endscript
|
24
24
|
}
|
@@ -1,8 +1,8 @@
|
|
1
|
-
upstream unicorn_<%=
|
2
|
-
server unix:/tmp/unicorn.<%=
|
1
|
+
upstream unicorn_<%= fetch(:nginx_config_name) %> {
|
2
|
+
server unix:/tmp/unicorn.<%= fetch(:nginx_config_name) %>.sock fail_timeout=0;
|
3
3
|
}
|
4
4
|
|
5
|
-
<% if nginx_use_ssl %>
|
5
|
+
<% if fetch(:nginx_use_ssl) %>
|
6
6
|
server {
|
7
7
|
listen 80;
|
8
8
|
rewrite ^(.*) https://$host$1 permanent;
|
@@ -10,11 +10,11 @@ server {
|
|
10
10
|
<% end %>
|
11
11
|
|
12
12
|
server {
|
13
|
-
<% if nginx_use_ssl %>
|
13
|
+
<% if fetch(:nginx_use_ssl) %>
|
14
14
|
listen 443;
|
15
15
|
ssl on;
|
16
|
-
ssl_certificate /etc/ssl/certs/<%= nginx_ssl_certificate %>;
|
17
|
-
ssl_certificate_key /etc/ssl/private/<%= nginx_ssl_certificate_key %>;
|
16
|
+
ssl_certificate /etc/ssl/certs/<%= fetch(:nginx_ssl_certificate) %>;
|
17
|
+
ssl_certificate_key /etc/ssl/private/<%= fetch(:nginx_ssl_certificate_key) %>;
|
18
18
|
<% else %>
|
19
19
|
listen 80;
|
20
20
|
<% end %>
|
@@ -25,18 +25,18 @@ server {
|
|
25
25
|
error_page 500 502 504 /500.html;
|
26
26
|
error_page 503 @503;
|
27
27
|
|
28
|
-
server_name <%= nginx_server_name %>;
|
28
|
+
server_name <%= fetch(:nginx_server_name) %>;
|
29
29
|
root <%= current_path %>/public;
|
30
|
-
try_files $uri/index.html $uri @unicorn_<%=
|
30
|
+
try_files $uri/index.html $uri @unicorn_<%= fetch(:nginx_config_name) %>;
|
31
31
|
|
32
|
-
location @unicorn_<%=
|
32
|
+
location @unicorn_<%= fetch(:nginx_config_name) %> {
|
33
33
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
34
34
|
proxy_set_header Host $http_host;
|
35
35
|
proxy_redirect off;
|
36
|
-
<% if nginx_use_ssl %>
|
36
|
+
<% if fetch(:nginx_use_ssl) %>
|
37
37
|
proxy_set_header X-Forwarded-Proto https;
|
38
38
|
<% end %>
|
39
|
-
proxy_pass http://unicorn_<%=
|
39
|
+
proxy_pass http://unicorn_<%= fetch(:nginx_config_name) %>;
|
40
40
|
# limit_req zone=one;
|
41
41
|
access_log <%= shared_path %>/log/nginx.access.log;
|
42
42
|
error_log <%= shared_path %>/log/nginx.error.log;
|
@@ -1,10 +1,10 @@
|
|
1
1
|
working_directory "<%= current_path %>"
|
2
|
-
pid "<%= unicorn_pid %>"
|
3
|
-
stderr_path "<%= unicorn_log %>"
|
4
|
-
stdout_path "<%= unicorn_log %>"
|
2
|
+
pid "<%= fetch(:unicorn_pid) %>"
|
3
|
+
stderr_path "<%= fetch(:unicorn_log) %>"
|
4
|
+
stdout_path "<%= fetch(:unicorn_log) %>"
|
5
5
|
|
6
|
-
listen "/tmp/unicorn.<%=
|
7
|
-
worker_processes <%= unicorn_workers %>
|
6
|
+
listen "/tmp/unicorn.<%= fetch(:nginx_config_name) %>.sock"
|
7
|
+
worker_processes <%= fetch(:unicorn_workers) %>
|
8
8
|
timeout 30
|
9
9
|
|
10
10
|
preload_app true
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/bin/
|
1
|
+
#!/bin/bash
|
2
2
|
### BEGIN INIT INFO
|
3
3
|
# Provides: unicorn
|
4
4
|
# Required-Start: $remote_fs $syslog
|
@@ -13,11 +13,18 @@ set -e
|
|
13
13
|
# Feel free to change any of the following variables for your app:
|
14
14
|
TIMEOUT=${TIMEOUT-60}
|
15
15
|
APP_ROOT=<%= current_path %>
|
16
|
-
PID=<%= unicorn_pid %>
|
16
|
+
PID=<%= fetch(:unicorn_pid) %>
|
17
17
|
|
18
|
-
|
18
|
+
# no rvm and no rbenv
|
19
|
+
CMD="cd $APP_ROOT; bundle exec unicorn -D -c <%= fetch(:unicorn_config) %> -E <%= fetch(:rails_env) %>"
|
19
20
|
|
20
|
-
|
21
|
+
# rvm
|
22
|
+
#CMD="cd <%= current_path %>; <%= fetch(:rvm_path) %>/bin/rvm do bundle exec unicorn -D -c <%= fetch(:unicorn_config) %> -E <%= fetch(:rails_env) %>"
|
23
|
+
|
24
|
+
# rbenv TODO
|
25
|
+
# doesn't work CMD="cd <%= current_path %>; bundle exec unicorn -D -c <%= fetch(:unicorn_config) %> -E <%= fetch(:rails_env) %>"
|
26
|
+
|
27
|
+
AS_USER=<%= fetch(:unicorn_user) %>
|
21
28
|
set -u
|
22
29
|
|
23
30
|
OLD_PIN="$PID.oldbin"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-nginx-unicorn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.1.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Tkalin
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|
@@ -17,26 +17,26 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ~>
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '3.0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ~>
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
27
|
+
version: '3.0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - '>='
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '0'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - '>='
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
description: Capistrano tasks for configuration and management nginx+unicorn combo
|
@@ -49,14 +49,20 @@ extensions: []
|
|
49
49
|
extra_rdoc_files: []
|
50
50
|
files:
|
51
51
|
- .gitignore
|
52
|
+
- CHANGELOG.md
|
52
53
|
- Gemfile
|
53
54
|
- LICENSE.txt
|
54
55
|
- README.md
|
55
56
|
- Rakefile
|
56
57
|
- capistrano-nginx-unicorn.gemspec
|
57
58
|
- lib/capistrano-nginx-unicorn.rb
|
58
|
-
- lib/capistrano/nginx_unicorn
|
59
|
+
- lib/capistrano/nginx_unicorn.rb
|
60
|
+
- lib/capistrano/nginx_unicorn/defaults.rb
|
61
|
+
- lib/capistrano/nginx_unicorn/helpers.rb
|
59
62
|
- lib/capistrano/nginx_unicorn/version.rb
|
63
|
+
- lib/capistrano/tasks/logrotate.rake
|
64
|
+
- lib/capistrano/tasks/nginx.rake
|
65
|
+
- lib/capistrano/tasks/unicorn.rake
|
60
66
|
- lib/generators/capistrano/nginx_unicorn/USAGE
|
61
67
|
- lib/generators/capistrano/nginx_unicorn/config_generator.rb
|
62
68
|
- lib/generators/capistrano/nginx_unicorn/templates/logrotate.erb
|
@@ -72,14 +78,14 @@ require_paths:
|
|
72
78
|
- lib
|
73
79
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
80
|
requirements:
|
75
|
-
- -
|
81
|
+
- - '>='
|
76
82
|
- !ruby/object:Gem::Version
|
77
83
|
version: '0'
|
78
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
85
|
requirements:
|
80
|
-
- -
|
86
|
+
- - '>'
|
81
87
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
88
|
+
version: 1.3.1
|
83
89
|
requirements: []
|
84
90
|
rubyforge_project:
|
85
91
|
rubygems_version: 2.1.11
|
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'capistrano'
|
2
|
-
|
3
|
-
Capistrano::Configuration.instance.load do
|
4
|
-
def set_default(name, *args, &block)
|
5
|
-
set(name, *args, &block) unless exists?(name)
|
6
|
-
end
|
7
|
-
|
8
|
-
set_default(:templates_path, "config/deploy/templates")
|
9
|
-
|
10
|
-
set_default(:nginx_server_name) { Capistrano::CLI.ui.ask "Nginx server name: " }
|
11
|
-
set_default(:nginx_use_ssl, false)
|
12
|
-
set_default(:nginx_pid) { "/run/nginx.pid" }
|
13
|
-
set_default(:nginx_ssl_certificate) { "#{nginx_server_name}.crt" }
|
14
|
-
set_default(:nginx_ssl_certificate_key) { "#{nginx_server_name}.key" }
|
15
|
-
set_default(:nginx_upload_local_certificate) { true }
|
16
|
-
set_default(:nginx_ssl_certificate_local_path) {Capistrano::CLI.ui.ask "Local path to ssl certificate: "}
|
17
|
-
set_default(:nginx_ssl_certificate_key_local_path) {Capistrano::CLI.ui.ask "Local path to ssl certificate key: "}
|
18
|
-
|
19
|
-
set_default(:unicorn_pid) { "#{current_path}/tmp/pids/unicorn.pid" }
|
20
|
-
set_default(:unicorn_config) { "#{shared_path}/config/unicorn.rb" }
|
21
|
-
set_default(:unicorn_log) { "#{shared_path}/log/unicorn.log" }
|
22
|
-
set_default(:unicorn_user) { user }
|
23
|
-
set_default(:unicorn_workers) { Capistrano::CLI.ui.ask "Number of unicorn workers: " }
|
24
|
-
|
25
|
-
set_default(:nginx_config_path) { "/etc/nginx/sites-available" }
|
26
|
-
|
27
|
-
namespace :nginx do
|
28
|
-
desc "Setup nginx configuration for this application"
|
29
|
-
task :setup, roles: :web do
|
30
|
-
template("nginx_conf.erb", "/tmp/#{application}")
|
31
|
-
if nginx_config_path == "/etc/nginx/sites-available"
|
32
|
-
run "#{sudo} mv /tmp/#{application} /etc/nginx/sites-available/#{application}"
|
33
|
-
run "#{sudo} ln -fs /etc/nginx/sites-available/#{application} /etc/nginx/sites-enabled/#{application}"
|
34
|
-
else
|
35
|
-
run "#{sudo} mv /tmp/#{application} #{nginx_config_path}/#{application}.conf"
|
36
|
-
end
|
37
|
-
|
38
|
-
if nginx_use_ssl
|
39
|
-
if nginx_upload_local_certificate
|
40
|
-
put File.read(nginx_ssl_certificate_local_path), "/tmp/#{nginx_ssl_certificate}"
|
41
|
-
put File.read(nginx_ssl_certificate_key_local_path), "/tmp/#{nginx_ssl_certificate_key}"
|
42
|
-
|
43
|
-
run "#{sudo} mv /tmp/#{nginx_ssl_certificate} /etc/ssl/certs/#{nginx_ssl_certificate}"
|
44
|
-
run "#{sudo} mv /tmp/#{nginx_ssl_certificate_key} /etc/ssl/private/#{nginx_ssl_certificate_key}"
|
45
|
-
end
|
46
|
-
|
47
|
-
run "#{sudo} chown root:root /etc/ssl/certs/#{nginx_ssl_certificate}"
|
48
|
-
run "#{sudo} chown root:root /etc/ssl/private/#{nginx_ssl_certificate_key}"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
after "deploy:setup", "nginx:setup"
|
53
|
-
after "deploy:setup", "nginx:reload"
|
54
|
-
|
55
|
-
desc "Reload nginx configuration"
|
56
|
-
task :reload, roles: :web do
|
57
|
-
run "#{sudo} /etc/init.d/nginx reload"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
namespace :unicorn do
|
62
|
-
desc "Setup Unicorn initializer and app configuration"
|
63
|
-
task :setup, roles: :app do
|
64
|
-
run "mkdir -p #{shared_path}/config"
|
65
|
-
template "unicorn.rb.erb", unicorn_config
|
66
|
-
template "unicorn_init.erb", "/tmp/unicorn_init"
|
67
|
-
run "chmod +x /tmp/unicorn_init"
|
68
|
-
run "#{sudo} mv /tmp/unicorn_init /etc/init.d/unicorn_#{application}"
|
69
|
-
run "#{sudo} update-rc.d -f unicorn_#{application} defaults"
|
70
|
-
end
|
71
|
-
|
72
|
-
after "deploy:setup", "unicorn:setup"
|
73
|
-
|
74
|
-
%w[start stop restart].each do |command|
|
75
|
-
desc "#{command} unicorn"
|
76
|
-
task command, roles: :app do
|
77
|
-
run "service unicorn_#{application} #{command}"
|
78
|
-
end
|
79
|
-
|
80
|
-
after "deploy:#{command}", "unicorn:#{command}"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
desc "Setup logs rotation for nginx and unicorn"
|
85
|
-
task :logrotate, roles: [:web, :app] do
|
86
|
-
template("logrotate.erb", "/tmp/#{application}_logrotate")
|
87
|
-
run "#{sudo} mv /tmp/#{application}_logrotate /etc/logrotate.d/#{application}"
|
88
|
-
run "#{sudo} chown root:root /etc/logrotate.d/#{application}"
|
89
|
-
end
|
90
|
-
|
91
|
-
after "deploy:setup", "logrotate"
|
92
|
-
|
93
|
-
def template(template_name, target)
|
94
|
-
config_file = "#{templates_path}/#{template_name}"
|
95
|
-
# if no customized file, proceed with default
|
96
|
-
unless File.exists?(config_file)
|
97
|
-
config_file = File.join(File.dirname(__FILE__), "../../generators/capistrano/nginx_unicorn/templates/#{template_name}")
|
98
|
-
end
|
99
|
-
put ERB.new(File.read(config_file)).result(binding), target
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|