lib/ash/magento.rb in capistrano-ash-1.3.6 vs lib/ash/magento.rb in capistrano-ash-1.3.7

- old
+ new

@@ -16,10 +16,25 @@ # # -------------------------------------------- depend :remote, :command, 'rsync' # -------------------------------------------- + # try_sudo configuration + # -------------------------------------------- + set :use_sudo, true # allow try_sudo methods to actually run via sudo + # set(:admin_runner) {"#{user}"} # specify the :admin_runner if you need to run it as another user other than root + + # Clear out the default prompt (i.e., `sudo -p 'sudo password: '`) to fall back + # to just using `sudo` due to the concatenation in the sudo method. + # + # This assumes that you have set up your SSH user to have passwordless sudo + # setup for common commands (e.g., mv, cp, ln, mkdir, chown, chmod, rm, etc.) + # + # (see: https://github.com/capistrano/capistrano/blob/legacy-v2/lib/capistrano/configuration/actions/invocation.rb#L229-L237) + set :sudo_prompt, '' + + # -------------------------------------------- # Magento Variables # -------------------------------------------- set :enable_modules, [] set :disable_modules, %w(Ash_Bar) @@ -55,41 +70,41 @@ end desc "Setup shared application directories and permissions after initial setup" task :setup_shared do # remove Capistrano specific directories - run "rm -Rf #{shared_path}/log" - run "rm -Rf #{shared_path}/pids" - run "rm -Rf #{shared_path}/system" + try_sudo "rm -Rf #{shared_path}/log" + try_sudo "rm -Rf #{shared_path}/pids" + try_sudo "rm -Rf #{shared_path}/system" # create shared directories run "mkdir -p #{shared_path}/includes" run "mkdir -p #{shared_path}/media" run "mkdir -p #{shared_path}/sitemap" run "mkdir -p #{shared_path}/var" # set correct permissions - run "chmod 777 #{shared_path}/*" + set_perms("#{shared_path}/*", 777) end desc "[internal] Touches up the released code. This is called by update_code after the basic deploy finishes." task :finalize_update, :roles => :web, :except => { :no_release => true } do # synchronize media directory with shared data run "rsync -rltDvzog #{latest_release}/media/ #{shared_path}/media/" - run "#{sudo} chmod -R 777 #{shared_path}/media/" + set_perms("#{shared_path}/media/", 777) # remove directories that will be shared run "rm -Rf #{latest_release}/includes" run "rm -Rf #{latest_release}/media" run "rm -Rf #{latest_release}/sitemap" run "rm -Rf #{latest_release}/var" # set the file and directory permissions ash.fixperms - run "chmod 400 #{latest_release}/pear" if remote_file_exists?("#{latest_release}/pear") - run "chmod 400 #{latest_release}/mage" if remote_file_exists?("#{latest_release}/mage") - run "chmod o+w #{latest_release}/app/etc" + set_perms("#{latest_release}/pear", 400) + set_perms("#{latest_release}/mage", 400) + set_perms("#{latest_release}/app/etc", "o+w") end namespace :web do desc "Disable the application and show a message screen" task :disable, :roles => :web, :except => { :no_release => true } do @@ -125,11 +140,12 @@ run "ln -nfs #{shared_path}/var #{latest_release}/var" end desc "Purge Magento cache directory" task :purge_cache, :roles => :web, :except => { :no_release => true } do - run "#{sudo} rm -Rf #{shared_path}/var/cache/*" + try_sudo "rm -Rf #{shared_path}/var/cache/*" + try_sudo "rm -Rf #{shared_path}/var/full_page_cache/*" if remote_dir_exists?("#{shared_path}/var/full_page_cache}") end desc "Watch Magento system log" task :watch_logs, :roles => :web, :except => { :no_release => true } do run "tail -f #{shared_path}/var/log/system.log" do |channel, stream, data| @@ -148,12 +164,11 @@ end end desc "Clear the Magento Cache" task :cc, :roles => [:web, :app], :except => { :no_release => true } do - run "#{sudo} chown -R #{user}:#{user} #{shared_path}/var/*" + try_sudo "chown -R #{user}:#{user} #{shared_path}/var/*" magento.purge_cache - run "#{sudo} rm -rf #{shared_path}/var/full_page_cache/*" end desc "Enable display errors" task :enable_dev, :roles => :web, :except => { :no_release => true } do run "perl -pi -e 's/#ini_set/ini_set/g' #{latest_release}/index.php"