railsmachine 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ load 'config/deploy'
3
+ namespace :deploy do
4
+
5
+ desc <<-DESC
6
+ #{app_server.to_s == 'mongrel' ? "Start the mongrel processes on the app server." : "This task no effect when using Passenger as your application server."}
7
+ DESC
8
+ task :start, :roles => :app do
9
+ application_servlet.start
10
+ end
11
+
12
+ desc <<-DESC
13
+ Restart the #{app_server} processes on the app server.
14
+ DESC
15
+ task :restart, :roles => :app do
16
+ application_servlet.restart
17
+ end
18
+
19
+ desc <<-DESC
20
+ #{app_server.to_s == 'mongrel' ? "Stop the mongrel processes on the app server." : "This task no effect when using Passenger as your application server."}
21
+ DESC
22
+ task :stop, :roles => :app do
23
+ application_servlet.stop
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -13,6 +13,8 @@ Capistrano::Configuration.instance(:must_exist).load do
13
13
  set :mongrel_log_file, nil
14
14
  set :mongrel_config_script, nil
15
15
 
16
+ load 'config/deploy'
17
+
16
18
  namespace :mongrel do
17
19
 
18
20
  namespace :cluster do
@@ -87,38 +89,29 @@ Capistrano::Configuration.instance(:must_exist).load do
87
89
  set_mongrel_conf
88
90
  send(run_method, "#{mongrel_rails} cluster::status -C #{mongrel_conf}")
89
91
  end
92
+
93
+ desc <<-DESC
94
+ Remove the mongrel cluster configuration from the app server.
95
+ DESC
96
+ task :remove, :roles => :app do
97
+ set_mongrel_conf
98
+ alt_mongrel_conf = mongrel_conf.gsub('.conf','.yml')
99
+ run("[ -f #{mongrel_conf} ] || [ -f #{alt_mongrel_conf} ] && echo \"yes\" || echo \"no\"") do |c, s, o|
100
+ if o =~ /yes?/
101
+ exit if Capistrano::CLI.ui.ask("WARNING: You are about to remove your mongrel cluster configuration. Are you sure you want to proceed? [y/N]").upcase != "Y"
102
+ mongrel.cluster.stop
103
+ sudo("rm -f #{mongrel_conf}")
104
+ sudo("rm -f #{alt_mongrel_conf}")
105
+ end
106
+ end
107
+ end
90
108
 
91
109
  end
92
110
 
93
111
  end
94
-
95
- namespace :deploy do
96
-
97
- desc <<-DESC
98
- Start the Mongrel processes on the app server by calling start_mongrel_cluster.
99
- DESC
100
- task :start, :roles => :app do
101
- mongrel.cluster.start
102
- end
103
-
104
- desc <<-DESC
105
- Restart the Mongrel processes on the app server by calling restart_mongrel_cluster.
106
- DESC
107
- task :restart, :roles => :app do
108
- mongrel.cluster.restart
109
- end
110
-
111
- desc <<-DESC
112
- Stop the Mongrel processes on the app server by calling stop_mongrel_cluster.
113
- DESC
114
- task :stop, :roles => :app do
115
- mongrel.cluster.stop
116
- end
117
-
118
- end
119
112
 
120
113
  def set_mongrel_conf
121
- set :mongrel_conf, "/etc/mongrel_cluster/#{application}.yml" unless mongrel_conf
114
+ set :mongrel_conf, "/etc/mongrel_cluster/#{application}.conf" unless mongrel_conf
122
115
  end
123
116
 
124
117
  def set_mongrel_pid_file
@@ -0,0 +1,20 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ set :use_mod_rewrite, false
3
+ load 'config/deploy'
4
+ namespace :passenger do
5
+
6
+ [:start, :stop].each do |t|
7
+ task t, :roles => :app do
8
+ puts "The :#{t} task no effect when using Passenger as your application server."
9
+ end
10
+ end
11
+
12
+ desc <<-DESC
13
+ Restart the Passenger processes on the app server by touching tmp/restart.txt.
14
+ DESC
15
+ task :restart, :roles => :app do
16
+ run "touch #{current_path}/tmp/restart.txt"
17
+ end
18
+
19
+ end
20
+ end
@@ -26,7 +26,7 @@ Capistrano::Configuration.instance(:must_exist).load do
26
26
 
27
27
  set :mysql_admin, nil
28
28
 
29
- namespace :mysql do
29
+ namespace :db do
30
30
 
31
31
  desc "Execute MySQL statements using --execute option. Set the 'sql' variable."
32
32
  task :execute, :roles => :db, :only => { :primary => true } do
@@ -40,7 +40,7 @@ Capistrano.plugin :pgsql, PostgreSQLMethods
40
40
 
41
41
  Capistrano::Configuration.instance(:must_exist).load do
42
42
 
43
- namespace :postgresql do
43
+ namespace :db do
44
44
 
45
45
  desc "Create PosgreSQL database and user based on config/database.yml"
46
46
  task :setup, :roles => :db, :only => { :primary => true } do
@@ -0,0 +1,14 @@
1
+ require 'capistrano'
2
+ require 'capistrano/cli'
3
+
4
+ Capistrano::Configuration.instance(:must_exist).load do
5
+
6
+ namespace :db do
7
+
8
+ desc "Do nothing when using sqlite3."
9
+ task :setup, :roles => :db, :only => { :primary => true } do
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,44 @@
1
+ require 'fileutils'
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+
4
+ namespace :localrepo do
5
+
6
+ desc "Setup directory structure and initialize git repository on remote server"
7
+ task :setup, :roles => :scm do
8
+ dir = "#{deploy_to}/repos/#{application}.git"
9
+ run "mkdir -p #{dir}"
10
+ sudo "chown -R #{user}:#{user} #{dir}"
11
+ run "cd #{dir} && git --bare init"
12
+ run "chmod 770 #{dir}"
13
+ end
14
+
15
+ desc "Import code into remote git repository."
16
+ task :import do
17
+ puts "Initializing local git repository"
18
+ system "git init"
19
+
20
+ puts "Adding remote server pointing to #{repository}"
21
+ system "git remote add origin #{repository}"
22
+
23
+ puts "Adding .gitignore file"
24
+ system "echo 'log/*'>> .gitignore"
25
+ system "echo 'tmp/*'>> .gitignore"
26
+ system "echo '.DS_Store'>> .gitignore"
27
+ system "echo 'public/cache/**/*'>> .gitignore"
28
+ system "git add .gitignore"
29
+
30
+ puts "Committing application locally"
31
+ system "git add *"
32
+ system 'git commit -a -v -m "initial import of site"'
33
+
34
+ puts "Pushing application to the remote server. The name of the branch is:"
35
+ system "git remote"
36
+ system "git push origin master"
37
+
38
+ puts "git setup complete"
39
+ puts "You can clone this repository with git clone #{repository} #{application}"
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,47 @@
1
+ require 'fileutils'
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+
4
+ namespace :localrepo do
5
+
6
+ desc "Setup svn repository"
7
+ task :setup, :roles => :scm do
8
+ dir = "#{deploy_to}/repos"
9
+ run "mkdir -p #{dir}"
10
+ sudo "chown -R #{user}:#{user} #{dir}"
11
+ run "chmod 770 #{dir}"
12
+ run "svnadmin create #{dir}"
13
+ end
14
+
15
+ desc "Import code into svn repository."
16
+ task :import do
17
+ new_path = Dir.pwd + "_machine"
18
+ tags = repository.sub("trunk", "tags")
19
+ branches = repository.sub("trunk", "branches")
20
+ puts "Adding branches and tags"
21
+ system "svn mkdir -m 'Adding tags and branches directories' #{tags} #{branches}"
22
+ puts "Importing application."
23
+ system "svn import #{repository} -m 'Import'"
24
+ puts "Checking out to new directory."
25
+ system "svn co #{repository} #{new_path}"
26
+ cwd = Dir.getwd
27
+ Dir.chdir new_path
28
+ puts "removing log directory contents from svn"
29
+ system "svn remove log/*"
30
+ puts "ignoring log directory"
31
+ system "svn propset svn:ignore '*.log' log/"
32
+ system "svn update log/"
33
+ puts "removing tmp directory from svn"
34
+ system "svn remove tmp/"
35
+ puts "ignoring tmp directory"
36
+ system "svn propset svn:ignore '*' tmp/"
37
+ system "svn update tmp/"
38
+ puts "committing changes"
39
+ system "svn commit -m 'Removed and ignored log files and tmp'"
40
+ Dir.chdir cwd
41
+ puts "Your repository is: #{repository}"
42
+ puts "Please change to your new working directory: #{new_path}"
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -1,7 +1,8 @@
1
1
  require 'erb'
2
2
  Capistrano::Configuration.instance(:must_exist).load do
3
3
 
4
- set :apache_server_name, nil
4
+
5
+ set :apache_server_name, nil
5
6
  set :apache_conf, nil
6
7
  set :apache_default_vhost, false
7
8
  set :apache_default_vhost_conf, nil
@@ -14,62 +15,72 @@ Capistrano::Configuration.instance(:must_exist).load do
14
15
  set :apache_ssl_ip, nil
15
16
  set :apache_ssl_forward_all, false
16
17
 
18
+ load 'config/deploy'
19
+
17
20
  namespace :apache do
18
21
 
19
22
  desc "Configure Apache. This uses the :use_sudo
20
23
  variable to determine whether to use sudo or not. By default, :use_sudo is
21
24
  set to true."
22
- task :configure, :roles => :web do
25
+ task :configure, :roles => :web do
23
26
  set_apache_conf
24
27
 
28
+ run("[ -f #{ apache_conf} ] && echo \"yes\" || echo \"no\"") do |c, s, o|
29
+ if o =~ /yes?/
30
+ backup = "#{ apache_conf}.old.#{Time.now.strftime('%Y%m%d%H%M%S')}"
31
+ send(run_method, "cp #{ apache_conf} #{backup}")
32
+ exit if Capistrano::CLI.ui.ask("WARNING: You are about to change your existing Apache configuration. A backup has been created at #{backup}. Are you sure you want to proceed? [y/N]").upcase != "Y"
33
+ end
34
+ end
35
+
25
36
  server_aliases = []
26
- server_aliases << "www.#{apache_server_name}"
27
- server_aliases.concat apache_server_aliases
37
+ server_aliases << "www.#{ apache_server_name}"
38
+ server_aliases.concat apache_server_aliases
28
39
  set :apache_server_aliases_array, server_aliases
29
40
 
30
- file = File.join(File.dirname(__FILE__), "templates", "httpd.conf")
41
+ file = File.join(File.dirname(__FILE__), "templates", app_server.to_s, "httpd.conf")
31
42
  template = File.read(file)
32
43
  buffer = ERB.new(template).result(binding)
33
44
 
34
- if apache_ssl_enabled
35
- file = File.join(File.dirname(__FILE__), "templates", "httpd-ssl.conf")
45
+ if apache_ssl_enabled
46
+ file = File.join(File.dirname(__FILE__), "templates", app_server.to_s, "httpd-ssl.conf")
36
47
  template = File.read(file)
37
48
  ssl_buffer = ERB.new(template).result(binding)
38
49
  buffer += ssl_buffer
39
50
  end
40
51
 
41
52
  put buffer, "#{shared_path}/httpd.conf", :mode => 0444
42
- send(run_method, "cp #{shared_path}/httpd.conf #{apache_conf}")
53
+ send(run_method, "cp #{shared_path}/httpd.conf #{ apache_conf}")
43
54
  send(run_method, "rm -f #{shared_path}/httpd.conf")
44
55
  end
45
56
 
46
57
  desc "Start Apache "
47
58
  task :start, :roles => :web do
48
- send(run_method, "#{apache_ctl} start")
59
+ send(run_method, "#{ apache_ctl} start")
49
60
  end
50
61
 
51
62
  desc "Restart Apache "
52
63
  task :restart, :roles => :web do
53
- send(run_method, "#{apache_ctl} restart")
64
+ send(run_method, "#{ apache_ctl} restart")
54
65
  end
55
66
 
56
67
  desc "Stop Apache "
57
68
  task :stop, :roles => :web do
58
- send(run_method, "#{apache_ctl} stop")
69
+ send(run_method, "#{ apache_ctl} stop")
59
70
  end
60
71
 
61
72
  desc "Reload Apache "
62
73
  task :reload, :roles => :web do
63
- send(run_method, "#{apache_ctl} reload")
74
+ send(run_method, "#{ apache_ctl} reload")
64
75
  end
65
76
 
66
77
  end
67
78
 
68
79
  def set_apache_conf
69
- if apache_default_vhost
70
- set :apache_conf, "/etc/httpd/conf/default.conf" unless apache_default_vhost_conf
80
+ if apache_default_vhost
81
+ set :apache_conf, "/etc/httpd/conf/default.conf" unless apache_default_vhost_conf
71
82
  else
72
- set :apache_conf, "/etc/httpd/conf/apps/#{application}.conf" unless apache_conf
83
+ set :apache_conf, "/etc/httpd/conf/apps/#{application}.conf" unless apache_conf
73
84
  end
74
85
  end
75
86
 
@@ -1,9 +1,14 @@
1
- <VirtualHost <%= apache_ssl_ip %>:443>
1
+ <VirtualHost <%= apache_ssl_ip %>:443>
2
2
 
3
- ServerName <%= apache_server_name %>
4
- <% apache_server_aliases_array.each do |a| %>
3
+ ServerName <%= apache_server_name %>
4
+ <% apache_server_aliases_array.each do |a| %>
5
5
  ServerAlias <%= "#{a}" %>
6
6
  <% end %>
7
+
8
+ <IfModule passenger_module>
9
+ RailsAutoDetect off
10
+ </IfModule>
11
+
7
12
  DocumentRoot <%= "#{current_path}/public" %>
8
13
 
9
14
  <Directory <%= "#{current_path}/public" %>>
@@ -15,10 +20,10 @@ DocumentRoot <%= "#{current_path}/public" %>
15
20
 
16
21
  # Configure mongrel_cluster
17
22
  <Proxy balancer://<%= "#{application}_cluster" %>>
18
- <% start_port = apache_proxy_port %>
19
- <% end_port = apache_proxy_port + apache_proxy_servers - 1 %>
23
+ <% start_port = apache_proxy_port %>
24
+ <% end_port = apache_proxy_port + apache_proxy_servers - 1 %>
20
25
  <% start_port.upto(end_port) do |port| %>
21
- BalancerMember http://<%= "#{apache_proxy_address}:#{port.to_s}" %>
26
+ BalancerMember http://<%= "#{ apache_proxy_address}:#{port.to_s}" %>
22
27
  <% end %>
23
28
  </Proxy>
24
29
 
@@ -46,7 +51,7 @@ RequestHeader set X-Forwarded-Proto "https"
46
51
  RewriteRule ^/(.*)$ balancer://<%= "#{application}_cluster" %>%{REQUEST_URI} [P,QSA,L]
47
52
 
48
53
  # Deflate
49
- AddOutputFilterByType DEFLATE text/html text/plain text/xml
54
+ AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript
50
55
  BrowserMatch ^Mozilla/4 gzip-only-text/html
51
56
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
52
57
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
@@ -55,7 +60,8 @@ BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
55
60
  SSLEngine on
56
61
 
57
62
  # SSL Cipher Suite:
58
- SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
63
+ SSLProtocol -all +SSLv3
64
+ SSLCipherSuite SSLv3:+HIGH:+MEDIUM
59
65
 
60
66
  # Server Certificate
61
67
  SSLCertificateFile /etc/httpd/conf/ssl.crt/<%= domain %>.crt
@@ -1,10 +1,14 @@
1
+ <VirtualHost <%= apache_ssl_enabled ? apache_ssl_ip : "*" %>:80>
2
+ ServerName <%= apache_server_name %>
3
+ <% apache_server_aliases_array.each do |a| %>
4
+ ServerAlias <%= "#{a}" %>
5
+ <% end %>
1
6
 
7
+ <IfModule passenger_module>
8
+ RailsAutoDetect off
9
+ </IfModule>
10
+
2
11
 
3
- <VirtualHost <%= apache_ssl_enabled ? apache_ssl_ip : "*" %>:80>
4
- ServerName <%= apache_server_name %>
5
- <% apache_server_aliases_array.each do |a| %>
6
- ServerAlias <%= "#{a}" %>
7
- <% end %>
8
12
  DocumentRoot <%= "#{current_path}/public" %>
9
13
 
10
14
  <Directory <%= "#{current_path}/public" %>>
@@ -16,16 +20,16 @@
16
20
 
17
21
  # Configure mongrel_cluster
18
22
  <Proxy balancer://<%= "#{application}_cluster" %>>
19
- <% start_port = apache_proxy_port %>
20
- <% end_port = apache_proxy_port + apache_proxy_servers - 1 %>
23
+ <% start_port = apache_proxy_port %>
24
+ <% end_port = apache_proxy_port + apache_proxy_servers - 1 %>
21
25
  <% start_port.upto(end_port) do |port| %>
22
- BalancerMember http://<%= "#{apache_proxy_address}:#{port.to_s}" %>
26
+ BalancerMember http://<%= "#{ apache_proxy_address}:#{port.to_s}" %>
23
27
  <% end %>
24
28
  </Proxy>
25
29
 
26
30
  RewriteEngine On
27
31
 
28
- <% if apache_ssl_enabled && apache_ssl_forward_all %>
32
+ <% if apache_ssl_enabled && apache_ssl_forward_all %>
29
33
  RewriteRule ^(.*)$ https://<%= domain %>$1
30
34
  <% end %>
31
35
 
@@ -49,7 +53,7 @@
49
53
  RewriteRule ^/(.*)$ balancer://<%= "#{application}_cluster" %>%{REQUEST_URI} [P,QSA,L]
50
54
 
51
55
  # Deflate
52
- AddOutputFilterByType DEFLATE text/html text/plain text/xml
56
+ AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript
53
57
  BrowserMatch ^Mozilla/4 gzip-only-text/html
54
58
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
55
59
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
@@ -0,0 +1,60 @@
1
+ <VirtualHost <%= apache_ssl_ip %>:443>
2
+ ServerName <%= apache_server_name %>
3
+ <% apache_server_aliases_array.each do |a| %>
4
+ ServerAlias <%= "#{a}" %>
5
+ <% end %>
6
+ DocumentRoot <%= "#{current_path}/public" %>
7
+
8
+ <Directory <%= "#{current_path}/public" %>>
9
+ Options FollowSymLinks
10
+ AllowOverride None
11
+ Order allow,deny
12
+ Allow from all
13
+ </Directory>
14
+
15
+ # set the environment
16
+ RailsEnv <%= rails_env.to_s %>
17
+
18
+ <% if use_mod_rewrite %>
19
+ RailsAllowModRewrite on
20
+ RewriteEngine On
21
+
22
+ # Prevent access to .svn directories
23
+ RewriteRule ^(.*/)?\.svn/ - [F,L]
24
+ ErrorDocument 403 "Access Forbidden"
25
+
26
+ # Check for maintenance file and redirect all requests
27
+ RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
28
+ RewriteCond %{SCRIPT_FILENAME} !maintenance.html
29
+ RewriteRule ^.*$ /system/maintenance.html [L]
30
+
31
+ <% end %>
32
+
33
+ # Deflate
34
+ AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript
35
+ BrowserMatch ^Mozilla/4 gzip-only-text/html
36
+ BrowserMatch ^Mozilla/4\.0[678] no-gzip
37
+ BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
38
+
39
+ # SSL Engine Switch
40
+ SSLEngine on
41
+
42
+ # SSL Cipher Suite:
43
+ SSLProtocol -all +SSLv3
44
+ SSLCipherSuite SSLv3:+HIGH:+MEDIUM
45
+
46
+ # Server Certificate
47
+ SSLCertificateFile /etc/httpd/conf/ssl.crt/<%= domain %>.crt
48
+
49
+ # Server Private Key
50
+ SSLCertificateKeyFile /etc/httpd/conf/ssl.key/<%= domain %>.key
51
+
52
+ BrowserMatch ".*MSIE.*" \
53
+ nokeepalive ssl-unclean-shutdown \
54
+ downgrade-1.0 force-response-1.0
55
+
56
+ ErrorLog logs/<%= domain %>-error_log
57
+ CustomLog logs/<%= domain %>-access_log combined
58
+ CustomLog logs/<%= domain %>-ssl_log \
59
+ "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
60
+ </VirtualHost>