capistrano-simple-unicorn 0.0.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +36 -0
- data/lib/capistrano/simple_unicorn.rb +1 -0
- data/lib/capistrano/simple_unicorn/helpers.rb +9 -1
- data/lib/capistrano/simple_unicorn/version.rb +1 -1
- data/lib/capistrano/tasks/nginx.rake +35 -0
- data/lib/generators/capistrano/simple_unicorn/templates/nginx_conf.erb +57 -0
- data/lib/generators/{templates → capistrano/simple_unicorn/templates}/unicorn.rb.erb +0 -0
- data/lib/generators/{templates → capistrano/simple_unicorn/templates}/unicorn_init.erb +0 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f64084737f469cb0dcf81ff40b7c3c1130a0a450
|
4
|
+
data.tar.gz: af00481fadf86312dcb2d9c5b5fda7048151f96a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad68e3d32476967894822e35cd88b2dff20f75286635594d97d6cc3c65a07737091145160a5caa6561c97afad716cb1a1d477ddc6fd7986ac769d52148e00e6a
|
7
|
+
data.tar.gz: 6ad7e35e6e67762392178e557743c7e458ad18944b36c0c370b354ef47e1fa63569e3ce0fc3c53a749c22a7d7c3610b89828d27e30ba7a9fd5417c05a41cc86a
|
data/README.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# Capistrano::SimpleNginx
|
2
|
+
Support for Capistrano 3.x
|
3
|
+
|
1
4
|
Capistrano task for automatic and unicorn configuration
|
2
5
|
|
3
6
|
This gem customize from [capistrano-unicorn-nginx](https://github.com/capistrano-plugins/capistrano-unicorn-nginx), and support for Ubuntu server, CentOs server, EC2 server...
|
@@ -62,3 +65,36 @@ $ cap production unicorn:start
|
|
62
65
|
$ cap production unicorn:stop
|
63
66
|
$ cap production unicorn:restart
|
64
67
|
```
|
68
|
+
|
69
|
+
# Config nginx
|
70
|
+
|
71
|
+
* Generate file config nginx, run:
|
72
|
+
```
|
73
|
+
$ cap production nginx:setup
|
74
|
+
```
|
75
|
+
|
76
|
+
* start|stop|restart nginx, run:
|
77
|
+
```
|
78
|
+
$ cap production nginx:start
|
79
|
+
$ cap production nginx:stop
|
80
|
+
$ cap production nginx:restart
|
81
|
+
```
|
82
|
+
|
83
|
+
You need add directory to sock file of app. Example using unicorn for app:
|
84
|
+
```
|
85
|
+
# in config/deploy.rb
|
86
|
+
set :nginx_upstream_file, "/tmp/unicorn.sock"
|
87
|
+
```
|
88
|
+
|
89
|
+
## Default config
|
90
|
+
|
91
|
+
```
|
92
|
+
set :nginx_listen_port, 80 #listen_port
|
93
|
+
set :nginx_server_name, "_" #server_name
|
94
|
+
set :nginx_upstream_name, -> { "#{fetch(:application)}" } # upstream name
|
95
|
+
set :nginx_config_name, -> { "#{fetch(:application)}_#{fetch(:stage)}" } #file name config
|
96
|
+
set :nginx_fail_timeout, 0
|
97
|
+
set :nginx_access_log_file, -> { "/var/log/nginx/#{fetch(:nginx_config_name)}.access.log" } # access log file
|
98
|
+
set :nginx_error_log_file, -> { "/var/log/nginx/#{fetch(:nginx_config_name)}.error.log" } # error log file
|
99
|
+
set :nginx_upstream_file, -> { "#{fetch(:unicorn_sock_file)}" } # .sock file path
|
100
|
+
```
|
@@ -8,7 +8,7 @@ module Capistrano
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def template_to_s template_name
|
11
|
-
config_file = File.join(File.dirname(__FILE__), "../../generators/templates/#{template_name}")
|
11
|
+
config_file = File.join(File.dirname(__FILE__), "../../generators/capistrano/simple_unicorn/templates/#{template_name}")
|
12
12
|
ERB.new(File.read(config_file), nil, '-').result(binding)
|
13
13
|
end
|
14
14
|
|
@@ -32,6 +32,14 @@ module Capistrano
|
|
32
32
|
capture(:cat, "/etc/*-release").include? "ubuntu"
|
33
33
|
end
|
34
34
|
|
35
|
+
def nginx_config_file
|
36
|
+
if os_is_ubuntu?
|
37
|
+
"/etc/nginx/sites-available/#{fetch(:nginx_config_name)}.conf"
|
38
|
+
else
|
39
|
+
"/etc/nginx/conf.d/#{fetch(:nginx_config_name)}.conf"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
35
43
|
def unicorn_initd_file
|
36
44
|
"/etc/init.d/#{fetch(:unicorn_service)}"
|
37
45
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'capistrano/simple_unicorn/helpers'
|
2
|
+
include Capistrano::SimpleUnicorn::Helpers
|
3
|
+
|
4
|
+
namespace :load do
|
5
|
+
task :defaults do
|
6
|
+
set :nginx_listen_port, 80
|
7
|
+
set :nginx_server_name, "_"
|
8
|
+
set :nginx_upstream_name, -> { "#{fetch(:application)}" }
|
9
|
+
set :nginx_config_name, -> { "#{fetch(:application)}_#{fetch(:stage)}" }
|
10
|
+
set :nginx_fail_timeout, 0
|
11
|
+
set :nginx_access_log_file, -> { "/var/log/nginx/#{fetch(:nginx_config_name)}.access.log" }
|
12
|
+
set :nginx_error_log_file, -> { "/var/log/nginx/#{fetch(:nginx_config_name)}.error.log" }
|
13
|
+
set :nginx_upstream_file, -> { "#{fetch(:unicorn_sock_file)}" }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
namespace :nginx do
|
18
|
+
desc 'Setup nginx configuration'
|
19
|
+
task :setup do
|
20
|
+
on roles :web do
|
21
|
+
unless file_exists?(nginx_config_file)
|
22
|
+
sudo_upload! template('nginx_conf.erb'), nginx_config_file
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
%w[stop start restart reload].each do |action|
|
28
|
+
desc "#{action} nginx"
|
29
|
+
task action do
|
30
|
+
on roles :web do
|
31
|
+
sudo :service, "nginx", action
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
upstream <%= fetch(:nginx_upstream_name) %> {
|
2
|
+
server unix:<%= fetch(:nginx_upstream_file) %> fail_timeout=<%= fetch(:nginx_fail_timeout) %>;
|
3
|
+
}
|
4
|
+
|
5
|
+
server {
|
6
|
+
server_tokens off;
|
7
|
+
add_header X-Content-Type-Options nosniff;
|
8
|
+
client_max_body_size 4G;
|
9
|
+
keepalive_timeout 10;
|
10
|
+
|
11
|
+
error_page 500 502 504 /500.html;
|
12
|
+
error_page 503 @503;
|
13
|
+
|
14
|
+
server_name <%= fetch(:nginx_server_name) %>;
|
15
|
+
root <%= current_path %>/public;
|
16
|
+
try_files $uri/index.html $uri @<%= fetch(:nginx_upstream_name) %>;
|
17
|
+
|
18
|
+
location @<%= fetch(:nginx_upstream_name) %> {
|
19
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
20
|
+
proxy_set_header Host $http_host;
|
21
|
+
proxy_redirect off;
|
22
|
+
proxy_pass http://<%= fetch(:nginx_upstream_name) %>;
|
23
|
+
|
24
|
+
access_log <%= fetch(:nginx_access_log_file) %>;
|
25
|
+
error_log <%= fetch(:nginx_error_log_file) %>;
|
26
|
+
}
|
27
|
+
|
28
|
+
location ^~ /assets/ {
|
29
|
+
gzip_static on;
|
30
|
+
expires max;
|
31
|
+
add_header Cache-Control public;
|
32
|
+
}
|
33
|
+
|
34
|
+
location = /50x.html {
|
35
|
+
root html;
|
36
|
+
}
|
37
|
+
|
38
|
+
location = /404.html {
|
39
|
+
root html;
|
40
|
+
}
|
41
|
+
|
42
|
+
location @503 {
|
43
|
+
error_page 405 = /system/maintenance.html;
|
44
|
+
if (-f $document_root/system/maintenance.html) {
|
45
|
+
rewrite ^(.*)$ /system/maintenance.html break;
|
46
|
+
}
|
47
|
+
rewrite ^(.*)$ /503.html break;
|
48
|
+
}
|
49
|
+
|
50
|
+
if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){
|
51
|
+
return 405;
|
52
|
+
}
|
53
|
+
|
54
|
+
if (-f $document_root/system/maintenance.html) {
|
55
|
+
return 503;
|
56
|
+
}
|
57
|
+
}
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-simple-unicorn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- truongkma
|
@@ -71,9 +71,11 @@ files:
|
|
71
71
|
- lib/capistrano/simple_unicorn.rb
|
72
72
|
- lib/capistrano/simple_unicorn/helpers.rb
|
73
73
|
- lib/capistrano/simple_unicorn/version.rb
|
74
|
+
- lib/capistrano/tasks/nginx.rake
|
74
75
|
- lib/capistrano/tasks/unicorn.rake
|
75
|
-
- lib/generators/templates/
|
76
|
-
- lib/generators/templates/
|
76
|
+
- lib/generators/capistrano/simple_unicorn/templates/nginx_conf.erb
|
77
|
+
- lib/generators/capistrano/simple_unicorn/templates/unicorn.rb.erb
|
78
|
+
- lib/generators/capistrano/simple_unicorn/templates/unicorn_init.erb
|
77
79
|
homepage: https://github.com/truongkma/capistrano-simple-unicorn
|
78
80
|
licenses:
|
79
81
|
- MIT
|