<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -10,16 +10,11 @@ which will help you deploy to your RailsBoxcar.com instance.
 You'll want to make sure that you have the following gems installed
 before you begin:
 
-palmtree capistrano
+capistrano fastthread
 
-With newer versions of capistrano you should install the following:
+If you will be using mongrels (instead of Passenger) also install:
 
-fastthread
-
-If you plan on using mongrel + nginx instead of Phusion Passenger, you
-should also install the following gems:
-
-mongrel mongrel_cluster
+palmtree
 
 
 ## Automatic Installation ##
@@ -53,16 +48,11 @@ http://github.com/planetargon/boxcar-conductor/tarball/master
 ../../../script/runner install.rb
 
 
-## Configure your Boxcar ##
+## Configure and deploy ##
 
 cap boxcar:config -q
 
 
-## Deploy! ##
-
-cap deploy:cold
-
-
 ## Done! ##
 Feature Requests / Bugs
 </diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -25,6 +25,15 @@ end
 # Only the courageous of ninjas dare pass this!
 ########################################################################
 
+DBNAME    = {:postgresql =&gt; &quot;PostgreSQL&quot;, :mysql =&gt; &quot;MySQL&quot;}
+GEMNAME   = {:postgresql =&gt; &quot;pg&quot;, :mysql =&gt; &quot;mysql&quot;}
+BINDBNAME = {:postgresql =&gt; &quot;psql&quot;, :mysql =&gt; &quot;mysql&quot;}
+INSTALLDB = {:postgresql =&gt; &quot;postgresql libpq-dev&quot;, :mysql =&gt; &quot;mysql-server mysql-client libmysqlclient15-dev&quot;}
+HTTPDNAME = {:nginx =&gt; &quot;Nginx&quot;, :apache =&gt; &quot;Apache&quot;}
+HTTPDSERV = {:nginx =&gt; &quot;nginx&quot;, :apache =&gt; &quot;apache2&quot;}
+
+REEDIR = &quot;/usr/local/lib/ruby-enterprise-current&quot;
+
 role :web, boxcar_server
 role :app, boxcar_server
 role :db, boxcar_server, :primary =&gt; true
@@ -47,7 +56,7 @@ set :db_test, database_name[:test]
 set :db_production, database_name[:production]
 
 # Prompt user to set database user/pass
-set :database_username, Proc.new { HighLine.ask(indentstring(&quot;What is your database username? |dbuser|&quot;)) { |q| q.default = &quot;dbuser&quot; } }
+set :database_username, Proc.new { HighLine.ask(indentstring(&quot;What is your database username? |#{user}|&quot;)) { |q| q.default = user } }
 set :database_host, Proc.new {
   if setup_type.to_s == &quot;quick&quot;
     &quot;localhost&quot;
@@ -105,13 +114,13 @@ set :database_port, Proc.new {
 # server type
 set :server_type, Proc.new {
   if setup_type.to_s == &quot;quick&quot;
-    :passenger
+    :nginx
   else
     # indenting this prompt by hand for now. Can't figure out how to work in indentstring
     choose do |menu|
       menu.layout = :one_line
-      menu.prompt = &quot;    What web server will you be using?  &quot;
-      menu.choices(:passenger, :mongrel)
+      menu.prompt = &quot;         What web server will you be using?  &quot;
+      menu.choices(:nginx, :apache)
     end
   end
 }
@@ -124,24 +133,6 @@ set :deploy_to, &quot;#{home}/sites/#{application_name}&quot;
 
 set :app_shared_dir, &quot;#{deploy_to}/shared&quot;
 
-
-# mongrel
-# What port number should your mongrel cluster start on?
-set :mongrel_port, Proc.new {
-  HighLine.ask(indentstring(&quot;What port will your mongrel cluster start with? |8000|&quot;), Integer) do |q|
-    q.default = 8000
-    q.in = 1024..65536
-  end
-}
-
-# How many instances of mongrel should be in your cluster?
-set :mongrel_servers, Proc.new {
-  HighLine.ask(indentstring(&quot;How many mongrel servers should run? |3|&quot;), Integer) do |q|
-    q.default=3
-    q.in = 1..10
-  end
-}
-
 # what type of setup does the user want?
 set :setup_type, Proc.new {
   # another manual indent
@@ -152,109 +143,190 @@ set :setup_type, Proc.new {
   end
 }
 
-set :mongrel_conf, &quot;#{etc}/mongrel_cluster.#{application_name}.conf&quot;
-set :mongrel_pid, &quot;#{log}/mongrel_cluster.#{application_name}.pid&quot;
-set :mongrel_address, '127.0.0.1'
-set :mongrel_environment, :production
-
 set :boxcar_conductor_templates, 'vendor/plugins/boxcar-conductor/templates'
 
 set :today, Time.now.strftime('%b %d, %Y').to_s
 
 namespace :boxcar do
   desc 'Configure your Boxcar environment'
-  task :config, :except =&gt; { :no_release =&gt; true } do
-    run &quot;mkdir -p #{home}/etc #{home}/log #{home}/sites&quot;
-    run &quot;mkdir -p #{app_shared_dir}/config #{app_shared_dir}/log&quot;
+  task :config,  :roles =&gt; :admin_web do
     puts &quot;&quot;
     setup_type
-    database.configure
-    setup
-    createdb
-    mongrel.cluster.generate unless server_type == :passenger
-    puts &quot;&quot;
-    say &quot;Setup complete. Now run cap deploy:cold and you should be all set.&quot;
+    setup.configdb
+    puts &quot;\n\nBeginning remote setup. This process will install and configure the&quot;
+    puts &quot;database server and Phusion Passenger modules for your Boxcar. Some&quot;
+    puts &quot;of these steps can take a couple of minutes, so relax, get a cup of&quot;
+    puts &quot;coffee and then come back.\n\n&quot;
+    setup.installdbms
+    setup.installgems
+    setup.passenger
     puts &quot;&quot;
+    if HighLine.agree(indentstring(&quot;Setup is complete. Ready to deploy? [y/n]&quot;))
+      puts &quot;--------------------cap deploy:cold--------------------&quot;
+      if system(&quot;cap deploy:cold&quot;)
+        puts &quot;--------------------cap deploy:cold--------------------&quot;
+        setup.startweb
+      else
+        puts &quot;Errors encountered during the deploy:cold. Please fix them and then try&quot;
+        puts &quot;running this task again.&quot;
+      end
+    end
+  end
+  before &quot;boxcar:config&quot;, &quot;boxcar:setup:createuser&quot;, &quot;deploy:setup&quot;
+
+  task :testing, :except =&gt; { :no_release =&gt; true } do
+    HighLine.agree(indentstring(&quot;Setup is complete. Ready to deploy? [y/n]&quot;))
   end
-  before &quot;boxcar:config&quot;, &quot;deploy:setup&quot;
-
-  desc 'Install and configure databases'
-  task :setup, :roles =&gt; :admin_web do
-    # Setting up some variables. Note that testdb *must* include the negation
-    if database_adapter.to_s == &quot;postgresql&quot;
-      installdb  = 'postgresql libpq-dev'
-      dbname = &quot;PostgreSQL&quot;
-      gemname = &quot;pg&quot;
-      bindbname = &quot;psql&quot;
-    elsif database_adapter.to_s == &quot;mysql&quot;
-      installdb  = 'mysql-server mysql-client libmysqlclient15-dev'
-      dbname = &quot;MySQL&quot;
-      gemname = &quot;mysql&quot;
-      bindbname = &quot;mysql&quot;
+
+  namespace :setup do
+    desc 'Create deployment user'
+    task :createuser, :roles =&gt; :admin_web do
+      print indentstring(&quot;Creating user #{user}:&quot;)
+      if capture(&quot;if [ -d /home/#{user} ]; then echo true; else echo false; fi&quot;).chomp.eql?(&quot;false&quot;)
+        run &quot;adduser --gecos '' --disabled-password #{user}&quot;
+        puts &quot;#{user} created&quot;
+        if capture(&quot;if [ -f /home/#{user}/.ssh/authorized_keys ]; then echo true; else echo false; fi&quot;).chomp.eql?(&quot;false&quot;)
+          user_password = &quot;&quot; # Keeping asking for the password until they get it right twice in a row.
+          loop do
+            user_password = HighLine.ask(indentstring(&quot;Please enter a password for #{user}:&quot;)) { |q| q.echo = &quot;.&quot; }
+            password_confirm = HighLine.ask(indentstring(&quot;Please retype the password to confirm:&quot;)) { |q| q.echo = &quot;.&quot; }
+            break if user_password == password_confirm
+          end
+          run &quot;echo '#{user}:#{user_password} | chpasswd -m&quot;
+        else
+          puts indentstring(&quot;using root's public key&quot;, :end)
+        end
+      else
+        puts &quot;#{user} already exists&quot;
+      end
     end
-    installgem = &quot;gem install #{gemname} --no-ri --no-rdoc -q&quot;
-    installdb  = &quot;aptitude -y -q install #{installdb} &gt; /dev/null&quot;
 
-    puts &quot;\n\nNow installing and configuring #{dbname}. If this is your first time&quot;
-    puts &quot;deploying to this Boxcar with this database type the install could take&quot;
-    puts &quot;a couple of minutes, so go get a cup of coffee, relax, and then come back.\n\n&quot;
+    desc 'Install and configure databases'
+    task :installdbms, :roles =&gt; :admin_web do
+      installdb  = &quot;aptitude -y -q install #{INSTALLDB[database_adapter]} &gt; /dev/null&quot;
 
-    print indentstring(&quot;Installing and configuring #{dbname}:&quot;)
+      print indentstring(&quot;Installing and configuring #{DBNAME[database_adapter]}:&quot;)
 
-    begin
-      run &quot;! which #{bindbname} &gt;/dev/null&quot;
+      begin
+        run &quot;! which #{BINDBNAME[database_adapter]} &gt;/dev/null&quot;
 
-      run installdb, :pty =&gt; true
-      puts &quot;#{dbname} installed&quot;
+        run installdb, :pty =&gt; true
+        puts &quot;#{DBNAME[database_adapter]} installed&quot;
+      rescue Capistrano::CommandError =&gt; e
+        puts &quot;#{DBNAME[database_adapter]} already installed, skipping.&quot;
+      end
+    end
+    after &quot;boxcar:setup:installdbms&quot;, &quot;boxcar:setup:createdb&quot;
+
+    desc 'Create application database and user'
+    task :createdb, :roles =&gt; :admin_web do
+      if database_adapter.to_s == &quot;postgresql&quot;
+        psqlconfig = &quot;CREATE ROLE #{database_username} PASSWORD '#{database_password}' NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN; CREATE DATABASE #{db_production} OWNER #{database_username};&quot;
+        put psqlconfig, &quot;/tmp/setupdb.sql&quot;
+        run &quot;psql &lt; /tmp/setupdb.sql&quot;, :shell =&gt; 'su postgres'
+      elsif database_adapter.to_s == &quot;mysql&quot;
+        mysqlconfig = &quot;CREATE DATABASE #{db_production}; GRANT ALL PRIVILEGES ON #{db_production}.* TO #{database_username} IDENTIFIED BY '#{database_password}'&quot;
+        put mysqlconfig, &quot;/tmp/setupdb.sql&quot;
+        run &quot;mysql &lt; /tmp/setupdb.sql&quot;
+      end
+      run &quot;rm -f /tmp/setupdb.sql&quot;
+      puts indentstring(&quot;database configured&quot;, :end)
+    end
 
-      run installgem, { :shell =&gt; '/bin/bash --login', :pty =&gt; true }
-      puts indentstring(&quot;#{gemname} gem installed&quot;, :end)
-    rescue Capistrano::CommandError =&gt; e
-      puts &quot;#{dbname} already installed, skipping.&quot;
+    desc 'Set up Phusion Passenger for the selected web server'
+    task :passenger, :roles =&gt; :admin_web do
+      print indentstring(&quot;Installing #{HTTPDNAME[server_type]} Passenger modules:&quot;)
+      begin
+        run &quot;test -h #{REEDIR}/lib/ruby/gems/1.8/gems/passenger-current&quot;
+      rescue Capistrano::CommandError =&gt; e
+        puts &quot;failed&quot;
+        puts '\n\nPassenger &amp; Ruby Enterprise Edition do not appear to be installed correctly. Please'
+        puts 'contact support for further assistance. Aborting.\n\n'
+        abort
+      end
+      begin
+        if server_type == :nginx
+          other_server = :apache
+          run &quot;if [ ! -f #{REEDIR}/lib/ruby/gems/1.8/gems/passenger-current/ext/nginx/HelperServer ]; then #{REEDIR}/bin/passenger-install-nginx-module --auto --prefix=/usr/local/lib/nginx --auto-download &gt; /dev/null 2&gt;&amp;1 &amp;&amp; rm -rf /usr/local/lib/nginx; fi&quot;
+        elsif server_type == :apache
+          other_server = :nginx
+          run &quot;if [ ! -f #{REEDIR}/lib/ruby/gems/1.8/gems/passenger-current/ext/apache2/mod_passenger.so ]; then #{REEDIR}/bin/passenger-install-apache2-module --auto &gt;/dev/null 2&gt;&amp;1; fi&quot;
+        end
+        puts &quot;#{HTTPDNAME[server_type]} module installed&quot;
+        run &quot;sysv-rc-conf #{HTTPDSERV[:nginx]} on &amp;&amp; sysv-rc-conf #{HTTPDSERV[:apache]} off&quot;
+        puts indentstring(&quot;#{HTTPDNAME[server_type]} startup enabled&quot;, :end)
+      rescue Capistrano::CommandError =&gt; e
+        puts &quot;\n\nAn unhandled error occured while attempting to install Passenger. Aborting.\n\n&quot;
+        abort
+      end
     end
-  end
 
-  desc 'Create application database and user'
-  task :createdb, :roles =&gt; :admin_web do
-    if database_adapter.to_s == &quot;postgresql&quot;
-      psqlconfig = &quot;CREATE ROLE #{database_username} PASSWORD '#{database_password}' NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN; CREATE DATABASE #{db_production} OWNER #{database_username};&quot;
-      put psqlconfig, &quot;/tmp/setupdb.sql&quot;
-      run &quot;psql &lt; /tmp/setupdb.sql&quot;, :shell =&gt; 'su postgres'
-    elsif database_adapter.to_s == &quot;mysql&quot;
-      mysqlconfig = &quot;CREATE DATABASE #{db_production}; GRANT ALL PRIVILEGES ON #{db_production}.* TO #{database_username} IDENTIFIED BY '#{database_password}'&quot;
-      put mysqlconfig, &quot;/tmp/setupdb.sql&quot;
-      run &quot;mysql &lt; /tmp/setupdb.sql&quot;
+    desc &quot;Install necessary gems on Boxcar&quot;
+    task :installgems, :roles =&gt; :admin_web do
+      eval(File.open(&quot;config/environment.rb&quot;).grep(/RAILS_GEM_VERSION/).first) if File.exists?(&quot;config/environment.rb&quot;)
+      installcmd=&quot;#{REEDIR}/bin/gem install --no-rdoc --no-ri -q &quot;
+      checkcmd=&quot;#{REEDIR}/bin/gem list -i &quot;
+      print indentstring(&quot;Installing gems:&quot;)
+      begin
+        run(checkcmd + &quot;-v=#{RAILS_GEM_VERSION} rails&quot;)
+        puts &quot;rails #{RAILS_GEM_VERSION} already installed&quot;
+      rescue
+        run(installcmd + &quot;-v=#{RAILS_GEM_VERSION} rails&quot;)
+        puts &quot;rails #{RAILS_GEM_VERSION} installed&quot;
+      end
+      begin
+        capture(checkcmd + &quot;#{GEMNAME[database_adapter]}&quot;)
+        puts indentstring(&quot;#{GEMNAME[database_adapter]} already installed&quot;, :end)
+      rescue
+        run(&quot;#{REEDIR}/bin/gem install --no-rdoc --no-ri -q #{GEMNAME[database_adapter]}&quot;)
+        puts indentstring(&quot;#{GEMNAME[database_adapter]} installed&quot;, :end)
+      end
     end
-    run &quot;rm -f /tmp/setupdb.sql&quot;
-    puts indentstring(&quot;database configured&quot;, :end)
-  end
 
-  namespace :deploy do
-    desc &quot;Link in the production database.yml&quot;
-    task :link_files, :except =&gt; { :no_release =&gt; true } do
-      run &quot;ln -nfs #{app_shared_dir}/config/database.yml #{release_path}/config/database.yml&quot;
-      run &quot;ln -nfs #{app_shared_dir}/log #{release_path}/log&quot;
+    desc &quot;Create remote directory structure&quot;
+    task :createdirs, :expect =&gt; { :no_release =&gt; true } do
+      run &quot;mkdir -p #{home}/log #{home}/sites&quot;
+      run &quot;mkdir -p #{app_shared_dir}/config #{app_shared_dir}/log&quot;
     end
-  end
 
-  namespace :database do
     desc &quot;Configure your Boxcar database&quot;
-    task :configure, :except =&gt; { :no_release =&gt; true } do
+    task :configdb, :except =&gt; { :no_release =&gt; true } do
       database_configuration = render_erb_template(&quot;#{boxcar_conductor_templates}/databases/#{database_adapter}.yml.erb&quot;)
       put database_configuration, &quot;#{app_shared_dir}/config/database.yml&quot;
     end
-  end
+    before &quot;boxcar:setup:configdb&quot;, &quot;boxcar:setup:createdirs&quot;
+
+    task :startweb, :roles =&gt; :admin_web do
+      print indentstring(&quot;Activating #{HTTPDNAME[server_type]}:&quot;)
+      begin
+        run &quot;/usr/local/bin/activate-server -a #{user} #{application_name} &gt; /dev/null 2&gt;&amp;1&quot;
+        puts &quot;success!&quot;
+        print indentstring(&quot;Your application should now be available at:&quot;)
+        puts &quot;http://#{boxcar_server}\n&quot;
+      rescue
+        puts &quot;failed!&quot;
+        puts &quot;\nPlease log into your Boxcar as root and run 'activate-server' to&quot;
+        puts &quot;get more detailed failure information.\n&quot;
+      end
+    end
 
-  namespace :mongrel do
-    namespace :cluster do
-      desc &quot;Generate mongrel cluster configuration&quot;
-      task :generate, :except =&gt; { :no_release =&gt; true } do
-        mongrel_cluster_configuration = render_erb_template(&quot;#{boxcar_conductor_templates}/mongrel_cluster.yml.erb&quot;)
-        put mongrel_cluster_configuration, mongrel_conf
+    task :testweb, :roles =&gt; :admin_web do
+      begin
+        stream &quot;/etc/init.d/nginx restart&quot;
+      rescue
+        puts &quot;failed&quot;
       end
     end
   end
 
+  namespace :deploy do
+    desc &quot;Link in the production database.yml&quot;
+    task :link_files, :except =&gt; { :no_release =&gt; true } do
+      run &quot;ln -nfs #{app_shared_dir}/config/database.yml #{release_path}/config/database.yml&quot;
+      run &quot;ln -nfs #{app_shared_dir}/log #{release_path}/log&quot;
+    end
+  end
+
   after &quot;deploy:update_code&quot;, &quot;boxcar:deploy:link_files&quot;
 
 end</diff>
      <filename>tasks/boxcar_tasks.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>99ad310f803fc99955ca2fc46bf12d9b3b5370d2</id>
    </parent>
  </parents>
  <author>
    <name>Alex Malinovich</name>
    <email>alex.malinovich@planetargon.com</email>
  </author>
  <url>http://github.com/planetargon/boxcar-conductor/commit/ee5eada5c1e0d0daf06ac2625ca9226eee2098bb</url>
  <id>ee5eada5c1e0d0daf06ac2625ca9226eee2098bb</id>
  <committed-date>2009-06-13T13:47:18-07:00</committed-date>
  <authored-date>2009-06-13T13:47:18-07:00</authored-date>
  <message>Updates for fully-automated setup</message>
  <tree>4c6bd8ba887349bb42d3323c3eca716f6f805e4b</tree>
  <committer>
    <name>Alex Malinovich</name>
    <email>alex.malinovich@planetargon.com</email>
  </committer>
</commit>
