axtro-rubber 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/generators/vulcanize/templates/mysql/config/rubber/rubber-mysql.yml +1 -1
- data/generators/vulcanize/templates/nginx_frontend/config/rubber/deploy-nginx_frontend.rb +85 -0
- data/generators/vulcanize/templates/nginx_frontend/config/rubber/role/nginx_frontend/logrotate-nginx_frontend +14 -0
- data/generators/vulcanize/templates/nginx_frontend/config/rubber/role/nginx_frontend/monit-nginx_frontend.conf +8 -0
- data/generators/vulcanize/templates/nginx_frontend/config/rubber/role/nginx_frontend/nginx.conf +50 -0
- data/generators/vulcanize/templates/nginx_frontend/config/rubber/role/nginx_frontend/nginx_frontend +366 -0
- data/generators/vulcanize/templates/nginx_frontend/config/rubber/role/web_tools/nginx-tools.conf +55 -0
- data/generators/vulcanize/templates/nginx_frontend/config/rubber/role/web_tools/tools-index.html +30 -0
- data/generators/vulcanize/templates/nginx_frontend/config/rubber/role/web_tools/tools-nginx.auth +7 -0
- data/generators/vulcanize/templates/nginx_frontend/config/rubber/rubber-nginx_frontend.yml +22 -0
- data/generators/vulcanize/templates/nginx_frontend/templates.yml +1 -0
- data/generators/vulcanize/templates/unicorn/config/rubber/deploy-unicorn.rb +43 -0
- data/generators/vulcanize/templates/unicorn/config/rubber/role/nginx_frontend/unicorn_nginx_server.conf +90 -0
- data/generators/vulcanize/templates/unicorn/config/rubber/role/unicorn/logrotate-unicorn +16 -0
- data/generators/vulcanize/templates/unicorn/config/rubber/role/unicorn/monit-unicorn.conf +10 -0
- data/generators/vulcanize/templates/unicorn/config/rubber/role/unicorn/unicorn +327 -0
- data/generators/vulcanize/templates/unicorn/config/rubber/role/unicorn/unicorn.conf +86 -0
- data/generators/vulcanize/templates/unicorn/config/rubber/rubber-unicorn.yml +13 -0
- metadata +30 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.1
|
@@ -0,0 +1,85 @@
|
|
1
|
+
|
2
|
+
namespace :rubber do
|
3
|
+
|
4
|
+
namespace :nginx_frontend do
|
5
|
+
|
6
|
+
rubber.allow_optional_tasks(self)
|
7
|
+
|
8
|
+
after "rubber:install_packages", "rubber:nginx_frontend:custom_install"
|
9
|
+
|
10
|
+
task :custom_install, :roles => :nginx_frontend do
|
11
|
+
# install nginx from source
|
12
|
+
ver = rubber_env.nginx_frontend_version
|
13
|
+
rubber.run_script 'install_sphinx', <<-ENDSCRIPT
|
14
|
+
# check if already installed
|
15
|
+
if [ -x /usr/local/sbin/nginx ]
|
16
|
+
then echo 'Found nginx on system'
|
17
|
+
if /usr/local/sbin/nginx -v | grep 'nginx/#{ver}'
|
18
|
+
then echo 'Nginx version matches, no further steps needed'
|
19
|
+
exit 0
|
20
|
+
fi
|
21
|
+
fi
|
22
|
+
|
23
|
+
echo 'Installing / Upgrading nginx #{ver}'
|
24
|
+
TMPDIR=`mktemp -d` || exit 1
|
25
|
+
cd $TMPDIR
|
26
|
+
echo 'Downloading'
|
27
|
+
wget -qN http://sysoev.ru/nginx/nginx-#{ver}.tar.gz
|
28
|
+
echo 'Unpacking'
|
29
|
+
tar xf nginx-#{ver}.tar.gz
|
30
|
+
cd nginx-#{ver}
|
31
|
+
./configure \
|
32
|
+
--with-http_ssl_module \
|
33
|
+
--with-http_stub_status_module \
|
34
|
+
--conf-path=/etc/nginx_frontend/nginx.conf \
|
35
|
+
--error-log-path=/var/log/nginx_frontend/error.log \
|
36
|
+
--pid-path=/var/run/nginx_frontend.pid \
|
37
|
+
--lock-path=/var/lock/nginx_frontend.lock \
|
38
|
+
--http-log-path=/var/log/nginx_frontend/access.log \
|
39
|
+
--http-client-body-temp-path=/var/lib/nginx_frontend/body \
|
40
|
+
--http-proxy-temp-path=/var/lib/nginx_frontend/proxy \
|
41
|
+
--http-fastcgi-temp-path=/var/lib/nginx_frontend/fastcgi
|
42
|
+
make
|
43
|
+
make install
|
44
|
+
cd ; rm -rf $TMPDIR
|
45
|
+
ENDSCRIPT
|
46
|
+
end
|
47
|
+
|
48
|
+
# serial_task can only be called after roles defined - not normally a problem, but
|
49
|
+
# rubber auto-roles don't get defined till after all tasks are defined
|
50
|
+
on :load do
|
51
|
+
rubber.serial_task self, :serial_restart, :roles => :nginx_frontend do
|
52
|
+
run "/etc/init.d/nginx_frontend restart"
|
53
|
+
end
|
54
|
+
rubber.serial_task self, :serial_reload, :roles => :nginx_frontend do
|
55
|
+
run "if ! ps ax | grep -v grep | grep -c nginx &> /dev/null; then /etc/init.d/nginx_frontend start; else /etc/init.d/nginx_frontend reload; fi"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
before "deploy:stop", "rubber:nginx_frontend:stop"
|
60
|
+
after "deploy:start", "rubber:nginx_frontend:start"
|
61
|
+
after "deploy:restart", "rubber:nginx_frontend:reload"
|
62
|
+
|
63
|
+
desc "Stops the nginx web server"
|
64
|
+
task :stop, :roles => :nginx_frontend, :on_error => :continue do
|
65
|
+
run "/etc/init.d/nginx_frontend stop"
|
66
|
+
end
|
67
|
+
|
68
|
+
desc "Starts the nginx web server"
|
69
|
+
task :start, :roles => :nginx_frontend do
|
70
|
+
run "/etc/init.d/nginx_frontend start"
|
71
|
+
end
|
72
|
+
|
73
|
+
desc "Restarts the nginx web server"
|
74
|
+
task :restart, :roles => :nginx_frontend do
|
75
|
+
serial_restart
|
76
|
+
end
|
77
|
+
|
78
|
+
desc "Reloads the nginx web server"
|
79
|
+
task :reload, :roles => :nginx_frontend do
|
80
|
+
serial_reload
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<%
|
2
|
+
@path = "/etc/logrotate.d/nginx_frontend"
|
3
|
+
@no_backup = true
|
4
|
+
-%>
|
5
|
+
/mnt/log/nginx_frontend/*.log {
|
6
|
+
daily
|
7
|
+
missingok
|
8
|
+
dateext
|
9
|
+
create 640 root root
|
10
|
+
sharedscripts
|
11
|
+
postrotate
|
12
|
+
[ ! -f /var/run/nginx_frontend.pid ] || kill -USR1 `cat /var/run/nginx_frontend.pid`
|
13
|
+
endscript
|
14
|
+
}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<%
|
2
|
+
@path = '/etc/monit/monit.d/monit-nginx.conf'
|
3
|
+
%>
|
4
|
+
<% PIDFILE = "/var/run/nginx_frontend.pid" %>
|
5
|
+
check process nginx with pidfile <%= PIDFILE %>
|
6
|
+
group nginx-<%= RUBBER_ENV %>
|
7
|
+
start program = "/etc/init.d/nginx start"
|
8
|
+
stop program = "/etc/init.d/nginx stop"
|
data/generators/vulcanize/templates/nginx_frontend/config/rubber/role/nginx_frontend/nginx.conf
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
<%
|
2
|
+
@path = "/etc/nginx_frontend/nginx.conf"
|
3
|
+
@post = "mkdir -p /mnt/nginx_frontend/logs"
|
4
|
+
-%>
|
5
|
+
user www-data www-data;
|
6
|
+
|
7
|
+
worker_processes <%= rubber_env.nginx_frontend_workers %>;
|
8
|
+
|
9
|
+
error_log /mnt/log/nginx_frontend/error.log;
|
10
|
+
|
11
|
+
#pid logs/nginx.pid;
|
12
|
+
|
13
|
+
|
14
|
+
events {
|
15
|
+
worker_connections <%= rubber_env.nginx_worker_connections %>;
|
16
|
+
accept_mutex <%= rubber_env.nginx_frontend_workers > 1 ? "on" : "off" %>;
|
17
|
+
use epoll; # enable for Linux 2.6+
|
18
|
+
}
|
19
|
+
|
20
|
+
|
21
|
+
http {
|
22
|
+
include mime.types;
|
23
|
+
default_type application/octet-stream;
|
24
|
+
|
25
|
+
# Like Apache's combined format but including the forwarded for header
|
26
|
+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
27
|
+
'$status $body_bytes_sent "$http_referer" '
|
28
|
+
'"$http_user_agent" "$http_x_forwarded_for"';
|
29
|
+
|
30
|
+
access_log /mnt/log/nginx_frontend/access.log main;
|
31
|
+
|
32
|
+
sendfile on;
|
33
|
+
tcp_nopush on; # off may be better for *some* Comet/long-poll stuff
|
34
|
+
tcp_nodelay off; # on may be better for some Comet/long-poll stuff
|
35
|
+
|
36
|
+
|
37
|
+
keepalive_timeout <%= rubber_env.nginx_frontend_keepalive_timeout %>;
|
38
|
+
|
39
|
+
gzip on;
|
40
|
+
gzip_http_version 1.0;
|
41
|
+
gzip_proxied any;
|
42
|
+
gzip_min_length 500;
|
43
|
+
gzip_disable "MSIE [1-6]\.";
|
44
|
+
gzip_types text/plain text/html text/xml text/css
|
45
|
+
text/comma-separated-values
|
46
|
+
text/javascript application/x-javascript application/javascript
|
47
|
+
application/atom+xml;
|
48
|
+
|
49
|
+
include /etc/nginx/rubber/*.conf;
|
50
|
+
}
|
data/generators/vulcanize/templates/nginx_frontend/config/rubber/role/nginx_frontend/nginx_frontend
ADDED
@@ -0,0 +1,366 @@
|
|
1
|
+
<%
|
2
|
+
@path = "/etc/init.d/nginx_frontend"
|
3
|
+
-%>
|
4
|
+
#! /bin/sh
|
5
|
+
### BEGIN INIT INFO
|
6
|
+
# Provides: nginx_frontend
|
7
|
+
# Required-Start: $remote_fs $syslog
|
8
|
+
# Required-Stop: $remote_fs $syslog
|
9
|
+
# Default-Start: 2 3 4 5
|
10
|
+
# Default-Stop: 0 1 6
|
11
|
+
# Short-Description: nginx init.d dash script for Ubuntu <=9.10.
|
12
|
+
# Description: nginx init.d dash script for Ubuntu <=9.10.
|
13
|
+
### END INIT INFO
|
14
|
+
#------------------------------------------------------------------------------
|
15
|
+
# nginx - this Debian Almquist shell (dash) script, starts and stops the nginx
|
16
|
+
# daemon for ubuntu 9.10 and lesser version numbered releases.
|
17
|
+
#
|
18
|
+
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
|
19
|
+
# proxy and IMAP/POP3 proxy server. This \
|
20
|
+
# script will manage the initiation of the \
|
21
|
+
# server and it's process state.
|
22
|
+
#
|
23
|
+
# processname: nginx
|
24
|
+
# config: /etc/nginx_frontend/nginx.conf
|
25
|
+
# pidfile: /var/run/nginx_frontend.pid
|
26
|
+
# Provides: nginx_frontend
|
27
|
+
#
|
28
|
+
# Author: Jason Giedymin
|
29
|
+
# <jason.giedymin AT gmail.com>.
|
30
|
+
#
|
31
|
+
# Version: 2.0 02-NOV-2009 jason.giedymin AT gmail.com
|
32
|
+
# Notes: nginx init.d dash script for Ubuntu <=9.10.
|
33
|
+
#
|
34
|
+
# This script's project home is:
|
35
|
+
# http://code.google.com/p/nginx-init-ubuntu/
|
36
|
+
#
|
37
|
+
#------------------------------------------------------------------------------
|
38
|
+
# MIT X11 License
|
39
|
+
#------------------------------------------------------------------------------
|
40
|
+
#
|
41
|
+
# Copyright (c) 2009 Jason Giedymin, http://Amuxbit.com formerly
|
42
|
+
# http://AcronymLabs.com
|
43
|
+
#
|
44
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
45
|
+
# a copy of this software and associated documentation files (the
|
46
|
+
# "Software"), to deal in the Software without restriction, including
|
47
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
48
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
49
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
50
|
+
# the following conditions:
|
51
|
+
#
|
52
|
+
# The above copyright notice and this permission notice shall be
|
53
|
+
# included in all copies or substantial portions of the Software.
|
54
|
+
#
|
55
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
56
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
57
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
58
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
59
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
60
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
61
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
62
|
+
#------------------------------------------------------------------------------
|
63
|
+
|
64
|
+
#------------------------------------------------------------------------------
|
65
|
+
# Functions
|
66
|
+
#------------------------------------------------------------------------------
|
67
|
+
. /lib/lsb/init-functions
|
68
|
+
|
69
|
+
#------------------------------------------------------------------------------
|
70
|
+
# Consts
|
71
|
+
#------------------------------------------------------------------------------
|
72
|
+
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
73
|
+
DAEMON=/usr/local/sbin/nginx
|
74
|
+
|
75
|
+
PS="nginx"
|
76
|
+
PIDNAME="nginx_frontend" #lets you do $PS-slave
|
77
|
+
PIDFILE=$PIDNAME.pid #pid file
|
78
|
+
PIDSPATH=/var/run
|
79
|
+
|
80
|
+
DESCRIPTION="Nginx Server..."
|
81
|
+
|
82
|
+
RUNAS=root #user to run as
|
83
|
+
|
84
|
+
SCRIPT_OK=0 #ala error codes
|
85
|
+
SCRIPT_ERROR=1 #ala error codes
|
86
|
+
TRUE=1 #boolean
|
87
|
+
FALSE=0 #boolean
|
88
|
+
|
89
|
+
lockfile=/var/lock/nginx_frontend
|
90
|
+
NGINX_CONF_FILE="/etc/nginx_frontend/nginx.conf"
|
91
|
+
|
92
|
+
#------------------------------------------------------------------------------
|
93
|
+
# Simple Tests
|
94
|
+
#------------------------------------------------------------------------------
|
95
|
+
|
96
|
+
#test if nginx is a file and executable
|
97
|
+
test -x $DAEMON || exit 0
|
98
|
+
|
99
|
+
# Include nginx defaults if available
|
100
|
+
if [ -f /etc/default/nginx_frontend ] ; then
|
101
|
+
. /etc/default/nginx_frontend
|
102
|
+
fi
|
103
|
+
|
104
|
+
#set exit condition
|
105
|
+
#set -e
|
106
|
+
|
107
|
+
#------------------------------------------------------------------------------
|
108
|
+
# Functions
|
109
|
+
#------------------------------------------------------------------------------
|
110
|
+
|
111
|
+
setFilePerms(){
|
112
|
+
|
113
|
+
if [ -f $PIDSPATH/$PIDFILE ]; then
|
114
|
+
chmod 400 $PIDSPATH/$PIDFILE
|
115
|
+
fi
|
116
|
+
}
|
117
|
+
|
118
|
+
configtest() {
|
119
|
+
$DAEMON -t -c $NGINX_CONF_FILE
|
120
|
+
}
|
121
|
+
|
122
|
+
getPSCount() {
|
123
|
+
return `pgrep -f $PS | wc -l`
|
124
|
+
}
|
125
|
+
|
126
|
+
isRunning() {
|
127
|
+
if [ $1 ]; then
|
128
|
+
pidof_daemon $1
|
129
|
+
PID=$?
|
130
|
+
|
131
|
+
if [ $PID -gt 0 ]; then
|
132
|
+
return 1
|
133
|
+
else
|
134
|
+
return 0
|
135
|
+
fi
|
136
|
+
else
|
137
|
+
pidof_daemon
|
138
|
+
PID=$?
|
139
|
+
|
140
|
+
if [ $PID -gt 0 ]; then
|
141
|
+
return 1
|
142
|
+
else
|
143
|
+
return 0
|
144
|
+
fi
|
145
|
+
fi
|
146
|
+
}
|
147
|
+
|
148
|
+
#courtesy of php-fpm
|
149
|
+
wait_for_pid () {
|
150
|
+
try=0
|
151
|
+
|
152
|
+
while test $try -lt 35 ; do
|
153
|
+
|
154
|
+
case "$1" in
|
155
|
+
'created')
|
156
|
+
if [ -f "$2" ] ; then
|
157
|
+
try=''
|
158
|
+
break
|
159
|
+
fi
|
160
|
+
;;
|
161
|
+
|
162
|
+
'removed')
|
163
|
+
if [ ! -f "$2" ] ; then
|
164
|
+
try=''
|
165
|
+
break
|
166
|
+
fi
|
167
|
+
;;
|
168
|
+
esac
|
169
|
+
|
170
|
+
#echo -n .
|
171
|
+
try=`expr $try + 1`
|
172
|
+
sleep 1
|
173
|
+
done
|
174
|
+
}
|
175
|
+
|
176
|
+
status(){
|
177
|
+
isRunning
|
178
|
+
isAlive=$?
|
179
|
+
|
180
|
+
if [ "${isAlive}" -eq $TRUE ]; then
|
181
|
+
echo "$PIDNAME found running with processes: `pidof $PS`"
|
182
|
+
else
|
183
|
+
echo "$PIDNAME is NOT running."
|
184
|
+
fi
|
185
|
+
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
removePIDFile(){
|
190
|
+
if [ $1 ]; then
|
191
|
+
if [ -f $1 ]; then
|
192
|
+
rm -f $1
|
193
|
+
fi
|
194
|
+
else
|
195
|
+
#Do default removal
|
196
|
+
if [ -f $PIDSPATH/$PIDFILE ]; then
|
197
|
+
rm -f $PIDSPATH/$PIDFILE
|
198
|
+
fi
|
199
|
+
fi
|
200
|
+
}
|
201
|
+
|
202
|
+
start() {
|
203
|
+
log_daemon_msg "Starting $DESCRIPTION"
|
204
|
+
|
205
|
+
isRunning
|
206
|
+
isAlive=$?
|
207
|
+
|
208
|
+
if [ "${isAlive}" -eq $TRUE ]; then
|
209
|
+
log_end_msg $SCRIPT_ERROR
|
210
|
+
else
|
211
|
+
start-stop-daemon --start --quiet --chuid $RUNAS --pidfile $PIDSPATH/$PIDFILE --exec $DAEMON \
|
212
|
+
-- -c $NGINX_CONF_FILE
|
213
|
+
setFilePerms
|
214
|
+
log_end_msg $SCRIPT_OK
|
215
|
+
fi
|
216
|
+
}
|
217
|
+
|
218
|
+
stop() {
|
219
|
+
log_daemon_msg "Stopping $DESCRIPTION"
|
220
|
+
|
221
|
+
isRunning
|
222
|
+
isAlive=$?
|
223
|
+
if [ "${isAlive}" -eq $TRUE ]; then
|
224
|
+
start-stop-daemon --stop --quiet --pidfile $PIDSPATH/$PIDFILE
|
225
|
+
|
226
|
+
wait_for_pid 'removed' $PIDSPATH/$PIDFILE
|
227
|
+
|
228
|
+
if [ -n "$try" ] ; then
|
229
|
+
log_end_msg $SCRIPT_ERROR
|
230
|
+
else
|
231
|
+
removePIDFile
|
232
|
+
log_end_msg $SCRIPT_OK
|
233
|
+
fi
|
234
|
+
|
235
|
+
else
|
236
|
+
log_end_msg $SCRIPT_ERROR
|
237
|
+
fi
|
238
|
+
}
|
239
|
+
|
240
|
+
reload() {
|
241
|
+
configtest || return $?
|
242
|
+
|
243
|
+
log_daemon_msg "Reloading (via HUP) $DESCRIPTION"
|
244
|
+
|
245
|
+
isRunning
|
246
|
+
if [ $? -eq $TRUE ]; then
|
247
|
+
`killall -HUP $PS` #to be safe
|
248
|
+
|
249
|
+
log_end_msg $SCRIPT_OK
|
250
|
+
else
|
251
|
+
log_end_msg $SCRIPT_ERROR
|
252
|
+
fi
|
253
|
+
}
|
254
|
+
|
255
|
+
quietupgrade() {
|
256
|
+
log_daemon_msg "Peforming Quiet Upgrade $DESCRIPTION"
|
257
|
+
|
258
|
+
isRunning
|
259
|
+
isAlive=$?
|
260
|
+
if [ "${isAlive}" -eq $TRUE ]; then
|
261
|
+
kill -USR2 `cat $PIDSPATH/$PIDFILE`
|
262
|
+
kill -WINCH `cat $PIDSPATH/$PIDFILE.oldbin`
|
263
|
+
|
264
|
+
isRunning
|
265
|
+
isAlive=$?
|
266
|
+
if [ "${isAlive}" -eq $TRUE ]; then
|
267
|
+
kill -QUIT `cat $PIDSPATH/$PIDFILE.oldbin`
|
268
|
+
wait_for_pid 'removed' $PIDSPATH/$PIDFILE.oldbin
|
269
|
+
removePIDFile $PIDSPATH/$PIDFILE.oldbin
|
270
|
+
|
271
|
+
log_end_msg $SCRIPT_OK
|
272
|
+
else
|
273
|
+
log_end_msg $SCRIPT_ERROR
|
274
|
+
|
275
|
+
log_daemon_msg "ERROR! Reverting back to original $DESCRIPTION"
|
276
|
+
|
277
|
+
kill -HUP `cat $PIDSPATH/$PIDFILE`
|
278
|
+
kill -TERM `cat $PIDSPATH/$PIDFILE.oldbin`
|
279
|
+
kill -QUIT `cat $PIDSPATH/$PIDFILE.oldbin`
|
280
|
+
|
281
|
+
wait_for_pid 'removed' $PIDSPATH/$PIDFILE.oldbin
|
282
|
+
removePIDFile $PIDSPATH/$PIDFILE.oldbin
|
283
|
+
|
284
|
+
log_end_msg $SCRIPT_ok
|
285
|
+
fi
|
286
|
+
else
|
287
|
+
log_end_msg $SCRIPT_ERROR
|
288
|
+
fi
|
289
|
+
}
|
290
|
+
|
291
|
+
terminate() {
|
292
|
+
log_daemon_msg "Force terminating (via KILL) $DESCRIPTION"
|
293
|
+
|
294
|
+
PIDS=`pidof $PS` || true
|
295
|
+
|
296
|
+
[ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`
|
297
|
+
|
298
|
+
for i in $PIDS; do
|
299
|
+
if [ "$i" = "$PIDS2" ]; then
|
300
|
+
kill $i
|
301
|
+
wait_for_pid 'removed' $PIDSPATH/$PIDFILE
|
302
|
+
removePIDFile
|
303
|
+
fi
|
304
|
+
done
|
305
|
+
|
306
|
+
log_end_msg $SCRIPT_OK
|
307
|
+
}
|
308
|
+
|
309
|
+
destroy() {
|
310
|
+
log_daemon_msg "Force terminating and may include self (via KILLALL) $DESCRIPTION"
|
311
|
+
killall $PS -q >> /dev/null 2>&1
|
312
|
+
log_end_msg $SCRIPT_OK
|
313
|
+
}
|
314
|
+
|
315
|
+
pidof_daemon() {
|
316
|
+
PIDS=`pidof $PS` || true
|
317
|
+
|
318
|
+
[ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`
|
319
|
+
|
320
|
+
for i in $PIDS; do
|
321
|
+
if [ "$i" = "$PIDS2" ]; then
|
322
|
+
return 1
|
323
|
+
fi
|
324
|
+
done
|
325
|
+
return 0
|
326
|
+
}
|
327
|
+
|
328
|
+
case "$1" in
|
329
|
+
start)
|
330
|
+
start
|
331
|
+
;;
|
332
|
+
stop)
|
333
|
+
stop
|
334
|
+
;;
|
335
|
+
restart|force-reload)
|
336
|
+
stop
|
337
|
+
sleep 1
|
338
|
+
start
|
339
|
+
;;
|
340
|
+
reload)
|
341
|
+
$1
|
342
|
+
;;
|
343
|
+
status)
|
344
|
+
status
|
345
|
+
;;
|
346
|
+
configtest)
|
347
|
+
$1
|
348
|
+
;;
|
349
|
+
quietupgrade)
|
350
|
+
$1
|
351
|
+
;;
|
352
|
+
terminate)
|
353
|
+
$1
|
354
|
+
;;
|
355
|
+
destroy)
|
356
|
+
$1
|
357
|
+
;;
|
358
|
+
*)
|
359
|
+
FULLPATH=/etc/init.d/$PS
|
360
|
+
echo "Usage: $FULLPATH {start|stop|restart|force-reload|status|configtest|quietupgrade|terminate|destroy}"
|
361
|
+
echo " The 'destroy' command should only be used as a last resort."
|
362
|
+
exit 1
|
363
|
+
;;
|
364
|
+
esac
|
365
|
+
|
366
|
+
exit 0
|
data/generators/vulcanize/templates/nginx_frontend/config/rubber/role/web_tools/nginx-tools.conf
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
<%
|
2
|
+
@path = "/etc/nginx/rubber/tools.conf"
|
3
|
+
%>
|
4
|
+
|
5
|
+
|
6
|
+
# This server is setup to serve http.
|
7
|
+
server
|
8
|
+
{
|
9
|
+
listen <%= rubber_env.web_tools_port %>;
|
10
|
+
server_name <%= rubber_env.full_host %>;
|
11
|
+
root /var/www;
|
12
|
+
|
13
|
+
rewrite (.*) https://$host:<%= rubber_env.web_tools_ssl_port %>$1 break;
|
14
|
+
}
|
15
|
+
|
16
|
+
# This server is setup to serve https.
|
17
|
+
server
|
18
|
+
{
|
19
|
+
listen <%= rubber_env.web_tools_ssl_port %>;
|
20
|
+
server_name <%= rubber_env.full_host %>;
|
21
|
+
|
22
|
+
ssl on;
|
23
|
+
ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
|
24
|
+
ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;
|
25
|
+
# ssl_certificate <%= RUBBER_ROOT %>/config/snapmylife.com.crt;
|
26
|
+
# ssl_certificate_key <%= RUBBER_ROOT %>/config/snapmylife.com.key;
|
27
|
+
|
28
|
+
auth_basic "Rubber Admin Tools";
|
29
|
+
auth_basic_user_file <%= RUBBER_ROOT %>/config/<%= rubber_env.app_name %>.auth;
|
30
|
+
|
31
|
+
client_max_body_size 10M;
|
32
|
+
root /var/www;
|
33
|
+
|
34
|
+
|
35
|
+
location /
|
36
|
+
{
|
37
|
+
# If the file exists as a static file serve it directly without
|
38
|
+
# running all the other rewrite tests on it
|
39
|
+
if (-f $request_filename)
|
40
|
+
{
|
41
|
+
break;
|
42
|
+
}
|
43
|
+
|
44
|
+
# check for index.html for directory index
|
45
|
+
# if its there on the filesystem then rewite
|
46
|
+
# the url to add /index.html to the end of it
|
47
|
+
# and then break to send it to the next config rules.
|
48
|
+
if (-f $request_filename/index.html)
|
49
|
+
{
|
50
|
+
rewrite (.*) $1/index.html break;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
include /etc/nginx/rubber/tools/*.conf;
|
55
|
+
}
|
data/generators/vulcanize/templates/nginx_frontend/config/rubber/role/web_tools/tools-index.html
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
<%
|
2
|
+
@path = "/var/www/index.html"
|
3
|
+
%>
|
4
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
5
|
+
<html>
|
6
|
+
<head>
|
7
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
8
|
+
<title>Rubber Admin Tools</title>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
<h1>Rubber Admin Tools</h1>
|
12
|
+
<ul>
|
13
|
+
|
14
|
+
<li><a href="/munin/">Munin</a></li>
|
15
|
+
|
16
|
+
<% if cruise_host = rubber_instances.for_role('cruise').first %>
|
17
|
+
<li><a href="http://<%= cruise_host %>/cruise/">CruiseControl</a></li>
|
18
|
+
<% end %>
|
19
|
+
|
20
|
+
<% rubber_instances.for_role('haproxy').each do |ic| %>
|
21
|
+
<li><a href="/haproxy_<%= ic.name %>/">HAProxy <%= ic.name %></a></li>
|
22
|
+
<% end %>
|
23
|
+
|
24
|
+
<% rubber_instances.each do |ic| %>
|
25
|
+
<li><a href="/monit_<%= ic.name %>/">Monit <%= ic.name %></a></li>
|
26
|
+
<% end %>
|
27
|
+
|
28
|
+
</ul>
|
29
|
+
</body>
|
30
|
+
</html>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
# Uses from base rubber config
|
3
|
+
# domain: foo.com
|
4
|
+
|
5
|
+
# Uses from rubber-complete.yml
|
6
|
+
# web_tools_port: 8080
|
7
|
+
|
8
|
+
nginx_frontend_version: 0.7.65
|
9
|
+
|
10
|
+
# you generally only need one nginx worker unless you're serving large amounts of static files which require blocking disk reads
|
11
|
+
nginx_frontend_workers: 1
|
12
|
+
|
13
|
+
# increase if you have lots of clients
|
14
|
+
nginx_frontend_worker_connections: 1024
|
15
|
+
|
16
|
+
# ~2 seconds is often enough for most folks to parse HTML/CSS and
|
17
|
+
# retrieve needed images/icons/frames, connections are cheap in
|
18
|
+
# nginx so increasing this is generally safe...
|
19
|
+
nginx_frontend_keepalive_timeout: 2
|
20
|
+
|
21
|
+
roles:
|
22
|
+
nginx_frontend:
|
@@ -0,0 +1 @@
|
|
1
|
+
description: The nginx module, configured to act as the front end for a web application backend server.
|
@@ -0,0 +1,43 @@
|
|
1
|
+
namespace :rubber do
|
2
|
+
|
3
|
+
namespace :unicorn do
|
4
|
+
|
5
|
+
rubber.allow_optional_tasks(self)
|
6
|
+
|
7
|
+
# serial_task can only be called after roles defined - not normally a problem, but
|
8
|
+
# rubber auto-roles don't get defined till after all tasks are defined
|
9
|
+
on :load do
|
10
|
+
rubber.serial_task self, :serial_restart, :roles => :unicorn do
|
11
|
+
run "/etc/init.d/unicorn restart"
|
12
|
+
end
|
13
|
+
rubber.serial_task self, :serial_reload, :roles => :unicorn do
|
14
|
+
run "if ! ps ax | grep -v grep | grep -c unicorn_rails &> /dev/null; then /etc/init.d/unicorn start; else /etc/init.d/unicorn reload; fi"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
before "deploy:stop", "rubber:unicorn:stop"
|
19
|
+
after "deploy:start", "rubber:unicorn:start"
|
20
|
+
after "deploy:restart", "rubber:unicorn:reload"
|
21
|
+
|
22
|
+
desc "Stops the unicorn web server"
|
23
|
+
task :stop, :roles => :unicorn, :on_error => :continue do
|
24
|
+
run "/etc/init.d/unicorn stop"
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "Starts the unicorn web server"
|
28
|
+
task :start, :roles => :unicorn do
|
29
|
+
run "/etc/init.d/unicorn start"
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "Restarts the unicorn web server"
|
33
|
+
task :restart, :roles => :unicorn do
|
34
|
+
serial_restart
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Reloads the unicorn web server"
|
38
|
+
task :reload, :roles => :unicorn do
|
39
|
+
serial_reload
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
<%
|
2
|
+
@path = "/etc/nginx_frontend/unicorn_nginx_server.conf"
|
3
|
+
|
4
|
+
# For unicorn nodes running on the same host as nginx, we can use unix domain sockets, otherwise fall back to TCP
|
5
|
+
unicorn_nodes = rubber_instances.for_role('nginx_frontend')
|
6
|
+
self_instance = rubber_instances[rubber_env.host]
|
7
|
+
|
8
|
+
# Instead of pointing to the real release dir, we point to the capistrano symlink (current). This allows us to
|
9
|
+
# do hot deploys without restarting nginx.
|
10
|
+
deploy_to = "/mnt/#{rubber_env.app_name}-#{RUBBER_ENV}"
|
11
|
+
-%>
|
12
|
+
|
13
|
+
# this can be any application server, not just Unicorn/Rainbows!
|
14
|
+
upstream app_server {
|
15
|
+
# fail_timeout=0 means we always retry an upstream even if it failed
|
16
|
+
# to return a good HTTP response (in case the Unicorn master nukes a
|
17
|
+
# single worker for timing out).
|
18
|
+
|
19
|
+
<% unicorn_nodes.each do |n| %>
|
20
|
+
<% if self_instance.full_name == n.full_name %>
|
21
|
+
# for UNIX domain socket setups:
|
22
|
+
server unix:/tmp/.sock fail_timeout=0;
|
23
|
+
<% else %>
|
24
|
+
server <%= n.full_name %>:8080 fail_timeout=0;
|
25
|
+
<% endif %>
|
26
|
+
<% end %>
|
27
|
+
}
|
28
|
+
|
29
|
+
server {
|
30
|
+
#listen 80;
|
31
|
+
listen 80 default deferred; # for Linux
|
32
|
+
client_max_body_size 1G;
|
33
|
+
|
34
|
+
server_name _;
|
35
|
+
root <%= "#{deploy_to}/current/public" %>;
|
36
|
+
|
37
|
+
# If we have Rails-style proxy-busting query string, do internal redirect to special location which adds a far-future expire header.
|
38
|
+
# When opening static assets without proxy-busting query string, we do not redirect, and do not set the expire header (for example when referencing images from css files not parsed by rails
|
39
|
+
if ($query_string ~* "^[0-9]{10}$") {
|
40
|
+
rewrite ^(.*) /add_expires_header$1;
|
41
|
+
break;
|
42
|
+
}
|
43
|
+
location /add_expires_header {
|
44
|
+
expires max;
|
45
|
+
}
|
46
|
+
|
47
|
+
location / {
|
48
|
+
# an HTTP header important enough to have its own Wikipedia entry:
|
49
|
+
# http://en.wikipedia.org/wiki/X-Forwarded-For
|
50
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
51
|
+
|
52
|
+
# enable this if and only if you use HTTPS, this helps Rack
|
53
|
+
# set the proper protocol for doing redirects:
|
54
|
+
# proxy_set_header X-Forwarded-Proto https;
|
55
|
+
|
56
|
+
# pass the Host: header from the client right along so redirects
|
57
|
+
# can be set properly within the Rack application
|
58
|
+
proxy_set_header Host $http_host;
|
59
|
+
|
60
|
+
# we don't want nginx trying to do something clever with
|
61
|
+
# redirects, we set the Host: header above already.
|
62
|
+
proxy_redirect off;
|
63
|
+
|
64
|
+
# set "proxy_buffering off" *only* for Rainbows! when doing
|
65
|
+
# Comet/long-poll stuff. It's also safe to set if you're
|
66
|
+
# using only serving fast clients with Unicorn + nginx.
|
67
|
+
# Otherwise you _want_ nginx to buffer responses to slow
|
68
|
+
# clients, really.
|
69
|
+
# proxy_buffering off;
|
70
|
+
|
71
|
+
# Try to serve static files from nginx, no point in making an
|
72
|
+
# *application* server like Unicorn/Rainbows! serve static files.
|
73
|
+
if (!-f $request_filename) {
|
74
|
+
proxy_pass http://app_server;
|
75
|
+
break;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
# TODO: Move this into our app
|
80
|
+
location /private/3sellers/ {
|
81
|
+
internal;
|
82
|
+
alias <%= deploy_to %>/shared/private/3sellers/;
|
83
|
+
}
|
84
|
+
|
85
|
+
# Rails error pages
|
86
|
+
error_page 500 502 503 504 /500.html;
|
87
|
+
location = /500.html {
|
88
|
+
root <%= deploy_to %>/current/public;
|
89
|
+
}
|
90
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<%
|
2
|
+
@path = "/etc/logrotate.d/unicorn"
|
3
|
+
@no_backup = true
|
4
|
+
|
5
|
+
deploy_to = "/mnt/#{rubber_env.app_name}-#{RUBBER_ENV}"
|
6
|
+
-%>
|
7
|
+
<%= deploy_to %>/shared/log/unicorn*.log {
|
8
|
+
daily
|
9
|
+
missingok
|
10
|
+
dateext
|
11
|
+
create 640 <%= rubber_env.app_user %> <%= rubber_env.app_user %>
|
12
|
+
sharedscripts
|
13
|
+
postrotate
|
14
|
+
[ ! -f <%= deploy_to %>/shared/pids/unicorn.pid ] || kill -USR1 `cat <%= deploy_to %>/shared/pids/unicorn.pid`
|
15
|
+
endscript
|
16
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%
|
2
|
+
@path = '/etc/monit/monit.d/monit-unicorn.conf'
|
3
|
+
|
4
|
+
deploy_to = "/mnt/#{rubber_env.app_name}-#{RUBBER_ENV}"
|
5
|
+
%>
|
6
|
+
<% PIDFILE = "#{deploy_to}/shared/pids/unicorn.pid" %>
|
7
|
+
check process unicorn with pidfile <%= PIDFILE %>
|
8
|
+
group unicorn-<%= RUBBER_ENV %>
|
9
|
+
start program = "/etc/init.d/unicorn start"
|
10
|
+
stop program = "/etc/init.d/unicorn stop"
|
@@ -0,0 +1,327 @@
|
|
1
|
+
<%
|
2
|
+
@path = "/etc/init.d/unicorn"
|
3
|
+
|
4
|
+
deploy_to = "/mnt/#{rubber_env.app_name}-#{RUBBER_ENV}"
|
5
|
+
-%>
|
6
|
+
#! /bin/sh
|
7
|
+
### BEGIN INIT INFO
|
8
|
+
# Provides: unicorn_rails
|
9
|
+
# Required-Start: $remote_fs $syslog
|
10
|
+
# Required-Stop: $remote_fs $syslog
|
11
|
+
# Default-Start: 2 3 4 5
|
12
|
+
# Default-Stop: 0 1 6
|
13
|
+
# Short-Description: unicorn_rails init.d dash script for Ubuntu <=9.10.
|
14
|
+
# Description: unicorn_rails init.d dash script for Ubuntu <=9.10.
|
15
|
+
### END INIT INFO
|
16
|
+
#------------------------------------------------------------------------------
|
17
|
+
# unicorn - this Debian Almquist shell (dash) script, starts and stops the unicorn
|
18
|
+
# daemon for ubuntu 9.10 and lesser version numbered releases.
|
19
|
+
#
|
20
|
+
# description: Unicorn is an HTTP server for Rack applications designed to only serve fast clients on low-latency, \
|
21
|
+
# high-bandwidth connections and take advantage of features in Unix/Unix-like kernels. Slow clients \
|
22
|
+
# should only be served by placing a reverse proxy capable of fully buffering both the the request and \
|
23
|
+
# response in between Unicorn and slow clients.
|
24
|
+
#
|
25
|
+
# processname: unicorn_rails
|
26
|
+
# config: /etc/unicorn/unicorn.conf
|
27
|
+
# pidfile: <% "#{deploy_to}/shared/pids/unicorn.pid" %>
|
28
|
+
# Provides: unicorn_rails
|
29
|
+
#
|
30
|
+
# Author: Henning Kiel
|
31
|
+
# <henning.kiel AT gmail.com>.
|
32
|
+
#
|
33
|
+
# Version: 0.1 18-FEB-2010 henning.kiel AT gmail.com
|
34
|
+
# Notes: unicorn_rails init.d dash script for Ubuntu <=9.10.
|
35
|
+
#
|
36
|
+
#------------------------------------------------------------------------------
|
37
|
+
# MIT X11 License
|
38
|
+
#------------------------------------------------------------------------------
|
39
|
+
#
|
40
|
+
# Copyright (c) 2010 Henning Kiel, http://www.axtro.es
|
41
|
+
#
|
42
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
43
|
+
# a copy of this software and associated documentation files (the
|
44
|
+
# "Software"), to deal in the Software without restriction, including
|
45
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
46
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
47
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
48
|
+
# the following conditions:
|
49
|
+
#
|
50
|
+
# The above copyright notice and this permission notice shall be
|
51
|
+
# included in all copies or substantial portions of the Software.
|
52
|
+
#
|
53
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
54
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
55
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
56
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
57
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
58
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
59
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
60
|
+
#------------------------------------------------------------------------------
|
61
|
+
|
62
|
+
#------------------------------------------------------------------------------
|
63
|
+
# Functions
|
64
|
+
#------------------------------------------------------------------------------
|
65
|
+
. /lib/lsb/init-functions
|
66
|
+
|
67
|
+
#------------------------------------------------------------------------------
|
68
|
+
# Consts
|
69
|
+
#------------------------------------------------------------------------------
|
70
|
+
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
71
|
+
DAEMON=/usr/local/bin/unicorn_rails
|
72
|
+
|
73
|
+
PS="unicorn_rails"
|
74
|
+
PIDNAME="unicorn" #lets you do $PS-slave
|
75
|
+
PIDFILE=$PIDNAME.pid #pid file
|
76
|
+
PIDSPATH=<% "#{deploy_to}/shared/pids %>
|
77
|
+
|
78
|
+
DESCRIPTION="Unicorn Server..."
|
79
|
+
|
80
|
+
RUNAS=<%= rubber_env.app_user %> #user to run as
|
81
|
+
|
82
|
+
SCRIPT_OK=0 #ala error codes
|
83
|
+
SCRIPT_ERROR=1 #ala error codes
|
84
|
+
TRUE=1 #boolean
|
85
|
+
FALSE=0 #boolean
|
86
|
+
|
87
|
+
UNICORN_CONF_FILE="/etc/unicorn/unicorn.conf"
|
88
|
+
|
89
|
+
#------------------------------------------------------------------------------
|
90
|
+
# Simple Tests
|
91
|
+
#------------------------------------------------------------------------------
|
92
|
+
|
93
|
+
#test if unicorn_rails is a file and executable
|
94
|
+
test -x $DAEMON || exit 0
|
95
|
+
|
96
|
+
# Include unicorn_rails defaults if available
|
97
|
+
if [ -f /etc/default/unicorn_rails ] ; then
|
98
|
+
. /etc/default/unicorn_rails
|
99
|
+
fi
|
100
|
+
|
101
|
+
#set exit condition
|
102
|
+
#set -e
|
103
|
+
|
104
|
+
#------------------------------------------------------------------------------
|
105
|
+
# Functions
|
106
|
+
#------------------------------------------------------------------------------
|
107
|
+
|
108
|
+
setFilePerms(){
|
109
|
+
|
110
|
+
if [ -f $PIDSPATH/$PIDFILE ]; then
|
111
|
+
chmod 400 $PIDSPATH/$PIDFILE
|
112
|
+
fi
|
113
|
+
}
|
114
|
+
|
115
|
+
configtest() {
|
116
|
+
$DAEMON -t -c $UNICORN_CONF_FILE
|
117
|
+
}
|
118
|
+
|
119
|
+
getPSCount() {
|
120
|
+
return `pgrep -f $PS | wc -l`
|
121
|
+
}
|
122
|
+
|
123
|
+
isRunning() {
|
124
|
+
if [ $1 ]; then
|
125
|
+
pidof_daemon $1
|
126
|
+
PID=$?
|
127
|
+
|
128
|
+
if [ $PID -gt 0 ]; then
|
129
|
+
return 1
|
130
|
+
else
|
131
|
+
return 0
|
132
|
+
fi
|
133
|
+
else
|
134
|
+
pidof_daemon
|
135
|
+
PID=$?
|
136
|
+
|
137
|
+
if [ $PID -gt 0 ]; then
|
138
|
+
return 1
|
139
|
+
else
|
140
|
+
return 0
|
141
|
+
fi
|
142
|
+
fi
|
143
|
+
}
|
144
|
+
|
145
|
+
#courtesy of php-fpm
|
146
|
+
wait_for_pid () {
|
147
|
+
try=0
|
148
|
+
|
149
|
+
while test $try -lt 35 ; do
|
150
|
+
|
151
|
+
case "$1" in
|
152
|
+
'created')
|
153
|
+
if [ -f "$2" ] ; then
|
154
|
+
try=''
|
155
|
+
break
|
156
|
+
fi
|
157
|
+
;;
|
158
|
+
|
159
|
+
'removed')
|
160
|
+
if [ ! -f "$2" ] ; then
|
161
|
+
try=''
|
162
|
+
break
|
163
|
+
fi
|
164
|
+
;;
|
165
|
+
esac
|
166
|
+
|
167
|
+
#echo -n .
|
168
|
+
try=`expr $try + 1`
|
169
|
+
sleep 1
|
170
|
+
done
|
171
|
+
}
|
172
|
+
|
173
|
+
status(){
|
174
|
+
isRunning
|
175
|
+
isAlive=$?
|
176
|
+
|
177
|
+
if [ "${isAlive}" -eq $TRUE ]; then
|
178
|
+
echo "$PIDNAME found running with processes: `pidof $PS`"
|
179
|
+
else
|
180
|
+
echo "$PIDNAME is NOT running."
|
181
|
+
fi
|
182
|
+
|
183
|
+
|
184
|
+
}
|
185
|
+
|
186
|
+
removePIDFile(){
|
187
|
+
if [ $1 ]; then
|
188
|
+
if [ -f $1 ]; then
|
189
|
+
rm -f $1
|
190
|
+
fi
|
191
|
+
else
|
192
|
+
#Do default removal
|
193
|
+
if [ -f $PIDSPATH/$PIDFILE ]; then
|
194
|
+
rm -f $PIDSPATH/$PIDFILE
|
195
|
+
fi
|
196
|
+
fi
|
197
|
+
}
|
198
|
+
|
199
|
+
start() {
|
200
|
+
log_daemon_msg "Starting $DESCRIPTION"
|
201
|
+
|
202
|
+
isRunning
|
203
|
+
isAlive=$?
|
204
|
+
|
205
|
+
if [ "${isAlive}" -eq $TRUE ]; then
|
206
|
+
log_end_msg $SCRIPT_ERROR
|
207
|
+
else
|
208
|
+
start-stop-daemon --start --quiet --chuid $RUNAS --pidfile $PIDSPATH/$PIDFILE --exec $DAEMON \
|
209
|
+
-- -c $UNICORN_CONF_FILE
|
210
|
+
setFilePerms
|
211
|
+
log_end_msg $SCRIPT_OK
|
212
|
+
fi
|
213
|
+
}
|
214
|
+
|
215
|
+
stop() {
|
216
|
+
log_daemon_msg "Stopping $DESCRIPTION"
|
217
|
+
|
218
|
+
isRunning
|
219
|
+
isAlive=$?
|
220
|
+
if [ "${isAlive}" -eq $TRUE ]; then
|
221
|
+
start-stop-daemon --stop --quiet --pidfile $PIDSPATH/$PIDFILE
|
222
|
+
|
223
|
+
wait_for_pid 'removed' $PIDSPATH/$PIDFILE
|
224
|
+
|
225
|
+
if [ -n "$try" ] ; then
|
226
|
+
log_end_msg $SCRIPT_ERROR
|
227
|
+
else
|
228
|
+
removePIDFile
|
229
|
+
log_end_msg $SCRIPT_OK
|
230
|
+
fi
|
231
|
+
|
232
|
+
else
|
233
|
+
log_end_msg $SCRIPT_ERROR
|
234
|
+
fi
|
235
|
+
}
|
236
|
+
|
237
|
+
reload() {
|
238
|
+
configtest || return $?
|
239
|
+
|
240
|
+
log_daemon_msg "Reloading (via HUP) $DESCRIPTION"
|
241
|
+
|
242
|
+
isRunning
|
243
|
+
if [ $? -eq $TRUE ]; then
|
244
|
+
`killall -HUP $PS` #to be safe
|
245
|
+
|
246
|
+
log_end_msg $SCRIPT_OK
|
247
|
+
else
|
248
|
+
log_end_msg $SCRIPT_ERROR
|
249
|
+
fi
|
250
|
+
}
|
251
|
+
|
252
|
+
terminate() {
|
253
|
+
log_daemon_msg "Force terminating (via KILL) $DESCRIPTION"
|
254
|
+
|
255
|
+
PIDS=`pidof $PS` || true
|
256
|
+
|
257
|
+
[ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`
|
258
|
+
|
259
|
+
for i in $PIDS; do
|
260
|
+
if [ "$i" = "$PIDS2" ]; then
|
261
|
+
kill $i
|
262
|
+
wait_for_pid 'removed' $PIDSPATH/$PIDFILE
|
263
|
+
removePIDFile
|
264
|
+
fi
|
265
|
+
done
|
266
|
+
|
267
|
+
log_end_msg $SCRIPT_OK
|
268
|
+
}
|
269
|
+
|
270
|
+
destroy() {
|
271
|
+
log_daemon_msg "Force terminating and may include self (via KILLALL) $DESCRIPTION"
|
272
|
+
killall $PS -q >> /dev/null 2>&1
|
273
|
+
log_end_msg $SCRIPT_OK
|
274
|
+
}
|
275
|
+
|
276
|
+
pidof_daemon() {
|
277
|
+
PIDS=`pidof $PS` || true
|
278
|
+
|
279
|
+
[ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`
|
280
|
+
|
281
|
+
for i in $PIDS; do
|
282
|
+
if [ "$i" = "$PIDS2" ]; then
|
283
|
+
return 1
|
284
|
+
fi
|
285
|
+
done
|
286
|
+
return 0
|
287
|
+
}
|
288
|
+
|
289
|
+
case "$1" in
|
290
|
+
start)
|
291
|
+
start
|
292
|
+
;;
|
293
|
+
stop)
|
294
|
+
stop
|
295
|
+
;;
|
296
|
+
restart|force-reload)
|
297
|
+
stop
|
298
|
+
sleep 1
|
299
|
+
start
|
300
|
+
;;
|
301
|
+
reload)
|
302
|
+
$1
|
303
|
+
;;
|
304
|
+
status)
|
305
|
+
status
|
306
|
+
;;
|
307
|
+
configtest)
|
308
|
+
$1
|
309
|
+
;;
|
310
|
+
quietupgrade)
|
311
|
+
$1
|
312
|
+
;;
|
313
|
+
terminate)
|
314
|
+
$1
|
315
|
+
;;
|
316
|
+
destroy)
|
317
|
+
$1
|
318
|
+
;;
|
319
|
+
*)
|
320
|
+
FULLPATH=/etc/init.d/$PS
|
321
|
+
echo "Usage: $FULLPATH {start|stop|restart|force-reload|status|configtest|quietupgrade|terminate|destroy}"
|
322
|
+
echo " The 'destroy' command should only be used as a last resort."
|
323
|
+
exit 1
|
324
|
+
;;
|
325
|
+
esac
|
326
|
+
|
327
|
+
exit 0
|
@@ -0,0 +1,86 @@
|
|
1
|
+
<%
|
2
|
+
@path = "/etc/unicorn/unicorn.conf"
|
3
|
+
@post = "mkdir -p /mnt/log/unicorn"
|
4
|
+
|
5
|
+
deploy_to = "/mnt/#{rubber_env.app_name}-#{RUBBER_ENV}"
|
6
|
+
-%>
|
7
|
+
# Sample configuration file for Unicorn (not Rack)
|
8
|
+
#
|
9
|
+
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
|
10
|
+
# documentation.
|
11
|
+
|
12
|
+
# Use at least one worker per core if you're on a dedicated server,
|
13
|
+
# more will usually help for _short_ waits on databases/caches.
|
14
|
+
worker_processes <%= rubber_env.unicorn_workers %>
|
15
|
+
|
16
|
+
# Help ensure your application will always spawn in the symlinked
|
17
|
+
# "current" directory that Capistrano sets up.
|
18
|
+
working_directory "<%= deploy_to %>/current" # available in 0.94.0+
|
19
|
+
|
20
|
+
# listen on both a Unix domain socket and a TCP port,
|
21
|
+
# we use a shorter backlog for quicker failover when busy
|
22
|
+
listen "/tmp/.sock", :backlog => 64
|
23
|
+
listen 8080, :tcp_nopush => true
|
24
|
+
|
25
|
+
# nuke workers after 30 seconds instead of 60 seconds (the default)
|
26
|
+
timeout <%= rubber_env.unicorn_worker_timeout %>
|
27
|
+
|
28
|
+
# feel free to point this anywhere accessible on the filesystem
|
29
|
+
pid "<%= deploy_to %>/shared/pids/unicorn.pid"
|
30
|
+
|
31
|
+
# some applications/frameworks log to stderr or stdout, so prevent
|
32
|
+
# them from going to /dev/null when daemonized here:
|
33
|
+
stderr_path "<%= deploy_to %>/shared/log/unicorn.stderr.log"
|
34
|
+
stdout_path "<%= deploy_to %>/shared/log/unicorn.stdout.log"
|
35
|
+
|
36
|
+
# combine REE with "preload_app true" for memory savings
|
37
|
+
# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
|
38
|
+
preload_app <%= rubber_env.unicorn_preload_app %>
|
39
|
+
<%= rubber_env.unicorn_use_copy_on_write_if_available || "false" %> and GC.respond_to?(:copy_on_write_friendly=) and
|
40
|
+
GC.copy_on_write_friendly = true
|
41
|
+
|
42
|
+
before_fork do |server, worker|
|
43
|
+
# the following is highly recomended for Rails + "preload_app true"
|
44
|
+
# as there's no need for the master process to hold a connection
|
45
|
+
defined?(ActiveRecord::Base) and
|
46
|
+
ActiveRecord::Base.connection.disconnect!
|
47
|
+
|
48
|
+
# The following is only recommended for memory/DB-constrained
|
49
|
+
# installations. It is not needed if your system can house
|
50
|
+
# twice as many worker_processes as you have configured.
|
51
|
+
#
|
52
|
+
# This allows a new master process to incrementally
|
53
|
+
# phase out the old master process with SIGTTOU to avoid a
|
54
|
+
# thundering herd (especially in the "preload_app false" case)
|
55
|
+
# when doing a transparent upgrade. The last worker spawned
|
56
|
+
# will then kill off the old master process with a SIGQUIT.
|
57
|
+
old_pid = "#{server.config[:pid]}.oldbin"
|
58
|
+
if old_pid != server.pid
|
59
|
+
begin
|
60
|
+
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
|
61
|
+
Process.kill(sig, File.read(old_pid).to_i)
|
62
|
+
rescue Errno::ENOENT, Errno::ESRCH
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# *optionally* throttle the master from forking too quickly by sleeping
|
67
|
+
sleep 1
|
68
|
+
end
|
69
|
+
|
70
|
+
after_fork do |server, worker|
|
71
|
+
# per-process listener ports for debugging/admin/migrations
|
72
|
+
# addr = "127.0.0.1:#{<%= rubber_env.unicorn_base_port %> + worker.nr}"
|
73
|
+
# server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
|
74
|
+
|
75
|
+
# the following is *required* for Rails + "preload_app true",
|
76
|
+
defined?(ActiveRecord::Base) and
|
77
|
+
ActiveRecord::Base.establish_connection
|
78
|
+
|
79
|
+
# if preload_app is true, then you may also want to check and
|
80
|
+
# restart any other shared sockets/descriptors such as Memcached,
|
81
|
+
# and Redis. TokyoCabinet file handles are safe to reuse
|
82
|
+
# between any number of forked children (assuming your kernel
|
83
|
+
# correctly implements pread()/pwrite() system calls)
|
84
|
+
Rails.cache.instance_variable_get(:@data).reset if defined?(Rails.cache) and Rails.cache.class == ActiveSupport::Cache::MemCacheStore
|
85
|
+
CACHE.reset if defined?(CACHE)
|
86
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
unicorn_version: 0.96.1
|
2
|
+
unicorn_workers: "#{RUBBER_ENV == 'production' ? 8 : 2}"
|
3
|
+
unicorn_worker_timeout: 30
|
4
|
+
unicorn_base_port: 7000
|
5
|
+
unicorn_preload_app: true
|
6
|
+
unicorn_use_copy_on_write_if_available: true
|
7
|
+
|
8
|
+
role_dependencies:
|
9
|
+
unicorn: [nginx_frontend]
|
10
|
+
|
11
|
+
roles:
|
12
|
+
unicorn:
|
13
|
+
gems: [[unicorn, "#{unicorn_version}"]]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: axtro-rubber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Conway
|
@@ -9,9 +9,19 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-22 00:00:00 +01:00
|
13
13
|
default_executable: vulcanize
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: gemcutter
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - <
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.4.0
|
24
|
+
version:
|
15
25
|
- !ruby/object:Gem::Dependency
|
16
26
|
name: capistrano
|
17
27
|
type: :runtime
|
@@ -80,7 +90,6 @@ extensions: []
|
|
80
90
|
|
81
91
|
extra_rdoc_files:
|
82
92
|
- README
|
83
|
-
- TODO
|
84
93
|
files:
|
85
94
|
- CHANGELOG
|
86
95
|
- COPYING
|
@@ -207,6 +216,16 @@ files:
|
|
207
216
|
- generators/vulcanize/templates/nginx/config/rubber/role/web_tools/tools-nginx.auth
|
208
217
|
- generators/vulcanize/templates/nginx/config/rubber/rubber-nginx.yml
|
209
218
|
- generators/vulcanize/templates/nginx/templates.yml
|
219
|
+
- generators/vulcanize/templates/nginx_frontend/config/rubber/deploy-nginx_frontend.rb
|
220
|
+
- generators/vulcanize/templates/nginx_frontend/config/rubber/role/nginx_frontend/logrotate-nginx_frontend
|
221
|
+
- generators/vulcanize/templates/nginx_frontend/config/rubber/role/nginx_frontend/monit-nginx_frontend.conf
|
222
|
+
- generators/vulcanize/templates/nginx_frontend/config/rubber/role/nginx_frontend/nginx.conf
|
223
|
+
- generators/vulcanize/templates/nginx_frontend/config/rubber/role/nginx_frontend/nginx_frontend
|
224
|
+
- generators/vulcanize/templates/nginx_frontend/config/rubber/role/web_tools/nginx-tools.conf
|
225
|
+
- generators/vulcanize/templates/nginx_frontend/config/rubber/role/web_tools/tools-index.html
|
226
|
+
- generators/vulcanize/templates/nginx_frontend/config/rubber/role/web_tools/tools-nginx.auth
|
227
|
+
- generators/vulcanize/templates/nginx_frontend/config/rubber/rubber-nginx_frontend.yml
|
228
|
+
- generators/vulcanize/templates/nginx_frontend/templates.yml
|
210
229
|
- generators/vulcanize/templates/passenger/config/rubber/deploy-passenger.rb
|
211
230
|
- generators/vulcanize/templates/passenger/config/rubber/role/passenger/munin-passenger-memory.conf
|
212
231
|
- generators/vulcanize/templates/passenger/config/rubber/role/passenger/munin-passenger-sudoers.conf
|
@@ -232,6 +251,13 @@ files:
|
|
232
251
|
- generators/vulcanize/templates/sphinx/config/rubber/role/sphinx/monit-sphinx.conf
|
233
252
|
- generators/vulcanize/templates/sphinx/config/rubber/rubber-sphinx.yml
|
234
253
|
- generators/vulcanize/templates/sphinx/templates.yml
|
254
|
+
- generators/vulcanize/templates/unicorn/config/rubber/deploy-unicorn.rb
|
255
|
+
- generators/vulcanize/templates/unicorn/config/rubber/role/nginx_frontend/unicorn_nginx_server.conf
|
256
|
+
- generators/vulcanize/templates/unicorn/config/rubber/role/unicorn/logrotate-unicorn
|
257
|
+
- generators/vulcanize/templates/unicorn/config/rubber/role/unicorn/monit-unicorn.conf
|
258
|
+
- generators/vulcanize/templates/unicorn/config/rubber/role/unicorn/unicorn
|
259
|
+
- generators/vulcanize/templates/unicorn/config/rubber/role/unicorn/unicorn.conf
|
260
|
+
- generators/vulcanize/templates/unicorn/config/rubber/rubber-unicorn.yml
|
235
261
|
- generators/vulcanize/vulcanize_generator.rb
|
236
262
|
- lib/capistrano/hostcmd.rb
|
237
263
|
- lib/rubber.rb
|
@@ -293,6 +319,6 @@ summary: A capistrano plugin for managing multi-instance deployments to the clou
|
|
293
319
|
test_files:
|
294
320
|
- test/environment_test.rb
|
295
321
|
- test/generator_test.rb
|
296
|
-
- test/instance_test.rb
|
297
322
|
- test/test_helper.rb
|
298
323
|
- test/util_test.rb
|
324
|
+
- test/instance_test.rb
|