From c2690e40d6aae77a620e6f0c20080b609ad77261 Mon Sep 17 00:00:00 2001 From: Antonio Romero Marin Date: Tue, 7 Mar 2017 18:18:33 +0100 Subject: [PATCH] Fix service settings when installing from archive --- spec/classes/config_spec.rb | 13 +++++++++++++ spec/classes/service_spec.rb | 24 ++++++++++++++++++++++++ templates/conf/environment.erb | 2 ++ templates/zookeeper.service.erb | 7 ++++++- 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index b8175bf..bab3972 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -62,6 +62,7 @@ it do is_expected.to contain_file('/etc/zookeeper/conf/environment').with_content(/ERROR/) + is_expected.to contain_file('/etc/zookeeper/conf/environment').with_content(/CLASSPATH/) end it do @@ -84,6 +85,18 @@ end end + context 'install from archive' do + let :pre_condition do + 'class {"zookeeper": + install_method: "archive", + archive_version: "3.4.9", + }' + + it {is_expected.to contain_file('/etc/zookeeper/conf/environment').without_content(/CLASSPATH/)} + + end + end + context 'extra environment_file parameter' do # set custom params let :pre_condition do diff --git a/spec/classes/service_spec.rb b/spec/classes/service_spec.rb index 65b52a5..7698762 100644 --- a/spec/classes/service_spec.rb +++ b/spec/classes/service_spec.rb @@ -60,6 +60,12 @@ }) end + it do + should contain_file( + '/usr/lib/systemd/system/zookeeper-server.service' + ).with_content(/zookeeper\.jar/) + end + it do should contain_service('zookeeper-server').with( :ensure => 'running', @@ -92,6 +98,24 @@ end end + context 'install from archive' do + let :pre_condition do + 'class {"zookeeper": + manage_service_file => true, + service_provider => "systemd", + install_method => "archive", + archive_version => "3.4.9" + }' + end + + it do + should contain_file( + '/usr/lib/systemd/system/zookeeper-server.service' + ).with_content(/zookeeper-3\.4\.9\.jar/) + end + + end + context 'do not manage systemd' do let :pre_condition do 'class {"zookeeper": diff --git a/templates/conf/environment.erb b/templates/conf/environment.erb index 6983a8a..2f968a6 100644 --- a/templates/conf/environment.erb +++ b/templates/conf/environment.erb @@ -1,10 +1,12 @@ NAME=zookeeper ZOOCFGDIR=<%= scope.lookupvar("zookeeper::cfg_dir") %> +<% if scope.lookupvar('zookeeper::install_method') != 'archive' -%> # TODO this is really ugly # How to find out, which jars are needed? # seems, that log4j requires the log4j.properties file to be in the classpath CLASSPATH="$ZOOCFGDIR:/usr/share/java/jline.jar:/usr/share/java/log4j-1.2.jar:/usr/share/java/xercesImpl.jar:/usr/share/java/xmlParserAPIs.jar:/usr/share/java/netty.jar:/usr/share/java/slf4j-api.jar:/usr/share/java/slf4j-log4j12.jar:/usr/share/java/zookeeper.jar" +<% end -%> #ZOOCFG="zoo.cfg" # necessary on Debian diff --git a/templates/zookeeper.service.erb b/templates/zookeeper.service.erb index 1ef35c3..6a30a04 100644 --- a/templates/zookeeper.service.erb +++ b/templates/zookeeper.service.erb @@ -11,7 +11,12 @@ After=<%= scope.lookupvar("zookeeper::systemd_unit_after") %> <% end -%> [Service] -ExecStart=/bin/sh -c 'set -x; . <%= scope.lookupvar("zookeeper::cfg_dir") %>/<%= scope.lookupvar("zookeeper::environment_file") %>; CLASSPATH="<%= @_zoo_dir %>/zookeeper.jar:<%= @_zoo_dir %>/lib/*:$CLASSPATH"; CLASSPATH="$(. <%= scope.lookupvar("zookeeper::service::_zoo_dir") %>/bin/zkEnv.sh ; echo $CLASSPATH)"; mkdir -p <%= scope.lookupvar("zookeeper::log_dir") %>; $JAVA "-Dzookeeper.log.dir=<%= scope.lookupvar("zookeeper::log_dir") %>" "-Dzookeeper.root.logger=$ZOO_LOG4J_PROP" -cp "$CLASSPATH" $JAVA_OPTS "$ZOOMAIN" "$ZOOCFG"' +ExecStart=/bin/sh -c 'set -x; \ + . <%= scope.lookupvar("zookeeper::cfg_dir") %>/<%= scope.lookupvar("zookeeper::environment_file") %>; \ + CLASSPATH="<%= @_zoo_dir %>/zookeeper<% if scope.lookupvar('zookeeper::install_method') == 'archive' -%>-<%= scope.lookupvar("zookeeper::archive_version") %><% end -%>.jar:<%= @_zoo_dir %>/lib/*:$CLASSPATH"; \ + CLASSPATH="$(. <%= scope.lookupvar("zookeeper::service::_zoo_dir") %>/bin/zkEnv.sh ; echo $CLASSPATH)"; \ + mkdir -p <%= scope.lookupvar("zookeeper::log_dir") %>; \ + $JAVA "-Dzookeeper.log.dir=<%= scope.lookupvar("zookeeper::log_dir") %>" "-Dzookeeper.root.logger=$ZOO_LOG4J_PROP" -cp "$CLASSPATH" $JAVA_OPTS "$ZOOMAIN" "$ZOOCFG"' Restart=always RemainAfterExit=no SyslogIdentifier=zookeeper