Skip to content

Commit e4b36a5

Browse files
author
Glyn Normington
committed
killjava script and diagnostic improvements
Locate killjava script relative to $HOME. The application directory path is not the same at droplet execution time as it is when the buildpack runs, so it is necessary to use $HOME at droplet execution time. Tidy up killjava script to format messages more cleanly and ensure they are flushed synchronously. Use correct encoding for empty string. String.new produces an empty string which is encoded with ASCII-8BIT rather than UTF-8. Use '' instead since this is encoded with UTF-8. The net result is that logging certain hashes now produces human-readable YAML rather than YAML containing binary. Make Buildpack.log flush each write [#51899933] [#51561265]
1 parent a5c0fb1 commit e4b36a5

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

lib/java_buildpack/buildpack.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def initialize(app_dir)
3838
Buildpack.require_component_files
3939
components = Buildpack.components
4040

41-
java_home = String.new
41+
java_home = ''
4242
java_opts = Array.new
4343

4444
@jres = components['jres'].map do |jre|
@@ -127,6 +127,7 @@ def release
127127
# @param [Hash, String] log_data Data to be logged
128128
def self.log(log_title, log_data)
129129
File.open(@@buildpack_log_file, 'a') do |log_file|
130+
log_file.sync = true
130131
log_file.write "#{log_title} @ #{time_in_millis}::\n"
131132
log_file.write(log_data.is_a?(Hash) ? log_data.to_yaml: log_data)
132133
end
@@ -147,6 +148,7 @@ def self.create_log_file(app_dir)
147148

148149
# Create new log file and write current time into it.
149150
File.open(@@buildpack_log_file, 'a') do |log_file|
151+
log_file.sync = true
150152
log_file.write "#{@@buildpack_log_file} @ #{time_in_millis}\n"
151153
end
152154
end

lib/java_buildpack/jre/openjdk.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def compile
6969
#
7070
# @return [void]
7171
def release
72-
@java_opts << "-XX:OnOutOfMemoryError=#{@diagnostics_dir}/killjava"
72+
@java_opts << "-XX:OnOutOfMemoryError=$HOME/buildpack-diagnostics/killjava"
7373
@java_opts.concat memory(@configuration)
7474
end
7575

resources/openjdk/diagnostics/killjava

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ $stdout.sync = true
2020

2121
module Kill
2222

23-
def Kill.log(log_title, log_data)
23+
def Kill.log(log_data)
2424
log_file = "#{File.dirname(__FILE__)}/buildpack.log"
2525
File.open(log_file, 'a') do |log_file|
26-
log_file.write "#{log_title} @ #{Kill.time_in_millis}::\n"
27-
log_file.write(log_data)
26+
log_file.sync = true
27+
log_file.write "#{log_data} @ #{Kill.time_in_millis}\n"
2828
end
2929
end
3030

@@ -35,10 +35,11 @@ module Kill
3535
end
3636

3737
begin
38-
Kill.log("#{__FILE__} attempting to kill Java processes",
39-
`pkill -9 -f .*-XX:OnOutOfMemoryError=.*#{File.basename(__FILE__)}`)
38+
command = "pkill -9 -f .*-XX:OnOutOfMemoryError=.*#{File.basename(__FILE__)}"
39+
Kill.log("#{__FILE__} attempting to kill Java processes using `#{command}`")
40+
`#{command}`
4041
rescue => e
41-
Kill.log("#{__FILE__} failed with exception", "#{e.inspect}, #{e.backtrace}\n")
42+
Kill.log("#{__FILE__} failed with exception #{e.inspect}, #{e.backtrace}\n")
4243
abort e.message
4344
end
4445

0 commit comments

Comments
 (0)