diff options
Diffstat (limited to 'bin/weblogs-rotate')
-rwxr-xr-x | bin/weblogs-rotate | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/bin/weblogs-rotate b/bin/weblogs-rotate new file mode 100755 index 0000000..98e969f --- /dev/null +++ b/bin/weblogs-rotate @@ -0,0 +1,46 @@ +#!/usr/bin/ruby + +require 'optparse' + +$VERBOSE = nil + +def show_help(parser, code=0, io=STDOUT) + io.puts parser + exit(code) +end +ARGV.options do |opts| + opts.on_tail("-h", "--help", "Display this help screen") { show_help(opts) } + opts.on("-v", "--verbose" , nil, "Be verbose") { $VERBOSE = 1 } + opts.parse! +end + + +root = '/srv/www/vhosts' +Dir.chdir(root) + +today = Time.new.strftime("%Y-%m-%d"); +Dir.glob("*").each{ |client| + Dir.chdir(root) + next unless File.stat( client ).directory? + next unless File.exist?( client + "/logs" ) + next unless File.stat( client + "/logs" ).directory? + + logroot = root+"/"+client+"/logs" + Dir.chdir(logroot) + Dir.glob("*.log").each{ |filename| + targetname = filename +"."+ today + + if File.exist?(targetname) or + File.exist?(targetname+".gz") or + File.exist?(targetname+".bz2") + STDERR.puts("Not moving #{filename}: Target exists."); + else + puts "Moving #{filename}" if $VERBOSE + File.rename( filename , targetname ); + end + } +} + +system ("/usr/sbin/apache2ctl graceful") or throw "system apache2ctl graceful failed" +## graceful means that apache might not close the old logfile immediately +## therefore we compress an hour later in a different script |