Skip to content

Instantly share code, notes, and snippets.

@johnantoni
Created January 10, 2012 21:55
Show Gist options
  • Save johnantoni/1591435 to your computer and use it in GitHub Desktop.
Save johnantoni/1591435 to your computer and use it in GitHub Desktop.
Install log rotate script for Capistrano
desc "Install log rotate script"
task :rotate_logs, :roles => :app do
set :use_sudo, true
default_run_options[:pty] = true
rotate_script = %Q{#{shared_path}/log/*.log {
daily
missingok
rotate 30
compress
size 5M
delaycompress
sharedscripts
postrotate
touch #{current_path}/tmp/restart.txt
endscript
}}
put rotate_script, "#{shared_path}/logrotate_script"
sudo "cp #{shared_path}/logrotate_script /etc/logrotate.d/#{application}_#{rails_env}"
run "rm #{shared_path}/logrotate_script"
# run manually with: logrotate -f /etc/logrotate.d/homesav_staging
end
@johnantoni
Copy link
Author

keep 30 days worth of logs
rotate when file size above 5mb
compress logs
missing files are ok, don't throw an error
run daily
restart passenger app only once, not per-logfile

@johnbellone
Copy link

I am assuming you're restarting Passenger because the logfiles are not being freed up. You can use the copytruncate parameter in the rotate script and you shouldn't have to worry about bouncing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment