Skip to content

Instantly share code, notes, and snippets.

Created January 5, 2013 15:45
Show Gist options
  • Save anonymous/4462150 to your computer and use it in GitHub Desktop.
Save anonymous/4462150 to your computer and use it in GitHub Desktop.
Generate logrotate conf for rails sites deployed with capistrano
# Generate logrotate conf for rails sites deployed with capistrano
# it scans current directory for rails site, it assumes that webserver is passenger
# cd /u/apps && ~/bin/gen_logrotate.rb
require 'etc'
Dir['*'].each do |entry|
next unless File.directory? entry
dir = File.expand_path entry
log_dir = dir + "/shared/log"
next unless File.directory? log_dir
puts dir
fstats = File.stat dir
user = Etc.getpwuid(fstats.uid).name
group = Etc.getgrgid(fstats.gid).name
File.open "#{entry.tr('.', '_')}_conf", "w" do |out|
out.write <<EOF
#{log_dir}/*.log {
daily
missingok
rotate 5
notifempty
create 640 #{user} #{group}
sharedscripts
postrotate
/bin/date >#{dir}/current/tmp/restart.txt
endscript
}
EOF
end
end
@vitaliel
Copy link

vitaliel commented Jan 5, 2013

My gist ;-)

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