pdo 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/bin/pdo +1 -1
- data/conf/log4r.yaml +12 -2
- data/lib/pdo.rb +7 -5
- data/lib/pdo/host.rb +14 -16
- data/lib/pdo/logging.rb +22 -5
- data/lib/pdo/task.rb +5 -5
- data/lib/pdo/version.rb +1 -1
- data/log/.gitignore +4 -0
- metadata +10 -5
- checksums.yaml +0 -15
data/.gitignore
CHANGED
data/bin/pdo
CHANGED
data/conf/log4r.yaml
CHANGED
@@ -5,14 +5,24 @@ log4r_config:
|
|
5
5
|
level : INFO
|
6
6
|
outputters:
|
7
7
|
- stderr
|
8
|
+
- logfile
|
8
9
|
|
9
|
-
# define all outputters (incl. formatters)
|
10
10
|
outputters:
|
11
11
|
- type : StderrOutputter
|
12
12
|
name : stderr
|
13
|
-
level :
|
13
|
+
level : ERROR
|
14
14
|
formatter:
|
15
15
|
type : PatternFormatter
|
16
16
|
pattern: "%d, %C: %l, %m"
|
17
17
|
|
18
|
+
- type : DateFileOutputter
|
19
|
+
name : logfile
|
20
|
+
level : INFO
|
21
|
+
date_pattern: '%Y%m%d'
|
22
|
+
trunc : 'false'
|
23
|
+
dirname : '#{LOGDIR}'
|
24
|
+
formatter :
|
25
|
+
type : PatternFormatter
|
26
|
+
pattern : '%d %l: %m'
|
27
|
+
|
18
28
|
# vim: set et ts=2 sts=2 sw=2 si sta:
|
data/lib/pdo.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
require 'pdo/logging'
|
4
4
|
|
5
5
|
class PDO
|
6
|
+
include Process
|
7
|
+
include Logging
|
8
|
+
|
6
9
|
def initialize(tasks, thread_num)
|
7
|
-
@logger = Logger[self.class.to_s] || Logger['pdo']
|
8
10
|
@tasks = tasks
|
9
11
|
@thread_num = thread_num
|
10
12
|
end
|
@@ -23,14 +25,14 @@ class PDO
|
|
23
25
|
1.upto(n) do
|
24
26
|
Thread.new do
|
25
27
|
while true do
|
26
|
-
|
28
|
+
logger.info "#{Thread.current.object_id} started."
|
27
29
|
begin
|
28
30
|
execute(@tasks.next)
|
29
31
|
# presumably new data is ready, thus i stop.
|
30
32
|
# main thread will read :output and then wakes me up.
|
31
33
|
Thread.stop
|
32
34
|
rescue
|
33
|
-
|
35
|
+
logger.info "No more task for #{Thread.current.object_id}."
|
34
36
|
break
|
35
37
|
end
|
36
38
|
end
|
@@ -44,7 +46,7 @@ class PDO
|
|
44
46
|
Thread.list.each do |t|
|
45
47
|
next if t == Thread.main
|
46
48
|
if t.key? :output and t.key? :new_data and t[:new_data] then
|
47
|
-
|
49
|
+
logger.info "#{t.object_id} finished."
|
48
50
|
puts "=== #{t[:target]} ==="
|
49
51
|
t[:output].each {|x| puts x}
|
50
52
|
# puts t[:output].join('').gsub("\n", ' | ').chomp(' | ')
|
data/lib/pdo/host.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'log4r'
|
4
|
-
include Log4r
|
5
|
-
|
6
3
|
require 'pp'
|
7
4
|
require 'yaml'
|
5
|
+
require_relative 'logging'
|
8
6
|
|
9
7
|
module Host
|
10
8
|
|
11
|
-
|
9
|
+
include Logging
|
12
10
|
|
13
11
|
@@recursive_level = 9
|
14
12
|
def self.recursive_level=(level)
|
@@ -30,8 +28,8 @@ module Host
|
|
30
28
|
begin
|
31
29
|
hosts.update(YAML::load_file(f))
|
32
30
|
rescue => ex
|
33
|
-
|
34
|
-
|
31
|
+
logger.warn { "#{ex.class}: #{ex.message}" }
|
32
|
+
logger.debug { ex.backtrace.join "\n" }
|
35
33
|
end
|
36
34
|
end
|
37
35
|
return @@host_hash = hosts
|
@@ -47,7 +45,7 @@ module Host
|
|
47
45
|
|
48
46
|
level += 1
|
49
47
|
if level > @@recursive_level then
|
50
|
-
|
48
|
+
logger.warn "circle detected in the host definition file."
|
51
49
|
return []
|
52
50
|
end
|
53
51
|
|
@@ -64,11 +62,11 @@ module Host
|
|
64
62
|
return [ group ]
|
65
63
|
end
|
66
64
|
rescue => ex
|
67
|
-
|
65
|
+
logger.warn {
|
68
66
|
"failed to get hash value for #{group.inspect}. "\
|
69
67
|
'possibly an error in the yaml file.'
|
70
68
|
}
|
71
|
-
|
69
|
+
logger.debug { ex.backtrace.join "\n" }
|
72
70
|
return []
|
73
71
|
end
|
74
72
|
end
|
@@ -83,7 +81,7 @@ module Host
|
|
83
81
|
elsif list_of_hosts.is_a? Array then
|
84
82
|
list_of_hosts.each do |h|
|
85
83
|
if not h.is_a? String then
|
86
|
-
|
84
|
+
logger.warn {
|
87
85
|
"invalid host or group format: #{h.inspect}\n"\
|
88
86
|
'possibly an error in the yaml file.'
|
89
87
|
}
|
@@ -96,7 +94,7 @@ module Host
|
|
96
94
|
end
|
97
95
|
end
|
98
96
|
else
|
99
|
-
|
97
|
+
logger.fatal "I don't know how to handle this. "\
|
100
98
|
'possibly an error in the yaml file.'
|
101
99
|
exit 1
|
102
100
|
end
|
@@ -116,7 +114,7 @@ module Host
|
|
116
114
|
|
117
115
|
def stepping(hosts, step)
|
118
116
|
unless hosts.is_a? Array or step.is_a? Array then
|
119
|
-
|
117
|
+
logger.warn "both hosts or step should be array."
|
120
118
|
return nil
|
121
119
|
end
|
122
120
|
|
@@ -162,11 +160,11 @@ module Host
|
|
162
160
|
return [ ]
|
163
161
|
end
|
164
162
|
rescue => ex
|
165
|
-
|
163
|
+
logger.warn {
|
166
164
|
"failed to get hash value for #{group.inspect}. "\
|
167
165
|
'maybe a wrong key is specifid?'
|
168
166
|
}
|
169
|
-
|
167
|
+
logger.debug { ex.backtrace.join "\n" }
|
170
168
|
return []
|
171
169
|
end
|
172
170
|
end
|
@@ -179,13 +177,13 @@ module Host
|
|
179
177
|
elsif pointer.is_a? Array then
|
180
178
|
return pointer
|
181
179
|
else
|
182
|
-
|
180
|
+
logger.fatal "I don't know how to handle this. "\
|
183
181
|
'possibly an error in the yaml file.'
|
184
182
|
exit 1
|
185
183
|
end
|
186
184
|
|
187
185
|
end
|
188
186
|
|
189
|
-
end
|
187
|
+
end # module Host
|
190
188
|
|
191
189
|
# vim: set et ts=2 sts=2 sw=2 si sta :
|
data/lib/pdo/logging.rb
CHANGED
@@ -4,11 +4,28 @@ require 'log4r'
|
|
4
4
|
require 'log4r/yamlconfigurator'
|
5
5
|
require 'log4r/outputter/datefileoutputter'
|
6
6
|
|
7
|
-
|
7
|
+
module Logging
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
Log4r::YamlConfigurator
|
12
|
-
}
|
9
|
+
include Log4r
|
10
|
+
# set the default log directory
|
11
|
+
Log4r::YamlConfigurator['LOGDIR'] =
|
12
|
+
File.expand_path("#{File.dirname(__FILE__)}/../../log")
|
13
|
+
|
14
|
+
def logger
|
15
|
+
|
16
|
+
return @logger if @logger
|
17
|
+
|
18
|
+
conf_dir = File.expand_path("#{File.dirname(__FILE__)}/../../conf")
|
19
|
+
|
20
|
+
[conf_dir, '/etc/pdo', "#{ENV['HOME']}/.pdo"].each { |dir|
|
21
|
+
conf = "#{dir}/log4r.yaml"
|
22
|
+
Log4r::YamlConfigurator.load_yaml_file conf if File.exists? conf
|
23
|
+
}
|
24
|
+
|
25
|
+
@logger = Logger[self.class.to_s] || Logger['pdo']
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end # module Logging
|
13
30
|
|
14
31
|
# vim: set et ts=2 sts=2 sw=2 si sta :
|
data/lib/pdo/task.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
include Log4r
|
3
|
+
require_relative 'logging'
|
5
4
|
|
6
5
|
class SSHCmd
|
6
|
+
include Logging
|
7
|
+
|
7
8
|
def initialize(local, sshopts)
|
8
|
-
@logger = Logger[self.class.to_s] || Logger['pdo']
|
9
9
|
|
10
10
|
@defaults = {
|
11
11
|
:user => 'root',
|
@@ -19,7 +19,7 @@ class SSHCmd
|
|
19
19
|
@local = local
|
20
20
|
@sshopts = @defaults[:sshopts]
|
21
21
|
@sshopts = @defaults[:sshopts].update sshopts if sshopts
|
22
|
-
|
22
|
+
logger.debug { @sshopts.inspect }
|
23
23
|
end
|
24
24
|
|
25
25
|
def form(host, cmd)
|
@@ -66,9 +66,9 @@ class SSHCmd
|
|
66
66
|
end
|
67
67
|
|
68
68
|
class Task
|
69
|
+
include Logging
|
69
70
|
|
70
71
|
def initialize
|
71
|
-
@logger = Logger[self.class.to_s] || Logger['pdo']
|
72
72
|
@task_q = Queue.new
|
73
73
|
end
|
74
74
|
|
data/lib/pdo/version.rb
CHANGED
data/log/.gitignore
ADDED
metadata
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- bqbn
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-
|
12
|
+
date: 2013-05-20 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: log4r
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ! '>'
|
18
20
|
- !ruby/object:Gem::Version
|
@@ -20,6 +22,7 @@ dependencies:
|
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ! '>'
|
25
28
|
- !ruby/object:Gem::Version
|
@@ -47,30 +50,32 @@ files:
|
|
47
50
|
- lib/pdo/pdoopts.rb
|
48
51
|
- lib/pdo/task.rb
|
49
52
|
- lib/pdo/version.rb
|
53
|
+
- log/.gitignore
|
50
54
|
- pdo.gemspec
|
51
55
|
homepage: https://github.com/bqbn/pdo
|
52
56
|
licenses:
|
53
57
|
- MIT
|
54
|
-
metadata: {}
|
55
58
|
post_install_message:
|
56
59
|
rdoc_options: []
|
57
60
|
require_paths:
|
58
61
|
- lib
|
59
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
60
64
|
requirements:
|
61
65
|
- - ! '>='
|
62
66
|
- !ruby/object:Gem::Version
|
63
67
|
version: 1.9.3
|
64
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
65
70
|
requirements:
|
66
71
|
- - ! '>='
|
67
72
|
- !ruby/object:Gem::Version
|
68
73
|
version: '0'
|
69
74
|
requirements: []
|
70
75
|
rubyforge_project:
|
71
|
-
rubygems_version:
|
76
|
+
rubygems_version: 1.8.25
|
72
77
|
signing_key:
|
73
|
-
specification_version:
|
78
|
+
specification_version: 3
|
74
79
|
summary: pdo is a wrapper for running commands on or against multiple hosts at the
|
75
80
|
same time.
|
76
81
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
ZGRhYjNlMDBhZWRlMWEzNWRhZWM1OGYwZDQwZjQ4ODVlZjc2NTY0Zg==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NGU5YWQxOGI4NmYwNDgxZmUwMmJhYTdiMTdhNTQyNmRiYThlYmRkNw==
|
7
|
-
!binary "U0hBNTEy":
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
MWRmMjczMzIyN2M4ZGYxN2ZjNDg4NjgzYjVkYzIwMTBkZGQ5ZWM2MTk4Zjdk
|
10
|
-
MWM2ZWU1MGI0ZmI0NWZiYmQ5OGVkNjUyNDVhMjM4YzBkYmVhM2JlYjA2NTNk
|
11
|
-
N2NiMTE2MGM1YTk5MzQ4ZDI3OTdiODQ5ZjNhNGIzYTI1YThhNGI=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NDhiOTU5N2U4NTZkY2VjNzNmYmZjNzU3Y2ZhYzA0ZmY1NzRkZDI2ZTVmNzQ4
|
14
|
-
ZDExMTI5YzRiNzk4MThmYmUxNzUxMGFlZmNhMDgyOTBjYjAzOTNiMjNmMzRl
|
15
|
-
YzM3NTdmMmU0ODU0YjM3NjBkNDU4MTNiMjgwZjI4NGQwNGZkYWQ=
|