From c1d2570a1250438db0e963f06e4d1f9de251caac Mon Sep 17 00:00:00 2001 From: Anton Baranov Date: Mon, 30 Apr 2018 12:05:38 -0400 Subject: [PATCH 1/2] Set java Xms and Xms for nexus Signed-off-by: Anton Baranov --- manifests/config.pp | 55 +++++++++++++++++++++++++++++++++ manifests/init.pp | 24 +++++++++------ manifests/params.pp | 3 ++ spec/classes/config_spec.rb | 61 +++++++++++++++++++++++++++++++------ 4 files changed, 125 insertions(+), 18 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 0f88c26..751d1dc 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -26,6 +26,9 @@ $nexus_context = $::nexus::nexus_context, $nexus_work_dir = $::nexus::nexus_work_dir, $nexus_data_folder = $::nexus::nexus_data_folder, + $nexus_java_initmemory = $::nexus::nexus_java_initmemory, + $nexus_java_maxmemory = $::nexus::nexus_java_maxmemory, + $nexus_java_add_number = $::nexus::nexus_java_add_number, $version = $::nexus::version, ) { @@ -34,11 +37,14 @@ # {karaf.data}/etc/nexus.properties where {karaf.data} is the work dir $conf_path = 'etc/nexus.properties' $nexus_properties_file = "${nexus_work_dir}/${conf_path}" + $java_config_file = "${nexus_root}/${nexus_home_dir}/bin/nexus.vmoptions" } elsif versioncmp($version, '3.0.0') >= 0 { $conf_path = 'etc/org.sonatype.nexus.cfg' $nexus_properties_file = "${nexus_root}/${nexus_home_dir}/${conf_path}" + $java_config_file = "${nexus_root}/${nexus_home_dir}/bin/nexus.vmoptions" } else { + $java_config_file = "${nexus_root}/${nexus_home_dir}/bin/jsw/conf/wrapper.conf" $conf_path = 'conf/nexus.properties' $nexus_properties_file = "${nexus_root}/${nexus_home_dir}/${conf_path}" } @@ -82,4 +88,53 @@ notify => Service['nexus'] } } + + if $nexus_java_initmemory { + if (versioncmp($version, '3.0.0') < 0) { + file_line {'comment_nexus_java_initmemory': + path => $java_config_file, + line => '#wrapper.java.initmemory=', + match => '^wrapper.java.initmemory=', + } + file_line {'set_nexus_java_xms': + path => $java_config_file, + line => "wrapper.java.additional.${nexus_java_add_number}=-Xms${nexus_java_initmemory}", + match => "^wrapper.java.additional.${nexus_java_add_number}=-Xms", + } + } else { + file_line {'set_nexus_java_xms': + path => $java_config_file, + line => "-Xms${nexus_java_initmemory}", + match => '^-Xms', + } + } + } + + if $nexus_java_maxmemory { + if (versioncmp($version, '3.0.0') < 0) { + file_line {'comment_nexus_java_maxmemory': + path => $java_config_file, + line => '#wrapper.java.maxmemory=', + match => '^wrapper.java.maxmemory=', + } + + if $nexus_java_initmemory { + $_num = $nexus_java_add_number + 1 + } else { + $_num = $nexus_java_add_number + } + + file_line {'set_nexus_java_xmx': + path => $java_config_file, + line => "wrapper.java.additional.${_num}=-Xmx${nexus_java_maxmemory}", + match => "^wrapper.java.additional.${_num}=-Xmx", + } + } else { + file_line {'set_nexus_java_xmx': + path => $java_config_file, + line => "-Xmx${nexus_java_maxmemory}", + match => '^-Xmx', + } + } + } } diff --git a/manifests/init.pp b/manifests/init.pp index fd90c5b..d2d4e8e 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -46,6 +46,9 @@ $nexus_work_recurse = $nexus::params::nexus_work_recurse, $nexus_context = $nexus::params::nexus_context, $nexus_manage_user = $nexus::params::nexus_manage_user, + $nexus_java_initmemory = $nexus::params::nexus_java_initmemory, + $nexus_java_maxmemory = $nexus::params::nexus_java_maxmemory, + $nexus_java_add_number = $nexus::params::nexus_java_add_number, $nexus_data_folder = $nexus::params::nexus_data_folder, $download_folder = $nexus::params::download_folder, $manage_config = $nexus::params::manage_config, @@ -119,15 +122,18 @@ if $manage_config { class{ 'nexus::config': - nexus_root => $nexus_root, - nexus_home_dir => $nexus_home_dir, - nexus_host => $nexus_host, - nexus_port => $nexus_port, - nexus_context => $nexus_context, - nexus_work_dir => $real_nexus_work_dir, - nexus_data_folder => $nexus_data_folder, - notify => Class['nexus::service'], - require => Anchor['nexus::setup'] + nexus_root => $nexus_root, + nexus_home_dir => $nexus_home_dir, + nexus_host => $nexus_host, + nexus_port => $nexus_port, + nexus_context => $nexus_context, + nexus_work_dir => $real_nexus_work_dir, + nexus_data_folder => $nexus_data_folder, + nexus_java_initmemory => $nexus_java_initmemory, + nexus_java_maxmemory => $nexus_java_maxmemory, + nexus_java_add_number => $nexus_java_add_number, + notify => Class['nexus::service'], + require => Anchor['nexus::setup'] } } diff --git a/manifests/params.pp b/manifests/params.pp index e27739f..80be0dc 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -36,6 +36,9 @@ $nexus_host = '0.0.0.0' $nexus_port = '8081' $nexus_context = '/nexus' + $nexus_java_initmemory = undef + $nexus_java_maxmemory = undef + $nexus_java_add_number = 5 $nexus_manage_user = true $pro_download_site = 'http://download.sonatype.com/nexus/professional-bundle' $nexus_data_folder = undef diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index 98a9362..959de09 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -1,20 +1,26 @@ require 'spec_helper' describe 'nexus::config', :type => :class do - let(:params) { + let(:defautl_params) { { - 'nexus_root' => '/foo', - 'nexus_home_dir' => '/bar', - 'nexus_host' => '1.1.1.1', - 'nexus_port' => '8888', - 'nexus_context' => '/baz', - 'nexus_work_dir' => '/foom', - 'version' => '2.11.2', - 'nexus_data_folder' => '', + 'nexus_root' => '/foo', + 'nexus_home_dir' => '/bar', + 'nexus_host' => '1.1.1.1', + 'nexus_port' => '8888', + 'nexus_context' => '/baz', + 'nexus_work_dir' => '/foom', + 'version' => '2.11.2', + 'nexus_java_initmemory' => '256M', + 'nexus_java_maxmemory' => '768M', + 'nexus_java_add_number' => 5, + 'nexus_data_folder' => '', } } context 'with nexus version 2.x test values' do + let (:params) do + defautl_params + end it { should contain_class('nexus::config') } it { should contain_file_line('nexus-application-host').with( @@ -40,6 +46,43 @@ 'match' => '^nexus-work', 'line' => 'nexus-work=/foom', ) } + it { should contain_file_line('comment_nexus_java_maxmemory').with( + 'path' => '/foo//bar/bin/jsw/conf/wrapper.conf', + 'match' => '^wrapper.java.maxmemory=', + 'line' => '#wrapper.java.maxmemory=', + ) } + it { should contain_file_line('comment_nexus_java_initmemory').with( + 'path' => '/foo//bar/bin/jsw/conf/wrapper.conf', + 'match' => '^wrapper.java.initmemory=', + 'line' => '#wrapper.java.initmemory=', + ) } + it { should contain_file_line('set_nexus_java_xms').with( + 'path' => '/foo//bar/bin/jsw/conf/wrapper.conf', + 'match' => '^wrapper.java.additional.5=-Xms', + 'line' => 'wrapper.java.additional.5=-Xms256M', + ) } + it { should contain_file_line('set_nexus_java_xmx').with( + 'path' => '/foo//bar/bin/jsw/conf/wrapper.conf', + 'match' => '^wrapper.java.additional.6=-Xmx', + 'line' => 'wrapper.java.additional.6=-Xmx768M', + ) } + end + context 'with nexus version 3.x test values' do + let (:params) do + defautl_params.merge({ + 'version' => '3.0.0', + }) + end + it { should contain_file_line('set_nexus_java_xms').with( + 'path' => '/foo//bar/bin/nexus.vmoptions', + 'match' => '^-Xms', + 'line' => '-Xms256M', + ) } + it { should contain_file_line('set_nexus_java_xmx').with( + 'path' => '/foo//bar/bin/nexus.vmoptions', + 'match' => '^-Xmx', + 'line' => '-Xmx768M', + ) } end end From 2a1f3f2106d5a26c869afddb6bbe01946888fef8 Mon Sep 17 00:00:00 2001 From: Anton Baranov Date: Mon, 7 May 2018 11:04:59 -0400 Subject: [PATCH 2/2] Fix typo Signed-off-by: Anton Baranov --- spec/classes/config_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index 959de09..69671ca 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'nexus::config', :type => :class do - let(:defautl_params) { + let(:default_params) { { 'nexus_root' => '/foo', 'nexus_home_dir' => '/bar', @@ -19,7 +19,7 @@ context 'with nexus version 2.x test values' do let (:params) do - defautl_params + default_params end it { should contain_class('nexus::config') } @@ -69,7 +69,7 @@ end context 'with nexus version 3.x test values' do let (:params) do - defautl_params.merge({ + default_params.merge({ 'version' => '3.0.0', }) end