lib/railsmachine/recipes.rb in railsmachine-0.1.2 vs lib/railsmachine/recipes.rb in railsmachine-1.0.0

- old
+ new

@@ -1,135 +1,161 @@ require 'railsmachine/recipes/svn' require 'railsmachine/recipes/mysql' +require 'railsmachine/recipes/pgsql' require 'railsmachine/recipes/apache' require 'railsmachine/recipes/mongrel' -Capistrano.configuration(:must_exist).load do +Capistrano::Configuration.instance(:must_exist).load do + + default_run_options[:pty] = true + set :keep_releases, 3 set :app_symlinks, nil - desc <<-DESC - A macro task that calls setup, setup_db, setup_app, setup_symlinks, and setup_web. - Used to configure your deployment environment in one command. - DESC - task :setup_servers do - setup - begin - setup_db - rescue - puts "setup_db failed!" - end - setup_app - setup_symlinks - setup_web - end + namespace :servers do - desc <<-DESC - A macro task that calls setup_db, setup_app, setup_symlinks, and setup_web. - Used to configure your deployment environment in one command. - DESC - task :setup_app, :roles => :app do - set :mongrel_environment, rails_env - set :mongrel_port, apache_proxy_port - set :mongrel_servers, apache_proxy_servers - set :mongrel_user, user unless mongrel_user - set :mongrel_group, mongrel_user unless mongrel_group - set_mongrel_conf - configure_mongrel_cluster - end + desc <<-DESC + A macro task that calls setup for db, app, symlinks, and web. + Used to configure your deployment environment in one command. + DESC + task :setup do + deploy.setup + begin + db.setup + rescue + puts "db:setup failed!" + end + app.setup + web.setup + end - desc "Restart application server." - task :restart_app, :roles => :app do - set_mongrel_conf - restart_mongrel_cluster - end + desc "A macro task that restarts the application and web servers" + task :restart do + app.restart + web.restart + end - desc "Start application server." - task :start_app, :roles => :app do - set_mongrel_conf - start_mongrel_cluster end - desc "Stop application server." - task :stop_app, :roles => :app do - set_mongrel_conf - stop_mongrel_cluster - end + namespace :app do - def set_mongrel_conf - set :mongrel_conf, "/etc/mongrel_cluster/#{application}.conf" unless mongrel_conf - end - - desc "Setup web server." - task :setup_web, :roles => :web do - set :apache_server_name, domain unless apache_server_name - configure_apache - end + desc 'Setup mongrel' + task :setup, :roles => :app do + set :mongrel_environment, rails_env + set :mongrel_port, apache_proxy_port + set :mongrel_servers, apache_proxy_servers + set :mongrel_user, user unless mongrel_user + set :mongrel_group, mongrel_user unless mongrel_group + set_mongrel_conf + mongrel.cluster.configure + end + + desc "Restart application server." + task :restart, :roles => :app do + set_mongrel_conf + mongrel.cluster.restart + end + + desc "Start application server." + task :start, :roles => :app do + set_mongrel_conf + mongrel.cluster.start + end + + desc "Stop application server." + task :stop, :roles => :app do + set_mongrel_conf + mongrel.cluster.stop + end - desc "Restart web server." - task :restart_web, :roles => :web do - restart_apache - end + namespace :symlinks do - desc "Reload web server configuration." - task :reload_web, :roles => :web do - reload_apache - end + desc "Setup application symlinks in the public" + 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." + task :update, :roles => [:app, :web] do + if app_symlinks + app_symlinks.each { |link| run "ln -nfs #{shared_path}/public/#{link} #{current_path}/public/#{link}" } + end + end - desc "Start web server." - task :start_web, :roles => :web do - start_apache - end + end - desc "Stop web server." - task :stop_web, :roles => :web do - stop_apache end - desc "Setup database server." - task :setup_db, :roles => :db, :only => { :primary => true } do - setup_mysql - end + namespace :web do + + desc "Setup web server." + task :setup, :roles => :web do + set :apache_server_name, domain unless apache_server_name + apache.configure + end + + desc "Restart web server." + task :restart, :roles => :web do + apache.restart + end + + desc "Reload web server configuration." + task :reload, :roles => :web do + apache.reload + end + + desc "Start web server." + task :start, :roles => :web do + apache.start + end + + desc "Stop web server." + task :stop, :roles => :web do + apache.stop + end - desc "Setup source control server." - task :setup_scm, :roles => :scm do - begin - setup_svn - rescue - puts "setup_svn failed!" end - import_svn - end - desc "Setup public symlink directories" - task :setup_symlinks, :roles => [:app, :web] do - if app_symlinks - app_symlinks.each { |link| run "mkdir -p #{shared_path}/public/#{link}" } + namespace :db do + + desc "Setup database server." + task :setup, :roles => :db, :only => { :primary => true } do + db_config = YAML.load_file('config/database.yml') + db_type = db_config[rails_env]["adapter"] + case db_config[rails_env]["adapter"] + when "mysql" + mysql.setup + when "postgresql" + postgresql.setup + else + puts "Only MySQL or Postgres can be configured by db:setup." + end end + end - desc "Link up any public directories." - task :symlink_public, :roles => [:app, :web] do - if app_symlinks - app_symlinks.each { |link| run "ln -nfs #{shared_path}/public/#{link} #{current_path}/public/#{link}" } + namespace :repos do + + desc "Setup source control repository." + task :setup, :roles => :scm do + begin + svn.setup + rescue + puts "svn:setup failed!" end - end + svn.import + end - desc <<-DESC - Restart the processes on the application server by calling restart_app. - DESC - task :restart, :roles => :app do - restart_app end - desc <<-DESC - Start the processes on the application server by calling start_app. - DESC - task :spinner, :roles => :app do - start_app - end - desc "Creates additional symlinks." - task :after_symlink, :roles => [:app, :web] do - symlink_public - end + before 'deploy:update_code', 'app:symlinks:setup' + after 'deploy:symlink', 'app:symlinks:update' + after 'deploy:cold', 'web:reload' + after :deploy,'deploy:cleanup' + + def set_mongrel_conf + set :mongrel_conf, "/etc/mongrel_cluster/#{application}.conf" unless mongrel_conf + end end