greenonline_capistrano_recipes 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/greenonline/capistrano_recipes/version.rb +1 -1
- data/lib/greenonline/recipes/nginx.rb +4 -0
- data/lib/greenonline/recipes/templates/nginx_unicorn.erb +54 -1
- data/lib/greenonline/recipes/templates/unicorn.rb.erb +2 -2
- data/lib/greenonline/recipes/templates/unicorn_init.erb +59 -12
- 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: fc06dc50871c7fa243d970197926fa3d5ac8037d
|
4
|
+
data.tar.gz: 9def24afcf5b8393f9df18cbb34df0a7e32aa546
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2864957e512235f7a62d08fd112d52ca724e46b92e20d0196c1aa0a77122724038be3a7923bea6090814c9b67e532f60e692e383c3c995e672ebac7627fb008e
|
7
|
+
data.tar.gz: 353c46b12cea3741c15df53dcea7af8bb0a58862cf1732517a756a369d113c6f0d5e31a912fef2303e341e6a11c47c43483f0b57adfcae3bb3085f15aeaf4108
|
@@ -1,6 +1,10 @@
|
|
1
1
|
module Capistrano
|
2
2
|
Configuration.instance(true).load do
|
3
3
|
set_default(:nginx_server_name, nil)
|
4
|
+
set_default(:nginx_ssl_enabled, false)
|
5
|
+
set_default(:nginx_ssl_path, '/etc/ssl/')
|
6
|
+
set_default(:nginx_ssl_key, nil)
|
7
|
+
set_default(:nginx_ssl_certificate, nil)
|
4
8
|
|
5
9
|
namespace :nginx do
|
6
10
|
desc "update latest nginx configuration"
|
@@ -50,4 +50,57 @@ server {
|
|
50
50
|
error_page 500 502 503 504 /500.html;
|
51
51
|
client_max_body_size 4G;
|
52
52
|
keepalive_timeout 10;
|
53
|
-
}
|
53
|
+
}
|
54
|
+
|
55
|
+
<% if nginx_ssl_enabled %>
|
56
|
+
server {
|
57
|
+
listen 443;
|
58
|
+
|
59
|
+
ssl on;
|
60
|
+
ssl_certificate <%= nginx_ssl_path %><%= nginx_ssl_certificate %>;
|
61
|
+
ssl_certificate_key <%= nginx_ssl_path %><%= nginx_ssl_key %>;
|
62
|
+
|
63
|
+
<% if nginx_server_name %>
|
64
|
+
server_name <%= nginx_server_name %>;
|
65
|
+
<% end %>
|
66
|
+
root <%= current_path %>/public;
|
67
|
+
|
68
|
+
location ^~ /assets/ {
|
69
|
+
gzip_static on;
|
70
|
+
expires max;
|
71
|
+
add_header Cache-Control public;
|
72
|
+
}
|
73
|
+
|
74
|
+
if (-f $document_root/maintenance.html) {
|
75
|
+
rewrite ^(.*)$ /maintenance.html last;
|
76
|
+
break;
|
77
|
+
}
|
78
|
+
|
79
|
+
try_files $uri/index.html $uri @unicorn;
|
80
|
+
|
81
|
+
location @unicorn {
|
82
|
+
proxy_set_header X-Forwarded-Proto https;
|
83
|
+
# an HTTP header important enough to have its own Wikipedia entry:
|
84
|
+
# http://en.wikipedia.org/wiki/X-Forwarded-For
|
85
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
86
|
+
|
87
|
+
# enable this if you forward HTTPS traffic to unicorn,
|
88
|
+
# this helps Rack set the proper URL scheme for doing redirects:
|
89
|
+
# proxy_set_header X-Forwarded-Proto $scheme;
|
90
|
+
|
91
|
+
# pass the Host: header from the client right along so redirects
|
92
|
+
# can be set properly within the Rack application
|
93
|
+
proxy_set_header Host $http_host;
|
94
|
+
|
95
|
+
# we don't want nginx trying to do something clever with
|
96
|
+
# redirects, we set the Host: header above already.
|
97
|
+
proxy_redirect off;
|
98
|
+
|
99
|
+
proxy_pass http://unicorn_<%= application.downcase %>_<%= stage %>;
|
100
|
+
}
|
101
|
+
|
102
|
+
error_page 500 502 503 504 /500.html;
|
103
|
+
client_max_body_size 4G;
|
104
|
+
keepalive_timeout 10;
|
105
|
+
}
|
106
|
+
<% end %>
|
@@ -29,8 +29,8 @@ before_fork do |server, worker|
|
|
29
29
|
# we send it a QUIT.
|
30
30
|
#
|
31
31
|
# Using this method we get 0 downtime deploys.
|
32
|
-
|
33
|
-
old_pid =
|
32
|
+
|
33
|
+
old_pid = '<%= unicorn_pid %>.oldbin'
|
34
34
|
if File.exists?(old_pid) && server.pid != old_pid
|
35
35
|
begin
|
36
36
|
Process.kill("QUIT", File.read(old_pid).to_i)
|
@@ -20,14 +20,16 @@ CMD="<%= current_path %>/bin/unicorn -D -c <%= unicorn_config %> -E <%= stage %>
|
|
20
20
|
AS_USER=<%= unicorn_user %>
|
21
21
|
set -u
|
22
22
|
|
23
|
-
|
23
|
+
OLD_PID="$PID.oldbin"
|
24
|
+
|
25
|
+
cd $APP_ROOT || exit 1
|
24
26
|
|
25
27
|
sig () {
|
26
28
|
test -s "$PID" && kill -$1 `cat $PID`
|
27
29
|
}
|
28
30
|
|
29
31
|
oldsig () {
|
30
|
-
test -s $
|
32
|
+
test -s $OLD_PID && kill -$1 `cat $OLD_PID`
|
31
33
|
}
|
32
34
|
|
33
35
|
run () {
|
@@ -38,44 +40,89 @@ run () {
|
|
38
40
|
fi
|
39
41
|
}
|
40
42
|
|
43
|
+
workersig () {
|
44
|
+
workerpid="<%= current_path %>/tmp/pids/unicorn.worker.$2.pid"
|
45
|
+
test -s "$workerpid" && kill -$1 `cat $workerpid`
|
46
|
+
}
|
47
|
+
|
41
48
|
case "$1" in
|
42
49
|
start)
|
43
|
-
sig 0 && echo >&2 "
|
50
|
+
sig 0 && echo >&2 "Start failed: Unicorn already running! Exiting!" && exit 0
|
51
|
+
echo "Starting: "
|
44
52
|
run "$CMD"
|
45
53
|
;;
|
46
54
|
stop)
|
47
55
|
sig QUIT && exit 0
|
48
|
-
echo >&2 "
|
56
|
+
echo >&2 "Stop failed: Unicorn isn't running."
|
49
57
|
;;
|
50
58
|
force-stop)
|
51
59
|
sig TERM && exit 0
|
52
|
-
echo >&2 "
|
60
|
+
echo >&2 "Force-stop failed: Unicorn isn't running"
|
53
61
|
;;
|
54
62
|
restart|reload)
|
55
63
|
sig HUP && echo reloaded OK && exit 0
|
56
|
-
echo >&2 "
|
64
|
+
echo >&2 "Reload failed: executing '$CMD' "
|
57
65
|
run "$CMD"
|
58
66
|
;;
|
59
67
|
upgrade)
|
60
|
-
if
|
68
|
+
if test -s $PID; then ORIG_PID=`cat $PID`; else ORIG_PID=0; fi
|
69
|
+
|
70
|
+
echo 'Original PID: ' $ORIG_PID
|
71
|
+
|
72
|
+
if sig USR2
|
61
73
|
then
|
74
|
+
echo 'USR2 sent; Waiting for .oldbin'
|
62
75
|
n=$TIMEOUT
|
63
|
-
|
76
|
+
|
77
|
+
#wait for .oldpid to be written
|
78
|
+
while (!(test -s $OLD_PID) && test $n -ge 0)
|
79
|
+
do
|
80
|
+
printf '.' && sleep 1 && n=$(( $n - 1 ))
|
81
|
+
done
|
82
|
+
|
83
|
+
echo 'Waiting for new pid file'
|
84
|
+
#when this loop finishes, should have new pid file
|
85
|
+
while (!(test -s $PID ) || test -s $OLD_PID) && test $n -ge 0
|
64
86
|
do
|
65
87
|
printf '.' && sleep 1 && n=$(( $n - 1 ))
|
66
88
|
done
|
67
|
-
echo
|
68
89
|
|
69
|
-
if test
|
90
|
+
if test -s $PID
|
70
91
|
then
|
71
|
-
|
92
|
+
NEW_PID=`cat $PID`
|
93
|
+
else
|
94
|
+
echo 'New master failed to start; see error log'
|
72
95
|
exit 1
|
73
96
|
fi
|
97
|
+
|
98
|
+
#timeout has elapsed, verify new pid file exists
|
99
|
+
if [ $ORIG_PID -eq $NEW_PID ]
|
100
|
+
then
|
101
|
+
echo
|
102
|
+
echo >&2 'New master failed to start; see error log'
|
103
|
+
exit 1
|
104
|
+
fi
|
105
|
+
|
106
|
+
echo 'New PID: ' $NEW_PID
|
107
|
+
|
108
|
+
#verify old master QUIT
|
109
|
+
echo
|
110
|
+
if test -s $OLD_PID
|
111
|
+
then
|
112
|
+
echo >&2 "$OLD_PID still exists after $TIMEOUT seconds"
|
113
|
+
exit 1
|
114
|
+
fi
|
115
|
+
|
116
|
+
printf 'Unicorn successfully upgraded'
|
74
117
|
exit 0
|
75
118
|
fi
|
76
|
-
echo >&2 "
|
119
|
+
echo >&2 "Upgrade failed: executing '$CMD' "
|
77
120
|
run "$CMD"
|
78
121
|
;;
|
122
|
+
kill_worker)
|
123
|
+
workersig QUIT $2 && exit 0
|
124
|
+
echo >&2 "Kill Worker failed: worker not running"
|
125
|
+
;;
|
79
126
|
reopen-logs)
|
80
127
|
sig USR1
|
81
128
|
;;
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: greenonline_capistrano_recipes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pieter Visser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|