itamae-mitsurin 0.46 → 0.47

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d1f6d29ae9b227945bb222e0eb972c819039c5b
4
- data.tar.gz: 9acdc555933504a72946673268da92c337ee7647
3
+ metadata.gz: 4b2e51e59486a4d9e4012683da2438208ae1ff71
4
+ data.tar.gz: e940d9d0f5426b12c422809299bc5c4c031f0897
5
5
  SHA512:
6
- metadata.gz: 618c953d6cac86794aa74fcc8637e48b9a079848a44fba14dfa17f644fedac7ed78e576637b0aa3995d6e4cf55f654547fe1ea47be0bea2c69e435b690b32581
7
- data.tar.gz: f20681d4563b280058249ae489677edaf94534fd587bd85d50f424ff719d6cb43eeb6da342d7a625bf36d1b760fac044a7524625c8c96dd406238edbda02dc39
6
+ metadata.gz: 6d0cfb95644d5f397e8c65a3d4412449fab7e3f9d1f22935fa16a151ec5ebc06f509af45c2d2aa85e9f1359ed2766ded7b6473aa068bb9f60d2ef005caffe668
7
+ data.tar.gz: f896bfdf02712c6c37e5d825ae300d367137c13732cc154ba62394a64c1d2af30cc43164bf73c07ea87fd790a46834b18ca283bb8ececd903c86b5916fe8e4ea
@@ -12,7 +12,9 @@ module ItamaeMitsurin
12
12
  super
13
13
 
14
14
  ItamaeMitsurin.logger.level = ::Logger.const_get(options[:log_level].upcase)
15
+ ItamaeMitsurin.file_logger.level = ::Logger.const_get(options[:log_level].upcase)
15
16
  ItamaeMitsurin.logger.formatter.colored = options[:color]
17
+ ItamaeMitsurin.file_logger.formatter.colored = options[:color]
16
18
  end
17
19
 
18
20
  def self.define_exec_options
@@ -120,10 +120,24 @@ module ItamaeMitsurin
120
120
  end
121
121
  end
122
122
 
123
+ # @logger = ::Logger.new($stdout).tap do |l|
124
+ # l.formatter = ItamaeMitsurin::Logger::Formatter.new
125
+ # end.extend(ItamaeMitsurin::Logger::Helper)
126
+
123
127
  @logger = ::Logger.new($stdout).tap do |l|
124
128
  l.formatter = ItamaeMitsurin::Logger::Formatter.new
125
129
  end.extend(ItamaeMitsurin::Logger::Helper)
126
130
 
131
+ class ItamaeMitsurin::Logger::FileFormatter < ItamaeMitsurin::Logger::Formatter
132
+ def colorize(str, severity)
133
+ Time.now.strftime('%Y %m %d %H:%M:%S %z').to_s + str
134
+ end
135
+ end
136
+
137
+ @file_logger = ::Logger.new('logs/itamae.log', 5, 100 * 1024 * 1024).tap do |l|
138
+ l.formatter = ItamaeMitsurin::Logger::FileFormatter.new
139
+ end.extend(ItamaeMitsurin::Logger::Helper)
140
+
127
141
  class << self
128
142
  def logger
129
143
  @logger
@@ -132,5 +146,13 @@ module ItamaeMitsurin
132
146
  def logger=(l)
133
147
  @logger = l.extend(ItamaeMitsurin::Logger::Helper)
134
148
  end
149
+
150
+ def file_logger
151
+ @file_logger
152
+ end
153
+
154
+ def file_logger=(l)
155
+ @file_logger = l.extend(ItamaeMitsurin::Logger::Helper)
156
+ end
135
157
  end
136
158
  end
@@ -9,17 +9,18 @@ module ItamaeMitsurin
9
9
  all = []
10
10
  if (ARGV[0] == '-T' || ARGV[0] == '--tasks') && ARGV[1] != nil
11
11
  if File.exists?("nodes/#{ARGV[1]}")
12
- project_h = {:project => ARGV[1]}
13
- File.open "Project.json", 'w' do |f|
14
- f.flock File::LOCK_EX
15
- f.puts project_h.to_json
16
- f.flock File::LOCK_UN
17
- end
18
- puts TaskBase.hl.color "Changed target mode '#{ARGV[1]}'", :green
12
+ project_h = {:project => ARGV[1]}
13
+ File.open "Project.json", 'w' do |f|
14
+ f.flock File::LOCK_EX
15
+ f.puts project_h.to_json
16
+ f.flock File::LOCK_UN
17
+ end
18
+ puts TaskBase.hl.color "Changed target mode '#{ARGV[1]}'", :green
19
19
  else
20
20
  raise "Change mode error '#{ARGV[1]}' is not exists"
21
21
  end
22
22
  end
23
+
23
24
  ret = JSON.parse(File.read("Project.json"))
24
25
  target = ret["project"] << '/**'
25
26
 
@@ -31,6 +32,7 @@ module ItamaeMitsurin
31
32
  rescue JSON::ParserError => e
32
33
  puts e.class.to_s + ", " + e.backtrace[0].to_s
33
34
  puts "Node error, nodefile:#{node_file}, reason:#{e.message}"
35
+ TaskBase.file_logger.fatal "Node error, nodefile:#{node_file}, reason:#{e.message}"
34
36
  end
35
37
 
36
38
  node_short = node_h[:environments][:hostname].split(".")[0]
@@ -51,6 +53,7 @@ module ItamaeMitsurin
51
53
  rescue Exception => e
52
54
  puts e.class.to_s + ", " + e.backtrace[0].to_s
53
55
  puts "Node or role error, nodefile:#{node_file}, reason:#{e.message}"
56
+ TaskBase.file_logger.fatal "Node or role error, nodefile:#{node_file}, reason:#{e.message}"
54
57
  else
55
58
  recipes.flatten!
56
59
  end
@@ -63,6 +66,7 @@ module ItamaeMitsurin
63
66
  rescue Exception => e
64
67
  puts e.class.to_s + ", " + e.backtrace[0].to_s
65
68
  puts "Node or environment error, nodefile:#{node_file}, reason:#{e.message}"
69
+ TaskBase.file_logger.fatal "Node or environment error, nodefile:#{node_file}, reason:#{e.message}"
66
70
  end
67
71
 
68
72
  # get recipes attr
@@ -132,7 +136,7 @@ module ItamaeMitsurin
132
136
  command << " --ask-password" unless ssh_password.nil?
133
137
  command << " --dry-run" if ENV['dry-run'] == "true"
134
138
  command << " -l debug" if ENV['debug'] == "true"
135
- command << " -c logs/config/itamae_with_target_task.config"
139
+ # command << " -c logs/config/itamae_with_target_task.config"
136
140
 
137
141
  # Pass to read the recipe command
138
142
  command_recipe = []
@@ -155,6 +159,7 @@ module ItamaeMitsurin
155
159
  command << command_recipe.join
156
160
 
157
161
  puts TaskBase.hl.color(%!Run Itamae to "#{bname}"!, :red)
162
+ TaskBase.file_logger.info(%!Run Itamae to "#{bname}"!)
158
163
  run_list_noti = []
159
164
  command_recipe.each { |c_recipe|
160
165
  unless c_recipe.split("/")[4].split(".")[0] == 'default'
@@ -165,9 +170,12 @@ module ItamaeMitsurin
165
170
  }
166
171
 
167
172
  puts TaskBase.hl.color(%!Run List to \"#{run_list_noti.uniq.join(", ")}\"!, :green)
173
+ TaskBase.file_logger.info(%!Run List to \"#{run_list_noti.uniq.join(", ")}\"!)
168
174
  puts TaskBase.hl.color(%!#{command}!, :white)
175
+ TaskBase.file_logger.debug(%!#{command}!)
169
176
  st = system command
170
177
  exit 1 unless st
178
+ TaskBase.file_logger.info "itamae_with_target_task end."
171
179
  end
172
180
  end
173
181
  end
@@ -1,6 +1,7 @@
1
1
  require 'json'
2
2
  require 'highline'
3
- require "tmpdir"
3
+ require 'tmpdir'
4
+ require 'logger'
4
5
 
5
6
  module ItamaeMitsurin
6
7
  module Mitsurin
@@ -82,6 +83,16 @@ module ItamaeMitsurin
82
83
  def handler_logger
83
84
  default = {"handlers"=>[{"type"=>"json", "path"=>"itamae-log.json"}]}
84
85
  end
86
+
87
+ def file_logger
88
+ file_logger = ::Logger.new('logs/itamae.log', 5, 100 * 1024 * 1024).tap do |l|
89
+ l.formatter = proc do |serverity, datetime, progname, msg|
90
+ "#{datetime.strftime('%Y %m %d %H:%M:%S %z')} #{serverity} : #{msg}\n"
91
+ end
92
+ end
93
+
94
+ file_logger
95
+ end
85
96
  end
86
97
 
87
98
  end
@@ -35,6 +35,7 @@ module ItamaeMitsurin
35
35
  unless errors.empty?
36
36
  errors.each do |error|
37
37
  ItamaeMitsurin.logger.error "'#{error.position.join('->')}' #{error.message}"
38
+ ItamaeMitsurin.file_logger.error "'#{error.position.join('->')}' #{error.message}"
38
39
  end
39
40
  raise ValidationError
40
41
  end
@@ -33,6 +33,7 @@ module ItamaeMitsurin
33
33
  def validate!
34
34
  unless [:delay, :delayed, :immediately].include?(timing)
35
35
  ItamaeMitsurin.logger.error "'#{timing}' is not valid notification timing. (Valid option is delayed or immediately)"
36
+ ItamaeMitsurin.file_logger.error "'#{timing}' is not valid notification timing. (Valid option is delayed or immediately)"
36
37
  abort
37
38
  end
38
39
  end
@@ -66,6 +66,11 @@ module ItamaeMitsurin
66
66
  @children.run
67
67
  run_delayed_notifications
68
68
  end
69
+
70
+ ItamaeMitsurin.file_logger.with_indent do
71
+ @children.run
72
+ run_delayed_notifications
73
+ end
69
74
  end
70
75
  end
71
76
 
@@ -83,6 +88,7 @@ module ItamaeMitsurin
83
88
 
84
89
  def show_banner
85
90
  ItamaeMitsurin.logger.info "Recipe: #{@path}"
91
+ ItamaeMitsurin.file_logger.info "Recipe: #{@path}"
86
92
  end
87
93
 
88
94
  class EvalContext
@@ -58,6 +58,7 @@ module ItamaeMitsurin
58
58
  class_name = to_camel_case(name.to_s)
59
59
  if Resource.const_defined?(class_name)
60
60
  ItamaeMitsurin.logger.warn "Redefine class. (#{class_name})"
61
+ ItamaeMitsurin.file_logger.warn "Redefine class. (#{class_name})"
61
62
  return
62
63
  end
63
64
 
@@ -149,6 +149,7 @@ module ItamaeMitsurin
149
149
  end
150
150
  rescue Backend::CommandExecutionError
151
151
  ItamaeMitsurin.logger.error "#{resource_type}[#{resource_name}] Failed."
152
+ ItamaeMitsurin.file_logger.error "#{resource_type}[#{resource_name}] Failed."
152
153
  exit 2
153
154
  end
154
155
 
@@ -189,6 +190,7 @@ module ItamaeMitsurin
189
190
  if runner.dry_run?
190
191
  unless respond_to?(method_name)
191
192
  ItamaeMitsurin.logger.error "action #{action.inspect} is unavailable"
193
+ ItamaeMitsurin.file_logger.error "action #{action.inspect} is unavailable"
192
194
  end
193
195
  else
194
196
  args = [method_name]
@@ -239,12 +241,14 @@ module ItamaeMitsurin
239
241
  elsif current_value.nil? && !value.nil?
240
242
  ItamaeMitsurin.logger.color :green do
241
243
  ItamaeMitsurin.logger.info "#{resource_type}[#{resource_name}] #{key} will be '#{value}'"
244
+ ItamaeMitsurin.file_logger.info "#{resource_type}[#{resource_name}] #{key} will be '#{value}'"
242
245
  end
243
246
  elsif current_value == value || value.nil?
244
247
  ItamaeMitsurin.logger.debug "#{resource_type}[#{resource_name}] #{key} will not change (current value is '#{current_value}')"
245
248
  else
246
249
  ItamaeMitsurin.logger.color :green do
247
250
  ItamaeMitsurin.logger.info "#{resource_type}[#{resource_name}] #{key} will change from '#{current_value}' to '#{value}'"
251
+ ItamaeMitsurin.file_logger.info "#{resource_type}[#{resource_name}] #{key} will change from '#{current_value}' to '#{value}'"
248
252
  end
249
253
  end
250
254
  end
@@ -347,9 +351,11 @@ module ItamaeMitsurin
347
351
  end
348
352
 
349
353
  ItamaeMitsurin.logger.info message
354
+ ItamaeMitsurin.file_logger.info message
350
355
 
351
356
  if notification.instance_of?(Subscription)
352
357
  ItamaeMitsurin.logger.info "(because it subscribes this resource)"
358
+ ItamaeMitsurin.file_logger.info "(because it subscribes this resource)"
353
359
  end
354
360
 
355
361
  if notification.delayed?
@@ -364,11 +370,17 @@ module ItamaeMitsurin
364
370
  return if @verify_commands.empty?
365
371
 
366
372
  ItamaeMitsurin.logger.info "Verifying..."
373
+ ItamaeMitsurin.file_logger.info "Verifying..."
367
374
  ItamaeMitsurin.logger.with_indent do
368
375
  @verify_commands.each do |command|
369
376
  run_command(command)
370
377
  end
371
378
  end
379
+ ItamaeMitsurin.file_logger.with_indent do
380
+ @verify_commands.each do |command|
381
+ run_command(command)
382
+ end
383
+ end
372
384
  end
373
385
  end
374
386
  end
@@ -7,6 +7,7 @@ module ItamaeMitsurin
7
7
  class << self
8
8
  def run(recipe_files, backend_type, options)
9
9
  ItamaeMitsurin.logger.info "Starting Itamae..."
10
+ ItamaeMitsurin.file_logger.info "Starting Itamae..."
10
11
 
11
12
  backend = Backend.create(backend_type, options)
12
13
  runner = self.new(backend, options)
@@ -99,22 +100,26 @@ module ItamaeMitsurin
99
100
  unless @backend.run_command("which ohai", error: false).exit_status == 0
100
101
  # install Ohai
101
102
  ItamaeMitsurin.logger.info "Installing Chef package... (to use Ohai)"
103
+ ItamaeMitsurin.file_logger.info "Installing Chef package... (to use Ohai)"
102
104
  @backend.run_command("curl -L https://www.opscode.com/chef/install.sh | bash")
103
105
  end
104
106
 
105
107
  ItamaeMitsurin.logger.info "Loading node data via ohai..."
108
+ ItamaeMitsurin.file_logger.info "Loading node data via ohai..."
106
109
  hash.merge!(JSON.parse(@backend.run_command("ohai").stdout))
107
110
  end
108
111
 
109
112
  if @options[:node_json]
110
113
  path = File.expand_path(@options[:node_json])
111
114
  ItamaeMitsurin.logger.info "Loading node data from #{path}..."
115
+ ItamaeMitsurin.file_logger.info "Loading node data from #{path}..."
112
116
  hash.merge!(JSON.load(open(path)))
113
117
  end
114
118
 
115
119
  if @options[:node_yaml]
116
120
  path = File.expand_path(@options[:node_yaml])
117
121
  ItamaeMitsurin.logger.info "Loading node data from #{path}..."
122
+ ItamaeMitsurin.file_logger.info "Loading node data from #{path}..."
118
123
  hash.merge!(YAML.load(open(path)) || {})
119
124
  end
120
125
 
@@ -1 +1 @@
1
- 0.46
1
+ 0.47
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae-mitsurin
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.46'
4
+ version: '0.47'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akihiro Kamiyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-08 00:00:00.000000000 Z
11
+ date: 2016-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor