Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjparrott committed Dec 17, 2008
1 parent 225a45e commit 4d73672
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 228 deletions.
28 changes: 14 additions & 14 deletions lib/railsmachine/generators/railsmachine/templates/deploy.rb
Expand Up @@ -57,19 +57,19 @@
# =============================================================================
# WEB SERVER OPTIONS
# =============================================================================
# set :httpd, "apache" # apache or nginx
# set : apache_server_name, domain
# set : apache_server_aliases, %w{alias1 alias2}
# set : apache_default_vhost, true # force use of apache_default_vhost_config
# set : apache_default_vhost_conf, "/etc/httpd/conf/default.conf"
# set : apache_conf, "/etc/httpd/conf/apps/#{application}.conf"
# set : apache_proxy_port, 8000
# set : apache_proxy_servers, 2
# set : apache_proxy_address, "127.0.0.1"
# set : apache_ssl_enabled, false
# set : apache_ssl_ip, "127.0.0.1"
# set : apache_ssl_forward_all, false
# set : apache_ctl, "/etc/init.d/httpd"
# set :httpd, "apache" # apache
# set :apache_server_name, domain
# set :apache_server_aliases, %w{alias1 alias2}
# set :apache_default_vhost, true # force use of apache_default_vhost_config
# set :apache_default_vhost_conf, "/etc/httpd/conf/default.conf"
# set :apache_conf, "/etc/httpd/conf/apps/#{application}.conf"
# set :apache_proxy_port, 8000
# set :apache_proxy_servers, 2
# set :apache_proxy_address, "127.0.0.1"
# set :apache_ssl_enabled, false
# set :apache_ssl_ip, "127.0.0.1"
# set :apache_ssl_forward_all, false
# set :apache_ctl, "/etc/init.d/httpd"



Expand All @@ -93,7 +93,7 @@
# =============================================================================
# SCM OPTIONS
# =============================================================================
# set :scm, :subversion
# set :scm, :subversion # :subversion or :git
set :repository, scm == :subversion ? "svn+ssh://#{user}@#{domain}#{deploy_to}/repos/trunk" : "ssh://#{user}@#{domain}#{deploy_to}/repos"

# =============================================================================
Expand Down
127 changes: 58 additions & 69 deletions lib/railsmachine/recipes.rb
Expand Up @@ -8,7 +8,7 @@
set :valid_scms, [:subversion, :git]

set :httpd, :apache
set :valid_httpds, [:apache, :nginx]
set :valid_httpds, [:apache]

set :app_server, :mongrel
set :valid_app_servers, [:mongrel, :passenger]
Expand Down Expand Up @@ -67,7 +67,9 @@
web.setup
end

desc "A macro task that restarts the application and web servers"
desc <<-DESC
A macro task that restarts the application and web servers
DESC
task :restart do
app.restart
web.restart
Expand All @@ -77,47 +79,42 @@

namespace :app do

desc "Setup #{app_server}"
desc <<-DESC
Setup #{app_server}
DESC
task :setup, :roles => :app do
case app_server.to_s
when "mongrel"
setup_mongrel
when "passenger"
setup_passenger
# do nothing
end
end

desc "Restart application server."
desc <<-DESC
Restart application server.
DESC
task :restart, :roles => :app do
case app_server.to_s
when "mongrel"
restart_mongrel
when "passenger"
restart_passenger
end
application_servlet.restart
end

desc "Start application server."
desc <<-DESC
Start application server.
DESC
task :start, :roles => :app do
case app_server.to_s
when "mongrel"
start_mongrel
when "passenger"
start_passenger
end
application_servlet.start
end

desc "Stop application server."
desc <<-DESC
Stop application server.
DESC
task :stop, :roles => :app do
case app_server.to_s
when "mongrel"
stop_mongrel
when "passenger"
stop_passenger
end
application_servlet.stop
end

desc "Switch your application to run on mongrel or passenger."
desc <<-DESC
Switch your application to run on mongrel or passenger.
DESC
task :switch do
case app_server.to_s
when "mongrel"
Expand All @@ -129,14 +126,18 @@

namespace :symlinks do

desc "Setup application symlinks in the public"
desc <<-DESC
Setup application symlinks in the public
DESC
task :setup, :roles => [:app, :web] do
if app_symlinks
app_symlinks.each { |link| run "mkdir -p #{shared_path}/public/#{link}" }
end
end

desc "Link public directories to shared location."
desc <<-DESC
Link public directories to shared location.
DESC
task :update, :roles => [:app, :web] do
if app_symlinks
app_symlinks.each { |link| run "ln -nfs #{shared_path}/public/#{link} #{current_path}/public/#{link}" }
Expand All @@ -149,36 +150,48 @@

namespace :web do

desc "Setup web server."
desc <<-DESC
Setup web server.
DESC
task :setup, :roles => :web do
set : apache_server_name, domain unless apache_server_name
set :apache_server_name, domain unless apache_server_name
apache.configure
end

desc "Restart web server."
desc <<-DESC
Restart web server.
DESC
task :restart, :roles => :web do
apache.restart
end

desc "Reload web server configuration."
desc <<-DESC
Reload web server configuration.
DESC
task :reload, :roles => :web do
apache.reload
end

desc "Start web server."
desc <<-DESC
Start web server.
DESC
task :start, :roles => :web do
apache.start
end

desc "Stop web server."
desc <<-DESC
Stop web server.
DESC
task :stop, :roles => :web do
apache.stop
end

end

namespace :repos do
desc "Setup source control repository."
desc <<-DESC
Setup source control repository.
DESC
task :setup, :roles => :scm do
begin
sudo "chown -R #{user}:#{user} #{deploy_to.gsub(application,'')}"
Expand Down Expand Up @@ -207,39 +220,6 @@ def setup_mongrel
mongrel.cluster.configure
end

def restart_mongrel
set_mongrel_conf
mongrel.cluster.restart
end

def start_mongrel
set_mongrel_conf
mongrel.cluster.start
end

def stop_mongrel
set_mongrel_conf
mongrel.cluster.stop
end

def setup_passenger
set :pasenger_environment, rails_env
set :passenger_user, user unless passenger_user
set :passenger_group, passenger_user unless passenger_group
end

def restart_passenger
passenger.restart
end

def start_passenger
passenger.start
end

def stop_passenger
passenger.stop
end

def switch_to_mongrel
app.setup
app.start
Expand All @@ -252,7 +232,16 @@ def switch_to_passenger
mongrel.cluster.remove
web.restart
end


def application_servlet
case app_server.to_s
when 'mongrel'
mongrel.cluster
when 'passenger'
passenger
end
end

def invalid_variable_value(value, name, valid_options)
error_msg("'#{value}' is not a valid :#{name}. Please set :#{name} to one of the following: #{valid_options.join(", ")}")
end
Expand Down
6 changes: 3 additions & 3 deletions lib/railsmachine/recipes/app/deploy.rb
Expand Up @@ -6,21 +6,21 @@
#{app_server.to_s == 'mongrel' ? "Start the mongrel processes on the app server." : "This task no effect when using Passenger as your application server."}
DESC
task :start, :roles => :app do
app_server.to_s == 'mongrel' ? mongrel.cluster.start : passenger.start
application_servlet.start
end

desc <<-DESC
Restart the #{app_server} processes on the app server.
DESC
task :restart, :roles => :app do
app_server.to_s == 'mongrel' ? mongrel.cluster.restart : passenger.restart
application_servlet.restart
end

desc <<-DESC
#{app_server.to_s == 'mongrel' ? "Stop the mongrel processes on the app server." : "This task no effect when using Passenger as your application server."}
DESC
task :stop, :roles => :app do
app_server.to_s == 'mongrel' ? mongrel.cluster.stop : passenger.stop
application_servlet.stop
end

end
Expand Down
4 changes: 3 additions & 1 deletion lib/railsmachine/recipes/app/mongrel.rb
Expand Up @@ -90,7 +90,9 @@
send(run_method, "#{mongrel_rails} cluster::status -C #{mongrel_conf}")
end

desc "Remove the mongrel cluster configuration."
desc <<-DESC
Remove the mongrel cluster configuration from the app server.
DESC
task :remove, :roles => :app do
set_mongrel_conf
alt_mongrel_conf = mongrel_conf.gsub('.conf','.yml')
Expand Down
10 changes: 1 addition & 9 deletions lib/railsmachine/recipes/app/passenger.rb
@@ -1,15 +1,8 @@
Capistrano::Configuration.instance(:must_exist).load do
set :pasenger_environment, "production"
set :passenger_user, nil
set :passenger_group, nil
set :use_mod_rewrite, false

load 'config/deploy'

load 'config/deploy'
namespace :passenger do

[:start, :stop].each do |t|
desc "The :#{t} task no effect when using Passenger as your application server."
task t, :roles => :app do
puts "The :#{t} task no effect when using Passenger as your application server."
end
Expand All @@ -23,5 +16,4 @@
end

end

end
6 changes: 0 additions & 6 deletions lib/railsmachine/recipes/scm/git.rb
Expand Up @@ -34,12 +34,6 @@
puts "Pushing application to the remote server. The name of the branch is:"
system "git remote"
system "git push origin master"
puts "Creating edge branch on remote"
system "git push origin master:refs/heads/edge"
puts "create a local tracking edge branch"
system "git branch --track edge origin/edge"
puts "checking out edge repository"
system "git checkout edge"
puts "git setup complete"
puts "You can clone this repository with git clone #{repository} #{application}"
end
Expand Down
34 changes: 17 additions & 17 deletions lib/railsmachine/recipes/web/apache.rb
Expand Up @@ -2,18 +2,18 @@
Capistrano::Configuration.instance(:must_exist).load do


set : apache_server_name, nil
set : apache_conf, nil
set : apache_default_vhost, false
set : apache_default_vhost_conf, nil
set : apache_ctl, "/etc/init.d/httpd"
set : apache_server_aliases, []
set : apache_proxy_port, 8000
set : apache_proxy_servers, 2
set : apache_proxy_address, "127.0.0.1"
set : apache_ssl_enabled, false
set : apache_ssl_ip, nil
set : apache_ssl_forward_all, false
set :apache_server_name, nil
set :apache_conf, nil
set :apache_default_vhost, false
set :apache_default_vhost_conf, nil
set :apache_ctl, "/etc/init.d/httpd"
set :apache_server_aliases, []
set :apache_proxy_port, 8000
set :apache_proxy_servers, 2
set :apache_proxy_address, "127.0.0.1"
set :apache_ssl_enabled, false
set :apache_ssl_ip, nil
set :apache_ssl_forward_all, false

load 'config/deploy'

Expand All @@ -23,7 +23,7 @@
variable to determine whether to use sudo or not. By default, :use_sudo is
set to true."
task :configure, :roles => :web do
set_ apache_conf
set_apache_conf

run("[ -f #{ apache_conf} ] && echo \"yes\" || echo \"no\"") do |c, s, o|
if o =~ /yes?/
Expand All @@ -36,7 +36,7 @@
server_aliases = []
server_aliases << "www.#{ apache_server_name}"
server_aliases.concat apache_server_aliases
set : apache_server_aliases_array, server_aliases
set :apache_server_aliases_array, server_aliases

file = File.join(File.dirname(__FILE__), "templates", app_server.to_s, "httpd.conf")
template = File.read(file)
Expand Down Expand Up @@ -76,11 +76,11 @@

end

def set_ apache_conf
def set_apache_conf
if apache_default_vhost
set : apache_conf, "/etc/httpd/conf/default.conf" unless apache_default_vhost_conf
set :apache_conf, "/etc/httpd/conf/default.conf" unless apache_default_vhost_conf
else
set : apache_conf, "/etc/httpd/conf/apps/#{application}.conf" unless apache_conf
set :apache_conf, "/etc/httpd/conf/apps/#{application}.conf" unless apache_conf
end
end

Expand Down

0 comments on commit 4d73672

Please sign in to comment.