Skip to content

Instantly share code, notes, and snippets.

@vitaliel
Forked from anonymous/gen_logrotate_conf.rb
Created January 5, 2013 15:47
Show Gist options
  • Save vitaliel/4462156 to your computer and use it in GitHub Desktop.
Save vitaliel/4462156 to your computer and use it in GitHub Desktop.
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment