Skip to content

Commit 7f798e1

Browse files
authored
Merge pull request #31 from ekohl/fix-java
Patch java_bin if overridden
2 parents 58c53c0 + a6e5c86 commit 7f798e1

2 files changed

Lines changed: 79 additions & 16 deletions

File tree

resources/puppetlabs/lein-ezbake/template/foss/ext/default.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# Init settings for <%= EZBake::Config[:project] %>
33
###########################################
44

5+
# used by openvox-server CLI apps, not by the systemd unit
6+
JAVA_BIN="<%= EZBake::Config[:java_bin] %>"
7+
58
# Modify this if you'd like to change the memory allocation, enable JMX, etc
69
JAVA_ARGS="<%= EZBake::Config[:java_args] %>"
710

resources/puppetlabs/lein-ezbake/template/global/ext/fpm.rb

Lines changed: 76 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,71 @@
44
require 'optparse'
55
require 'ostruct'
66

7+
def patch_files(options)
8+
if options.java_bin == EZBake::Config[:java_bin]
9+
yield
10+
else
11+
suffix = '.backup'
12+
[
13+
# Debian
14+
'/etc/default/puppet*',
15+
'/lib/systemd/system/puppet*.service',
16+
# RPM
17+
'/usr/lib/systemd/system/puppet*.service',
18+
'/etc/sysconfig/puppet*',
19+
].each do |path|
20+
Dir.glob(File.join(options.chdir, path)).each do |real_path|
21+
content = File.read(real_path)
22+
next unless content.include?(EZBake::Config[:java_bin])
23+
24+
warn "Copying #{real_path} to #{real_path}#{suffix}"
25+
FileUtils.cp(real_path, "#{real_path}#{suffix}")
26+
warn "Patching #{real_path} to use #{options.java_bin}"
27+
File.write(real_path, content.gsub(EZBake::Config[:java_bin], options.java_bin))
28+
end
29+
end
30+
31+
yield
32+
33+
Dir.glob(File.join(options.chdir, '**', "*#{suffix}")).each do |path|
34+
original = File.join(File.dirname(path), File.basename(path, suffix))
35+
warn "Restoring #{path} to #{original}"
36+
FileUtils.mv(path, original)
37+
end
38+
end
39+
end
40+
741
options = OpenStruct.new
42+
43+
# ezbake.rb is rendered from
44+
# resources/puppetlabs/lein-ezbake/staging-templates/ezbake.rb.mustache
45+
#
46+
# inside the build container, fpm.rb is at:
47+
# /code/target/staging/puppetserver-8.9.0/ext/fpm.rb
48+
# ezbake:
49+
# /code/target/staging/ezbake.rb
50+
#
51+
# we do this hula hoop jump because in our build process the ezbake.rb exists
52+
# We also distribute a .tar.gz. This contains the compiled jar + fpm.rb.
53+
# fpm.rb is executed while we build the packages. This is the same process as
54+
# compiling the jar and rendering ezbake from
55+
# resources/puppetlabs/lein-ezbake/staging-templates/ezbake.rb.mustache
56+
# people that try to build their own package based on our tar, like FreeBSD, don't have the ezbake.rb
57+
#
58+
# patches welcome to move ezbake.rb into the tar *or* get rid of ezbake
59+
begin
60+
require_relative '../../ezbake'
61+
rescue LoadError
62+
options.java_bin = '/usr/bin/java'
63+
else
64+
options.java_bin = EZBake::Config[:java_bin]
65+
end
66+
867
# settin' some defaults
968
options.systemd_el = 0
1069
options.systemd_sles = 0
1170
options.sles = 0
1271
options.java = 'java-1.8.0-openjdk-headless'
13-
options.java_bin = '/usr/bin/java'
1472
options.release = 1
1573
options.platform_version = 0
1674
options.replaces = {}
@@ -408,22 +466,24 @@
408466
puts "#{Dir.pwd}"
409467
end
410468

411-
# fpm sends all output to stdout
412-
out, _, stat = Open3.capture3("#{fpm_editor} fpm #{fpm_opts.join(' ')}")
413-
fail "Error trying to run FPM for #{options.dist}!\n#{out}" unless stat.success?
469+
patch_files(options) do
470+
# fpm sends all output to stdout
471+
out, _, stat = Open3.capture3("#{fpm_editor} fpm #{fpm_opts.join(' ')}")
472+
fail "Error trying to run FPM for #{options.dist}!\n#{out}" unless stat.success?
473+
474+
puts "#{out}"
414475

415-
puts "#{out}"
476+
if options.termini
477+
if options.debug
478+
puts "=========================="
479+
puts "FPM COMMAND"
480+
puts "fpm #{termini_opts.join(' ')}"
481+
puts "=========================="
482+
end
416483

417-
if options.termini
418-
if options.debug
419-
puts "=========================="
420-
puts "FPM COMMAND"
421-
puts "fpm #{termini_opts.join(' ')}"
422-
puts "=========================="
484+
# fpm sends all output to stdout
485+
out, _, stat = Open3.capture3("fpm #{termini_opts.join(' ')}")
486+
fail "Error trying to run FPM for the termini for #{options.dist}!\n#{out}" unless stat.success?
487+
puts "#{out}"
423488
end
424-
425-
# fpm sends all output to stdout
426-
out, _, stat = Open3.capture3("fpm #{termini_opts.join(' ')}")
427-
fail "Error trying to run FPM for the termini for #{options.dist}!\n#{out}" unless stat.success?
428-
puts "#{out}"
429489
end

0 commit comments

Comments
 (0)