tannins 0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,51 @@
1
+ require 'erubis'
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+ namespace :gentoo do
4
+
5
+ desc "Setup Merb Configuration"
6
+ task :application_configuration_setup, :roles => :app do
7
+ # creates an init script specific to this application
8
+ merb_init_file = Tannins.get_template("merb_init.erb")
9
+ merb_init_conf = ::Erubis::Eruby.new(File.read(merb_init_file)).result(binding)
10
+ put merb_init_conf, "#{shared_path}/config/merb_init"
11
+ sudo "ln -nfs #{shared_path}/config/merb_init /etc/init.d/merb_#{application}"
12
+ sudo "chmod a+x /etc/init.d/merb_#{application}"
13
+ sudo "rc-update add merb_#{application} default"
14
+ end
15
+
16
+ desc "Tasks to execute after initial setup"
17
+ task :setup do
18
+ rake = fetch(:rake, "rake")
19
+ run "cd #{latest_release} && #{rake} db:create db:migrate MERB_ENV=#{rails_env}"
20
+ end
21
+ end
22
+
23
+ # restarts the individual application
24
+ namespace :deploy do
25
+ desc 'restart merb cluster'
26
+ task :restart do
27
+ sudo "/etc/init.d/merb_#{application} restart"
28
+ end
29
+
30
+ task :start do
31
+ sudo "/etc/init.d/merb_#{application} start"
32
+ end
33
+
34
+ task :stop do
35
+ sudo "/etc/init.d/merb_#{application} stop"
36
+ end
37
+
38
+ desc 'cluster status'
39
+ task :cluster_status do
40
+ sudo "/etc/init.d/merb_#{application} status"
41
+ end
42
+
43
+ after 'deploy:update_code', 'deploy:gem_deployment'
44
+ desc 'deploy gems'
45
+ task :gem_deployment do
46
+ run "cd #{latest_release} && thor merb:gem:redeploy"
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,51 @@
1
+ require 'erubis'
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+ # mongrel has some replacements for restart and spinner:
4
+ require 'mongrel_cluster/recipes'
5
+ namespace :gentoo do
6
+
7
+ desc "Setup mongrel Configuration"
8
+ task :application_configuration_setup, :roles => :app do
9
+ # generate a mongrel configuration file
10
+ mongrel.cluster.configure
11
+ sudo "ln -nfs #{shared_path}/mongrel_cluster.yml /etc/mongrel_cluster/#{application}.yml"
12
+
13
+ # creates an init script specific to this application
14
+ mongrel_init_file = Tannins.get_template("mongrel_init.erb")
15
+ mongrel_init_conf = ::Erubis::Eruby.new(File.read(mongrel_init_file)).result(binding)
16
+ put mongrel_init_conf, "#{shared_path}/config/mongrel_init"
17
+ sudo "ln -nfs #{shared_path}/config/mongrel_init /etc/init.d/mongrel_#{application}"
18
+ sudo "chmod a+x /etc/init.d/mongrel_#{application}"
19
+ sudo "rc-update add mongrel_#{application} default"
20
+ end
21
+ end
22
+
23
+ # restarts the individual application
24
+ namespace :deploy do
25
+ desc 'restart mongrel cluster'
26
+ task :restart do
27
+ sudo "/etc/init.d/mongrel_#{application} restart"
28
+ end
29
+
30
+ task :start do
31
+ sudo "/etc/init.d/mongrel_#{application} start"
32
+ end
33
+
34
+ task :stop do
35
+ sudo "/etc/init.d/mongrel_#{application} stop"
36
+ end
37
+
38
+ desc 'rails cluster status'
39
+ task :cluster_status do
40
+ sudo "/etc/init.d/mongrel_#{application} status"
41
+ end
42
+
43
+ after 'deploy:symlink_configs', 'deploy:symlink_mongrel_cluster_config'
44
+
45
+ desc "Link to the shared mongrel_cluster.yml."
46
+ task :symlink_mongrel_cluster_config, :roles => [:web] do
47
+ run "rm -f #{latest_release}/config/mongrel_cluster.yml"
48
+ run "ln -nfs #{shared_path}/mongrel_cluster.yml #{latest_release}/config/mongrel_cluster.yml"
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,56 @@
1
+ require 'erubis'
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+ namespace :gentoo do
4
+ desc "Setup Nginx Configuration"
5
+ task :web_configuration_setup, :roles => :web do
6
+ sudo "mkdir -p /etc/nginx/vhosts/"
7
+
8
+ vhost_file = Tannins.get_template("nginx_vhost.erb")
9
+ nginx_file = Tannins.get_template("nginx.conf.erb")
10
+ nginx_rails_conf = ::Erubis::Eruby.new(File.read(vhost_file)).result(binding)
11
+ nginx_main_conf = ::Erubis::Eruby.new(File.read(nginx_file)).result(binding)
12
+
13
+ put nginx_rails_conf, "#{shared_path}/config/#{application}_nginx.conf"
14
+ put nginx_main_conf, "#{shared_path}/config/nginx.conf"
15
+
16
+ sudo "ln -nfs #{shared_path}/config/#{application}_nginx.conf /etc/nginx/vhosts/#{precedence}_#{application}.conf"
17
+ sudo "ln -nfs #{shared_path}/config/nginx.conf /etc/nginx/nginx.conf"
18
+ sudo "rc-update add nginx default"
19
+ sudo "/etc/init.d/nginx restart"
20
+ end
21
+ end
22
+
23
+ namespace :nginx do
24
+ desc "Start Nginx on the app slices."
25
+ task :start, :roles => :app do
26
+ sudo "/etc/init.d/nginx start"
27
+ end
28
+
29
+ desc "Restart the Nginx processes on the app slices."
30
+ task :restart , :roles => :app do
31
+ sudo "/etc/init.d/nginx restart"
32
+ end
33
+
34
+ desc "Stop the Nginx processes on the app slices."
35
+ task :stop , :roles => :app do
36
+ sudo "/etc/init.d/nginx stop"
37
+ end
38
+
39
+ desc "Tail the nginx access logs for this application"
40
+ task :tail, :roles => :app do
41
+ run "tail -f /var/log/nginx/access.log" do |channel, stream, data|
42
+ puts "#{channel[:server]}: #{data}" unless data =~ /^10\.[01]\.0/ # skips lb pull pages
43
+ break if stream == :err
44
+ end
45
+ end
46
+
47
+ desc "Tail the nginx error logs on the app slices"
48
+ task :tail_error, :roles => :app do
49
+ run "tail -f /var/log/nginx/error.log" do |channel, stream, data|
50
+ puts "#{channel[:server]}: #{data}" unless data =~ /^10\.[01]\.0/ # skips lb pull pages
51
+ break if stream == :err
52
+ end
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,44 @@
1
+ ServerName <%= server_name %>
2
+ ServerAlias *.<%= server_name %>
3
+ DocumentRoot <%= deploy_to %>/current/public
4
+ <Directory "<%= deploy_to %>/current/public">
5
+ Options FollowSymLinks
6
+ AllowOverride None
7
+ Order allow,deny
8
+ Allow from all
9
+ </Directory>
10
+
11
+ RewriteEngine On
12
+
13
+ # Uncomment for rewrite debugging
14
+ #RewriteLog logs/<%= application %>_rewrite_log
15
+ #RewriteLogLevel 9
16
+
17
+ # Check for maintenance file and redirect all requests
18
+ RewriteCond %{DOCUMENT_ROOT%>/system/maintenance.html -f
19
+ RewriteCond %{SCRIPT_FILENAME%> !maintenance.html
20
+ RewriteRule ^.*$ /system/maintenance.html [L]
21
+
22
+ # Rewrite index to check for static
23
+ RewriteRule ^/$ /index.html [QSA]
24
+
25
+ # Rewrite to check for Rails cached page
26
+ RewriteRule ^([^.]+)$ $1.html [QSA]
27
+
28
+ # Redirect all non-static requests to cluster
29
+ RewriteCond %{DOCUMENT_ROOT%>/%{REQUEST_FILENAME%> !-f
30
+ RewriteRule ^/(.*)$ balancer://<%= application %>_mongrel_cluster%{REQUEST_URI%> [P,QSA,L]
31
+
32
+ # Deflate
33
+ AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css
34
+ BrowserMatch ^Mozilla/4 gzip-only-text/html
35
+ BrowserMatch ^Mozilla/4.0[678] no-gzip
36
+ BrowserMatch bMSIE !no-gzip !gzip-only-text/html
37
+
38
+ # Uncomment for deflate debugging
39
+ #DeflateFilterNote Input input_info
40
+ #DeflateFilterNote Output output_info
41
+ #DeflateFilterNote Ratio ratio_info
42
+ #LogFormat '"%r" %{output_info%>n/%{input_info%>n (%{ratio_info%>n%%)' deflate
43
+ #CustomLog logs/<%= application %>_deflate_log deflate
44
+
@@ -0,0 +1,39 @@
1
+ NameVirtualHost *:80
2
+ <VirtualHost *:80>
3
+ Include /etc/apache2/vhosts.d/<%= application %>.common
4
+
5
+ ErrorLog <%=deploy_to %>/current/log/<%= application %>_errors_log
6
+ CustomLog <%=deploy_to %>/current/log/<%= application %>_log combined
7
+ </VirtualHost>
8
+
9
+ <% if ssl_required %>
10
+ NameVirtualHost *:443
11
+ <VirtualHost *:443>
12
+ Include /etc/apache2/vhosts.d/<%= application %>.common
13
+ RequestHeader set X_FORWARDED_PROTO 'https'
14
+ SSLEngine on
15
+ SSLCertificateFile <%= deploy_to %>/current/config/<%= application %>.pem
16
+ SSLCertificateKeyFile <%= deploy_to %>/current/config/<%= application %>.key
17
+ SSLCertificateChainFile <%= deploy_to %>/current/config/<%= application %>.crt
18
+
19
+ ErrorLog <%= deploy_to %>/current/log/ssl_<%= application %>_errors_log
20
+ CustomLog <%= deploy_to %>/current/log/ssl_<%= application %>_log combined
21
+ </VirtualHost>
22
+ <% end %>
23
+
24
+
25
+ <Proxy balancer://<%= application %>_mongrel_cluster>
26
+ <% (0..mongrel_servers-1).each do |server| %>
27
+ BalancerMember http://127.0.0.1:<%= mongrel_port + server %>
28
+ <% end %>
29
+
30
+ </Proxy>
31
+
32
+ Listen <%= mongrel_port + 81 %>
33
+ <VirtualHost *:<%= mongrel_port + 81 %>>
34
+ <Location />
35
+ SetHandler balancer-manager
36
+ Deny from all
37
+ Allow from localhost
38
+ </Location>
39
+ </VirtualHost>
@@ -0,0 +1,28 @@
1
+ # Deployment database.yml
2
+ login: &login
3
+ adapter: <%= database_adapter %>
4
+ username: <%= database_username %>
5
+ password: <%= database_password %>
6
+ <% unless fetch(:database_host, "").empty? %>
7
+ host: <%= database_host %>
8
+ <% end %>
9
+ <% unless fetch(:database_socket, "").empty? %>
10
+ socket: <%= database_socket %>
11
+ <% end %>
12
+
13
+ # Leave dev and test off, so accedents don't happen
14
+ #development:
15
+ # database: <%= application %>_development
16
+ # <<: *login
17
+
18
+ #test:
19
+ # database: <%= application %>_test
20
+ # <<: *login
21
+
22
+ staging:
23
+ database: <%= application %>_staging
24
+ <<: *login
25
+
26
+ production:
27
+ database: <%= application %>_production
28
+ <<: *login
@@ -0,0 +1,33 @@
1
+
2
+ #Install needed packages
3
+ `gem install mongrel_cluster`
4
+
5
+ #Create the deployment user
6
+ `useradd -g users -G wheel -m <%= deploy_username %>`
7
+ `echo "<%= deploy_username %>:<%= deploy_password %>" | chpasswd`
8
+
9
+ #Add to known hosts
10
+ `echo "github.com,65.74.177.129 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==" >> /home/<%= deploy_username %>/.ssh/known_hosts`
11
+ `chown <%= deploy_username %>:<%= group %> /home/<%= deploy_username %>/.ssh/known_hosts`
12
+
13
+ #Mount S3
14
+ `echo "<%= s3_id %>:<%= s3_key %>" > /etc/passwd-s3fs`
15
+ `mkdir -p /mnt/s3fs`
16
+ `modprobe fuse`
17
+ `echo "s3fs#<%= s3_backup_bucket %> /mnt/s3fs fuse allow_other,accessKeyId=<%= s3_id %>,secretAccessKey=<%= s3_key %> 0 0 " >> /etc/fstab`
18
+ `mount -a`
19
+
20
+ #Mysql password setting
21
+ `/etc/init.d/mysql start`
22
+ `rc-update mysql default`
23
+ `mysqladmin -uroot password "<%= mysql_root_password %>"`
24
+ `mysqladmin -uroot -p<%= mysql_root_password %> flush-privileges `
25
+
26
+ #Delete everything after the RUN ONCE in /etc/conf.d/local.start
27
+ file_in = File.open("/etc/conf.d/local.start", "r")
28
+ file_out = File.open("/etc/conf.d/local.new", "w")
29
+ while (line = file_in.readline)
30
+ file_out.puts(line)
31
+ break if line =~ /RUN ONCE/
32
+ end
33
+ File.rename("/etc/conf.d/local.new", "/etc/conf.d/local.start")
@@ -0,0 +1,28 @@
1
+ #!/sbin/runscript
2
+ # Distributed under the terms of the GNU General Public License v2
3
+
4
+ MERB_DIR="<%= current_path %>"
5
+ MERB_PORT="8<%= precedence %>00"
6
+ depend() {
7
+ need net
8
+ use mysql logger
9
+ after sshd
10
+ }
11
+
12
+ start() {
13
+ ebegin "Starting Merb: <%= application %>"
14
+ cd ${MERB_DIR} && ./bin/merb -c <%= mongrel_servers %> -p ${MERB_PORT} -e <%= rails_env %>
15
+ eend $?
16
+ }
17
+ stop() {
18
+ ebegin "Stopping Merb: <%= application %>"
19
+ cd ${MERB_DIR} && ./bin/merb -K all -e <%= rails_env %>
20
+ eend $?
21
+ }
22
+
23
+ status() {
24
+ ebegin "Status for Merb: <%= application %>"
25
+ echo 'currenty not implemented'
26
+ #cd ${MERB_DIR} && ./bin/merb
27
+ eend $?
28
+ }
@@ -0,0 +1,37 @@
1
+ #!/sbin/runscript
2
+ # Distributed under the terms of the GNU General Public License v2
3
+
4
+ MONGREL_BIN="/usr/bin/mongrel_rails"
5
+ MONGREL_CONF="/etc/mongrel_cluster/<%= application %>.yml"
6
+
7
+ depend() {
8
+ need net
9
+ use mysql logger
10
+ after sshd
11
+ }
12
+
13
+ before() {
14
+ if [ "$MONGREL_PORT" ]; then
15
+ MONGREL_ARGS=" --only $MONGREL_PORT"
16
+ fi
17
+ }
18
+
19
+ start() {
20
+ before;
21
+ ebegin "Starting Mongrel: <%= application %>"
22
+ ${MONGREL_BIN} cluster::start -C ${MONGREL_CONF} --clean ${MONGREL_ARGS}
23
+ eend $?
24
+ }
25
+ stop() {
26
+ before;
27
+ ebegin "Stopping Mongrel: <%= application %>"
28
+ ${MONGREL_BIN} cluster::stop -C ${MONGREL_CONF} ${MONGREL_ARGS}
29
+ eend $?
30
+ }
31
+
32
+ status() {
33
+ before;
34
+ ebegin "Status for Mongrel: ${SITE}"
35
+ ${MONGREL_BIN} cluster::status -c ${MONGREL_CONF} ${MONGREL_ARGS}
36
+ eend $?
37
+ }
@@ -0,0 +1,55 @@
1
+ user nginx nginx;
2
+ worker_processes 6;
3
+
4
+ error_log /var/log/nginx/error.log info;
5
+
6
+ events {
7
+ worker_connections 1024;
8
+ use epoll;
9
+ }
10
+
11
+ http {
12
+ include /etc/nginx/mime.types;
13
+ default_type application/octet-stream;
14
+
15
+ log_format main
16
+ '$remote_addr - $remote_user [$time_local] '
17
+ '"$request" $status $bytes_sent '
18
+ '"$http_referer" "$http_user_agent" '
19
+ '"$gzip_ratio"';
20
+ access_log /var/log/nginx/access.log main;
21
+
22
+ client_header_timeout 10m;
23
+ client_body_timeout 10m;
24
+ send_timeout 10m;
25
+
26
+ connection_pool_size 256;
27
+ client_header_buffer_size 1k;
28
+ large_client_header_buffers 4 2k;
29
+ request_pool_size 4k;
30
+ server_names_hash_bucket_size 64;
31
+
32
+ gzip on;
33
+ gzip_min_length 1100;
34
+ gzip_buffers 4 8k;
35
+ gzip_http_version 1.0;
36
+ gzip_comp_level 2;
37
+ gzip_proxied any;
38
+ gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml
39
+ application/xml+rss text/javascript;
40
+
41
+
42
+ #output_buffers 1 32k;
43
+ #postpone_output 1460;
44
+
45
+ sendfile on;
46
+ tcp_nopush on;
47
+ tcp_nodelay off; #TODO - load test both ways
48
+
49
+ keepalive_timeout 75 20;
50
+
51
+ ignore_invalid_headers on;
52
+
53
+ index index.html;
54
+ include /etc/nginx/vhosts/*.conf;
55
+ }
@@ -0,0 +1,132 @@
1
+ upstream <%= application %> {
2
+ <% (0..mongrel_servers-1).each do |server|%>
3
+ server 127.0.0.1:<%= mongrel_port + server %>;
4
+ <% end %>
5
+ }
6
+
7
+ server {
8
+ listen 80;
9
+ server_name <%= server_name %>;
10
+
11
+ access_log /var/log/nginx/<%= application %>.access_log main;
12
+ error_log /var/log/nginx/<%= application %>.error_log info;
13
+
14
+ root <%= deploy_to %>/current/public;
15
+
16
+ # for cap's deploy:web:disable task
17
+ if (-f $document_root/system/maintenance.html) {
18
+ rewrite ^(.*)$ /system/maintenance.html last;
19
+ break;
20
+ }
21
+
22
+ <% if forced_prefix.nil? %>
23
+ <% elsif !forced_prefix %>
24
+ if ($host ~* "www") {
25
+ rewrite ^(.*)$ http://<%= server_name %>$1 redirect;
26
+ break;
27
+ }
28
+ <% else %>
29
+ if ($host !~* "<%= forced_prefix %>") {
30
+ rewrite ^(.*)$ http://<%= forced_prefix %>.<%= server_name %>$1 redirect;
31
+ break;
32
+ }
33
+ <% end %>
34
+ location / {
35
+ proxy_set_header X-Real-IP $remote_addr;
36
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
37
+ proxy_set_header Host $http_host;
38
+ proxy_redirect false;
39
+
40
+ # If the file exists as a static file serve it directly without
41
+ # running all the other rewite tests on it
42
+ if (-f $request_filename) {
43
+ break;
44
+ }
45
+
46
+ # If this is a directory and the index.html file exists go there
47
+ if (-f $request_filename/index.html) {
48
+ rewrite (.*) $1/index.html break;
49
+ }
50
+
51
+ # This is for page caching
52
+ if (-f $request_filename.html) {
53
+ rewrite (.*) $1.html break;
54
+ }
55
+
56
+ if (!-f $request_filename) {
57
+ proxy_pass http://<%= application %>;
58
+ break;
59
+ }
60
+ }
61
+ error_page 500 502 503 504 /50x.html;
62
+ location = /50x.html {
63
+ root <%= deploy_to %>/current/public;
64
+ }
65
+ }
66
+
67
+ <% if ssl_required %>
68
+ ##ssl portion
69
+ server {
70
+ listen 443;
71
+ server_name www.<%= server_name %>;
72
+
73
+ ssl on;
74
+ ssl_certificate <%= deploy_to %>/current/config/<%= application %>.pem;
75
+ ssl_certificate_key <%= deploy_to %>/current/config/<%= application %>.key;
76
+
77
+ access_log /var/log/nginx/<%= application %>.ssl_access_log main;
78
+ error_log /var/log/nginx/<%= application %>.ssl_error_log info;
79
+
80
+ root <%= deploy_to %>/current/public;
81
+
82
+ # for cap's deploy:web:disable task
83
+ if (-f $document_root/system/maintenance.html) {
84
+ rewrite ^(.*)$ /system/maintenance.html last;
85
+ break;
86
+ }
87
+ <% if defined?(forced_prefix) && forced_prefix %>
88
+ if ($host !~* "<%= forced_prefix %>") {
89
+ rewrite ^(.*)$ http://<%= forced_prefix %>.<%= server_name %>$1 redirect;
90
+ break;
91
+ }
92
+ <% elsif defined?(forced_prefix) && !forced_prefix %>
93
+ if ($host ~* "www") {
94
+ rewrite ^(.*)$ http://<%= server_name %>$1 redirect;
95
+ break;
96
+ }
97
+ <% end %>
98
+
99
+ location / {
100
+ proxy_set_header X-Real-IP $remote_addr;
101
+ proxy_set_header X_FORWARDED_PROTO https;
102
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
103
+ proxy_set_header Host $http_host;
104
+ proxy_redirect false;
105
+
106
+ # If the file exists as a static file serve it directly without
107
+ # running all the other rewite tests on it
108
+ if (-f $request_filename) {
109
+ break;
110
+ }
111
+
112
+ # If this is a directory and the index.html file exists go there
113
+ if (-f $request_filename/index.html) {
114
+ rewrite (.*) $1/index.html break;
115
+ }
116
+
117
+ # This is for page caching
118
+ if (-f $request_filename.html) {
119
+ rewrite (.*) $1.html break;
120
+ }
121
+
122
+ if (!-f $request_filename) {
123
+ proxy_pass http://<%= application %>;
124
+ break;
125
+ }
126
+ }
127
+ error_page 500 502 503 504 /50x.html;
128
+ location = /50x.html {
129
+ root <%= deploy_to %>/current/public;
130
+ }
131
+ }
132
+ <% end %>