Wrap text
|
|
desc 'Configures apache with a new phusion passenger virtual host; USAGE: sake passenger:new server_name=myapp rails_dir=/projects/my_rails_app'
task 'passenger:new' do
unless (ENV.include?("server_name") and (ENV.include?("rails_dir") and File.exists?(File.join(ENV["rails_dir"], "public")))) then
raise("\nUSAGE: sake passenger:new server_name=myapp rails_dir=/projects/my_rails_app/\n\n")
end
server_name = ENV["server_name"]
rails_public_dir = File.join(File.expand_path(ENV["rails_dir"]), "public")
httpd_conf = "/etc/apache2/other/httpd-mod-rails.conf"
commands = []
puts("Updating your /etc/hosts with an alias for #{server_name} to 127.0.0.1")
(commands << "echo '127.0.0.1 #{server_name}' >> /etc/hosts")
puts("Adding new virtual host to apache")
virtual_host_template = []
(virtual_host_template << "")
(virtual_host_template << "")
(virtual_host_template << " ServerName #{server_name}")
(virtual_host_template << " DocumentRoot #{rails_public_dir}")
(virtual_host_template << " RailsEnv development")
(virtual_host_template << "")
(commands << "echo '#{virtual_host_template.join("\\n")}' >> #{httpd_conf}")
puts("Restarting apache")
(commands << "apachectl graceful")
system("sudo -p 'sudo password for %u: ' sh -c \"#{commands.join(" && ")}\"")
end
|