tags:

views:

14

answers:

1

I am trying to create a capistrano task to setup my log rotation file.

namespace :app do
  task :setup_log_rotation,:roles => :app do
    rotate_script = %Q{#{shared_path}/log/#{stage}.log {
      daily
      rotate #{ENV['days'] || 7}
      size #{ENV['size'] || "5M"}
      compress
      create 640 #{user} #{ENV['group'] || user}
      missingok
    }}

    put rotate_script, "#{shared_path}/logrotate_script"

    "sudo cp #{shared_path}/logrotate_script /etc/logrotate.d/#{application}"

    run "rm #{shared_path}/logrotate_script"
  end
end

At the very top of my deploy.rb file I had following line

set :use_sudo, false

I completely missed that my cp command was silently failing and on my terminal I thought everything is fine. That is not good. How should I write the cp code so that incase cp fails for some reason ( in this case sudo command was failing) then I should get feedback on my terminal.

A: 

Solved my own problem.

Look at this for something similar.

I add this line in deploy.rb

default_run_options[:pty] = true

And changed from

run "sudo cp #{shared_path}/logrotate_script /etc/logrotate.d/#{application}"

to this

sudo "cp #{shared_path}/logrotate_script /etc/logrotate.d/#{application}"
Roger