logtwuncator 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Rakefile +1 -1
- data/lib/log_twuncator.rb +1 -1
- data/lib/log_twuncator/daemon.rb +2 -1
- data/lib/log_twuncator/options.rb +2 -2
- data/lib/log_twuncator/service.rb +21 -16
- data/test/test_win32_file.rb +13 -13
- metadata +65 -58
data/History.txt
CHANGED
data/Rakefile
CHANGED
@@ -13,7 +13,7 @@ Hoe.new('logtwuncator', LogTwuncator::VERSION) do |p|
|
|
13
13
|
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
14
14
|
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
15
15
|
p.remote_rdoc_dir = ''
|
16
|
-
p.extra_deps << ['win32-service', '
|
16
|
+
p.extra_deps << ['win32-service', '= 0.5.2']
|
17
17
|
end
|
18
18
|
|
19
19
|
# vim: syntax=Ruby
|
data/lib/log_twuncator.rb
CHANGED
data/lib/log_twuncator/daemon.rb
CHANGED
@@ -3,7 +3,7 @@ require 'optparse'
|
|
3
3
|
module LogTwuncator
|
4
4
|
class Options
|
5
5
|
|
6
|
-
def self.parse(args = ARGV)
|
6
|
+
def self.parse(args = ARGV, validate = true)
|
7
7
|
options = {}
|
8
8
|
options[:delay] = 5
|
9
9
|
opts = OptionParser.new do |opts|
|
@@ -29,7 +29,7 @@ module LogTwuncator
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
opts.parse!(args)
|
32
|
-
validate_options
|
32
|
+
validate_options(options) if validate
|
33
33
|
options
|
34
34
|
end
|
35
35
|
|
@@ -1,5 +1,6 @@
|
|
1
|
-
|
1
|
+
gem 'win32-service', '=0.5.2'
|
2
2
|
require 'win32/service'
|
3
|
+
require 'optparse'
|
3
4
|
|
4
5
|
module LogTwuncator
|
5
6
|
class ServiceCommand
|
@@ -31,17 +32,19 @@ module LogTwuncator
|
|
31
32
|
opts.on("-N", "--name SERVICE_NAME", String, "Name of windows service") do |v|
|
32
33
|
@options[:name] = v
|
33
34
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
35
|
+
|
36
|
+
if @command == 'install'
|
37
|
+
opts.on("-c", "--config FILE", String, "Config file with log file truncation settings") do |v|
|
38
|
+
@options[:config] = v
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.on("-d", "--delay N", Integer, "Check files for truncation every N minutes") do |v|
|
42
|
+
@options[:delay] = v
|
43
|
+
end
|
44
|
+
|
45
|
+
opts.on("-l", "--log FILE", String, "Log file for truncator") do |v|
|
46
|
+
@options[:log] = v
|
47
|
+
end
|
45
48
|
end
|
46
49
|
|
47
50
|
opts.on_tail("-h", "--help", "Show this message") do
|
@@ -49,7 +52,7 @@ module LogTwuncator
|
|
49
52
|
exit
|
50
53
|
end
|
51
54
|
end
|
52
|
-
opts.parse!(args)
|
55
|
+
opts.parse!(args)
|
53
56
|
validate_options
|
54
57
|
rescue OptionParser::ParseError => e
|
55
58
|
puts e
|
@@ -60,9 +63,11 @@ module LogTwuncator
|
|
60
63
|
def validate_options
|
61
64
|
errors = []
|
62
65
|
errors << "Service name is required (switch -N)" unless @options[:name]
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
+
if @command == 'install'
|
67
|
+
errors << "Delay is required (switch -d)" unless @options[:delay]
|
68
|
+
errors << "Config file is required (switch -c)" unless @options[:config]
|
69
|
+
errors << "Config file does not exist" if @options[:config] && !FileTest.exists?(@options[:config])
|
70
|
+
end
|
66
71
|
|
67
72
|
if errors.size > 0
|
68
73
|
puts "Error found."
|
data/test/test_win32_file.rb
CHANGED
@@ -6,7 +6,7 @@ class TestWin32File < Test::Unit::TestCase
|
|
6
6
|
def setup
|
7
7
|
setup_paths_and_files
|
8
8
|
@test_file = File.join(@log_path, 'test.txt')
|
9
|
-
@
|
9
|
+
@hour_ago = yesterday = Time.now - 3600
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_set_file_time_with_no_changes
|
@@ -20,24 +20,24 @@ class TestWin32File < Test::Unit::TestCase
|
|
20
20
|
def test_set_file_times_on_closed_file
|
21
21
|
file = File.open(@test_file, File::CREAT)
|
22
22
|
file.close
|
23
|
-
LogTwuncator::Win32File.set_file_time(file.path, @
|
24
|
-
assert_equal @
|
25
|
-
LogTwuncator::Win32File.set_file_time(file.path, nil, @
|
26
|
-
assert_equal @
|
27
|
-
LogTwuncator::Win32File.set_file_time(file.path, nil, nil, @
|
28
|
-
assert_equal @
|
23
|
+
LogTwuncator::Win32File.set_file_time(file.path, @hour_ago, nil, nil)
|
24
|
+
assert_equal @hour_ago.to_s, File.stat(file.path).ctime.to_s
|
25
|
+
LogTwuncator::Win32File.set_file_time(file.path, nil, @hour_ago, nil)
|
26
|
+
assert_equal @hour_ago.to_s, File.stat(file.path).atime.to_s
|
27
|
+
LogTwuncator::Win32File.set_file_time(file.path, nil, nil, @hour_ago)
|
28
|
+
assert_equal @hour_ago.to_s, File.stat(file.path).mtime.to_s
|
29
29
|
end
|
30
30
|
|
31
31
|
def test_set_file_times_on_open_file
|
32
32
|
File.open(@test_file, File::CREAT) do |file|
|
33
|
-
LogTwuncator::Win32File.set_file_time(file.path, @
|
34
|
-
assert_equal @
|
33
|
+
LogTwuncator::Win32File.set_file_time(file.path, @hour_ago, nil, nil)
|
34
|
+
assert_equal @hour_ago.to_s, File.stat(file.path).ctime.to_s
|
35
35
|
|
36
36
|
# FIXME: these fail and I think its because of the file interaction which changes the dates
|
37
|
-
# LogTwuncator::Win32File.set_file_time(file.path, nil, @
|
38
|
-
# assert_equal @
|
39
|
-
# LogTwuncator::Win32File.set_file_time(file.path, nil, nil, @
|
40
|
-
# assert_equal @
|
37
|
+
# LogTwuncator::Win32File.set_file_time(file.path, nil, @hour_ago, nil)
|
38
|
+
# assert_equal @hour_ago.to_s, File.stat(file.path).atime.to_s
|
39
|
+
# LogTwuncator::Win32File.set_file_time(file.path, nil, nil, @hour_ago)
|
40
|
+
# assert_equal @hour_ago.to_s, File.stat(file.path).mtime.to_s
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
metadata
CHANGED
@@ -1,33 +1,46 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: logtwuncator
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2007-10-24 00:00:00 +10:00
|
8
|
-
summary: A win32 log file truncator and archiver with windows service
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: adam.meehan@gmail.com
|
12
|
-
homepage: " by Adam Meehan (adam.meehan@gmail.com)"
|
13
|
-
rubyforge_project: logtwuncator
|
14
|
-
description: "It comes with a windows service to install and leave running to monitor the directories you specify in the config file. The config file allows the specification of many directories to monitor for log file age and size. File age is monitored by using the file creation date. In *nix programs like logrotate the log file can be moved and recreated using POSIX signalling to restart the process, and hence starting with a new file and creation date. On windows this is not possible without getting really intimate with the running process, so to get around it this program uses win32 API call to change the created date after arching and truncating the file, leaving it in plave. This seems to work fine with Rails and Apache but may cause problems depending on how the running application has opened the log file to append to it. Please report any problems/suggestions you have. Credits:"
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.1.2
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Adam Meehan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-01-17 00:00:00 +11:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: win32-service
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - "="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.5.2
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: hoe
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 1.4.0
|
32
|
+
version:
|
33
|
+
description: "It comes with a windows service to install and leave running to monitor the directories you specify in the config file. The config file allows the specification of many directories to monitor for log file age and size. File age is monitored by using the file creation date. In *nix programs like logrotate the log file can be moved and recreated using POSIX signalling to restart the process, and hence starting with a new file and creation date. On windows this is not possible without getting really intimate with the running process, so to get around it this program uses win32 API call to change the created date after arching and truncating the file, leaving it in plave. This seems to work fine with Rails and Apache but may cause problems depending on how the running application has opened the log file to append to it. Please report any problems/suggestions you have. Credits:"
|
34
|
+
email: adam.meehan@gmail.com
|
35
|
+
executables:
|
36
|
+
- log_twuncator_service
|
37
|
+
- log_twuncator_daemon
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files:
|
41
|
+
- History.txt
|
42
|
+
- Manifest.txt
|
43
|
+
- README.txt
|
31
44
|
files:
|
32
45
|
- History.txt
|
33
46
|
- Manifest.txt
|
@@ -48,42 +61,36 @@ files:
|
|
48
61
|
- test/test_win32_file.rb
|
49
62
|
- test/test_service.rb
|
50
63
|
- test/test_helper.rb
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
- test/test_service.rb
|
55
|
-
- test/test_truncator.rb
|
56
|
-
- test/test_win32_file.rb
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: " by Adam Meehan (adam.meehan@gmail.com)"
|
66
|
+
post_install_message:
|
57
67
|
rdoc_options:
|
58
68
|
- --main
|
59
69
|
- README.txt
|
60
|
-
|
61
|
-
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
-
|
66
|
-
|
67
|
-
|
68
|
-
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
version:
|
69
84
|
requirements: []
|
70
85
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
-
|
82
|
-
name: hoe
|
83
|
-
version_requirement:
|
84
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
85
|
-
requirements:
|
86
|
-
- - ">="
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: 1.3.0
|
89
|
-
version:
|
86
|
+
rubyforge_project: logtwuncator
|
87
|
+
rubygems_version: 1.0.1
|
88
|
+
signing_key:
|
89
|
+
specification_version: 2
|
90
|
+
summary: A win32 log file truncator and archiver with windows service
|
91
|
+
test_files:
|
92
|
+
- test/test_service.rb
|
93
|
+
- test/test_truncator.rb
|
94
|
+
- test/test_win32_file.rb
|
95
|
+
- test/test_helper.rb
|
96
|
+
- test/test_daemon.rb
|