From 3aa8740da5182f4a29761e0ea350048764bc0752 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Tue, 1 Nov 2016 15:42:48 +0800 Subject: [PATCH] Change how attributes and resource parameters work - Node attributes and the `elasticsearch::default` recipe: 1. We're now using `node['elasticsearch'][][]` and we automatically post any of those values to the corresponding resource in `elasticsearch::default`. For example, if you set `node['elasticsearch']['user']['shell']='/bin/sh'`, we will automatically call `elasticsearch_user_resource.shell '/bin/sh'`. This allows people to set as much as they want in the node attributes and still use the ::default recipe, and we'll pass it to the appropriate places. 2. We now use strings for the type of install (e.g. 'package' or 'tarball', not :package or :tarball). Also, 'tar' has been dropped as a supported value. - Installing elasticsearch 1. We now install the tarball and package files into the same locations. There's no more `/usr/local`; it's all in one place. This allows us to drop a huge part of the default values for non-package installs. You may still override the values to be `/usr/local`, we just don't give you the defaults for it. 2. We dropped the fancy logic for figuring out the requested version of Elasticsearch to be installed. You should pass it on the resource or in the recipe, but we no longer do a bunch of logic to figure out what you meant -- we favor being explicit now. 3. We delete the sample configs directory when doing a tarball installation. It was overriding the stuff in /etc and /lib. - Configuring elasticsearch 1. We've dropped the `gc_options` parameter of elasticsearch_configure, and now have `jvm.options`. We've also dropped thread_stack_size and env_options, as they aren't used in the upstream packaging as defaults anymore. We added `max_map_count` since that was added in the packaging as well. 2. Systemd support required we create `/usr/lib/systemd/system` if it didn't exist, but `/usr/lib/systemd` did exist. - Running elasticsearch 1. We now start the service by default, instead of only `:enable` but not `:start`. 2. The systemd packaging scripts don't allow the override of ES_USER or ES_GROUP env vars to take effect. We've filed an upstream bug about this. - Cookbook testing 1. Due to the new attribute handling in the recipe, we're using `::default` a lot more in our tests. Fixes #497. Fixes #512. --- .kitchen.yml | 6 +- README.md | 26 ++++---- attributes/default.rb | 14 +++-- libraries/helpers.rb | 42 +++---------- libraries/provider_configure.rb | 34 +++++------ libraries/provider_install.rb | 37 +++++------ libraries/provider_plugin.rb | 18 +++--- libraries/provider_service.rb | 21 ++++++- libraries/resource_configure.rb | 46 ++++---------- libraries/resource_install.rb | 20 +++--- libraries/resource_service.rb | 2 +- recipes/default.rb | 37 +++++++++-- templates/amazon/initscript.erb | 2 +- templates/centos/initscript.erb | 2 +- templates/centos/systemd_unit.erb | 61 ------------------- templates/debian/initscript.erb | 2 +- templates/debian/systemd_unit.erb | 61 ------------------- .../{amazon => default}/systemd_unit.erb | 2 +- templates/oracle/initscript.erb | 2 +- templates/oracle/systemd_unit.erb | 61 ------------------- templates/redhat/initscript.erb | 2 +- templates/redhat/systemd_unit.erb | 61 ------------------- templates/ubuntu/initscript.erb | 2 +- templates/ubuntu/systemd_unit.erb | 61 ------------------- .../recipes/default_with_plugins.rb | 12 +--- .../recipes/doubleinstances.rb | 16 ++--- .../elasticsearch_test/recipes/package.rb | 12 ++-- .../elasticsearch_test/recipes/tarball.rb | 24 ++++---- .../helpers/serverspec/configure_examples.rb | 10 ++- .../helpers/serverspec/install_examples.rb | 4 +- .../helpers/serverspec/plugin_examples.rb | 2 +- .../serverspec/default_spec.rb | 8 +-- 32 files changed, 198 insertions(+), 512 deletions(-) delete mode 100644 templates/centos/systemd_unit.erb delete mode 100644 templates/debian/systemd_unit.erb rename templates/{amazon => default}/systemd_unit.erb (97%) delete mode 100644 templates/oracle/systemd_unit.erb delete mode 100644 templates/redhat/systemd_unit.erb delete mode 100644 templates/ubuntu/systemd_unit.erb diff --git a/.kitchen.yml b/.kitchen.yml index 312b48b75..666d94896 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -52,7 +52,8 @@ suites: - recipe[elasticsearch_test::default_with_plugins] attributes: elasticsearch: - install_type: package + install: + type: package - name: tarball # install by tarball require_chef_omnibus: 12.15.19 @@ -61,7 +62,8 @@ suites: - recipe[elasticsearch_test::default_with_plugins] attributes: elasticsearch: - install_type: tarball + install: + type: tarball - name: override_package # the override-everything use case driver_config: diff --git a/README.md b/README.md index b72977c7a..321ea1094 100644 --- a/README.md +++ b/README.md @@ -25,16 +25,16 @@ the version parameter as a string into your download_url. |Name|Default|Other values| |----|-------|------------| |`default['elasticsearch']['version']`|`'5.0.0'`|[See list](attributes/default.rb).| -|`default['elasticsearch']['install_type']`|`:package`|`:tarball`| +TODO: |`default['elasticsearch']['install_type']`|`:package`|`:tarball`| |`default['elasticsearch']['download_urls']['debian']`|[See values](attributes/default.rb).|`%s` will be replaced with the version attribute above| |`default['elasticsearch']['download_urls']['rhel']`|[See values](attributes/default.rb).|`%s` will be replaced with the version attribute above| -|`default['elasticsearch']['download_urls']['tar']`|[See values](attributes/default.rb).|`%s` will be replaced with the version attribute above| +|`default['elasticsearch']['download_urls']['tarball']`|[See values](attributes/default.rb).|`%s` will be replaced with the version attribute above| ## Recipes Resources are the intended way to consume this cookbook, however we have provided a single recipe that configures Elasticsearch by downloading an archive -containing a distribution of Elasticsearch, and extracting that into /usr/local. +containing a distribution of Elasticsearch, and extracting that into `/usr/share`. See the attributes section above to for what defaults you can adjust. @@ -220,28 +220,26 @@ Very complicated - ```ruby elasticsearch_configure 'my_elasticsearch' do # if you override one of these, you probably want to override all - path_home tarball: "/opt/elasticsearch" - path_conf tarball: "/etc/opt/elasticsearch" - path_data tarball: "/var/opt/elasticsearch" - path_logs tarball: "/var/log/elasticsearch" - path_pid tarball: "/var/run/elasticsearch" - path_plugins tarball: "/opt/elasticsearch/plugins" - path_bin tarball: "/opt/elasticsearch/bin" + path_home "/opt/elasticsearch" + path_conf "/etc/opt/elasticsearch" + path_data "/var/opt/elasticsearch" + path_logs "/var/log/elasticsearch" + path_pid "/var/run/elasticsearch" + path_plugins "/opt/elasticsearch/plugins" + path_bin "/opt/elasticsearch/bin" logging({:"action" => 'INFO'}) allocated_memory '123m' - thread_stack_size '512k' - env_options '-DFOO=BAR' - gc_settings <<-CONFIG + jvm_options %w( -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDetails - CONFIG + ) configuration ({ 'node.name' => 'crazy' diff --git a/attributes/default.rb b/attributes/default.rb index d8fa0c7a2..222291032 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1,15 +1,19 @@ -# elasticsearch version & install type -default['elasticsearch']['version'] = '5.0.0' -default['elasticsearch']['install_type'] = :package +# empty settings (populate these for the elasticsearch::default recipe) +# see the resources or README.md to see what you can pass here. +default['elasticsearch']['user'] = {} +default['elasticsearch']['install'] = {} +default['elasticsearch']['configure'] = {} +default['elasticsearch']['service'] = {} +default['elasticsearch']['plugin'] = {} # platform_family keyed download URLs default['elasticsearch']['download_urls'] = { 'debian' => 'https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-%s.deb', 'rhel' => 'https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-%s.rpm', - 'tar' => 'https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-%s.tar.gz' + 'tarball' => 'https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-%s.tar.gz' } # platform_family keyed download sha256 checksums default['elasticsearch']['checksums']['5.0.0']['debian'] = '0a4f8842a1f7d7bd3015118298284383efcd4c25f9591c46bb5ab68189815268' default['elasticsearch']['checksums']['5.0.0']['rhel'] = 'fb502a9754f2162f27590125aecc6b68fa999738051d8f230c4da4ed6deb8d62' -default['elasticsearch']['checksums']['5.0.0']['tar'] = 'a866534f0fa7428e980c985d712024feef1dee04709add6e360fc7b73bb1e7ae' +default['elasticsearch']['checksums']['5.0.0']['tarball'] = 'a866534f0fa7428e980c985d712024feef1dee04709add6e360fc7b73bb1e7ae' diff --git a/libraries/helpers.rb b/libraries/helpers.rb index 4f2f8cbc1..b4b14d79a 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -61,42 +61,20 @@ def find_instance_name_resource(run_context, resource_type, instance_name) nil # falsey end - def determine_version(new_resource, node) - if new_resource.version - new_resource.version.to_s - elsif node['elasticsearch'] && node['elasticsearch']['version'] - node['elasticsearch']['version'].to_s - else - raise 'could not determine version of elasticsearch to install' - end - end - - def determine_install_type(new_resource, node) - if new_resource.type - new_resource.type.to_s - elsif node['elasticsearch'] && node['elasticsearch']['install_type'] - node['elasticsearch']['install_type'].to_s - else - raise 'could not determine how to install elasticsearch (package? tarball?)' - end - end - def determine_download_url(new_resource, node) platform_family = node['platform_family'] - install_type = determine_install_type(new_resource, node) - version = determine_version(new_resource, node) url_string = nil if new_resource.download_url url_string = new_resource.download_url - elsif install_type.to_s == 'tar' || install_type.to_s == 'tarball' - url_string = node['elasticsearch']['download_urls']['tar'] - elsif install_type.to_s == 'package' && node['elasticsearch']['download_urls'][platform_family] + elsif new_resource.type == 'tarball' + url_string = node['elasticsearch']['download_urls']['tarball'] + elsif new_resource.type == 'package' && node['elasticsearch']['download_urls'][platform_family] url_string = node['elasticsearch']['download_urls'][platform_family] end - if url_string && version - return format(url_string, version) + if url_string && new_resource.version + return format(url_string, new_resource.version) elsif url_string return url_string end @@ -104,18 +82,18 @@ def determine_download_url(new_resource, node) def determine_download_checksum(new_resource, node) platform_family = node['platform_family'] - install_type = determine_install_type(new_resource, node) - version = determine_version(new_resource, node) + install_type = new_resource.type + version = new_resource.version if new_resource.download_checksum new_resource.download_checksum - elsif install_type.to_s == 'tar' || install_type.to_s == 'tarball' + elsif install_type == 'tarball' node && version && node['elasticsearch'] && node['elasticsearch']['checksums'] && node['elasticsearch']['checksums'][version] && - node['elasticsearch']['checksums'][version]['tar'] - elsif install_type.to_s == 'package' && node['elasticsearch']['checksums'][version] && node['elasticsearch']['checksums'][version][platform_family] + node['elasticsearch']['checksums'][version]['tarball'] + elsif install_type == 'package' && node['elasticsearch']['checksums'][version] && node['elasticsearch']['checksums'][version][platform_family] node && version && platform_family && node['elasticsearch'] && node['elasticsearch']['checksums'] && diff --git a/libraries/provider_configure.rb b/libraries/provider_configure.rb index c8373e578..03deae479 100644 --- a/libraries/provider_configure.rb +++ b/libraries/provider_configure.rb @@ -17,16 +17,16 @@ def whyrun_supported? default_configuration = new_resource.default_configuration.dup # if a subdir parameter is missing but dir is set, infer the subdir name # then go and be sure it's also set in the YML hash if it wasn't given there - if new_resource.path_conf[es_install.type] && default_configuration['path.conf'].nil? - default_configuration['path.conf'] = new_resource.path_conf[es_install.type] + if new_resource.path_conf && default_configuration['path.conf'].nil? + default_configuration['path.conf'] = new_resource.path_conf end - if new_resource.path_data[es_install.type] && default_configuration['path.data'].nil? - default_configuration['path.data'] = new_resource.path_data[es_install.type] + if new_resource.path_data && default_configuration['path.data'].nil? + default_configuration['path.data'] = new_resource.path_data end - if new_resource.path_logs[es_install.type] && default_configuration['path.logs'].nil? - default_configuration['path.logs'] = new_resource.path_logs[es_install.type] + if new_resource.path_logs && default_configuration['path.logs'].nil? + default_configuration['path.logs'] = new_resource.path_logs end # calculation for memory allocation; 50% or 31g, whatever is smaller @@ -38,7 +38,7 @@ def whyrun_supported? # Create ES directories # - [new_resource.path_conf[es_install.type], "#{new_resource.path_conf[es_install.type]}/scripts", new_resource.path_logs[es_install.type]].each do |path| + [new_resource.path_conf, "#{new_resource.path_conf}/scripts", new_resource.path_logs].each do |path| d = directory path do owner es_user.username group es_user.groupname @@ -52,7 +52,7 @@ def whyrun_supported? # Create data path directories # - data_paths = new_resource.path_data[es_install.type].is_a?(Array) ? new_resource.path_data[es_install.type] : new_resource.path_data[es_install.type].split(',') + data_paths = new_resource.path_data.is_a?(Array) ? new_resource.path_data : new_resource.path_data.split(',') data_paths.each do |path| d = directory path.strip do @@ -76,19 +76,19 @@ def whyrun_supported? # We provide these values as resource attributes/parameters directly params = {} - params[:ES_HOME] = new_resource.path_home[es_install.type] + params[:ES_HOME] = new_resource.path_home params[:JAVA_HOME] = new_resource.java_home - params[:CONF_DIR] = new_resource.path_conf[es_install.type] - params[:DATA_DIR] = new_resource.path_data[es_install.type] - params[:LOG_DIR] = new_resource.path_logs[es_install.type] - params[:PID_DIR] = new_resource.path_pid[es_install.type] + params[:CONF_DIR] = new_resource.path_conf + params[:DATA_DIR] = new_resource.path_data + params[:LOG_DIR] = new_resource.path_logs + params[:PID_DIR] = new_resource.path_pid params[:RESTART_ON_UPGRADE] = new_resource.restart_on_upgrade params[:ES_USER] = es_user.username params[:ES_GROUP] = es_user.groupname params[:ES_STARTUP_SLEEP_TIME] = new_resource.startup_sleep_seconds.to_s params[:MAX_OPEN_FILES] = new_resource.nofile_limit params[:MAX_LOCKED_MEMORY] = new_resource.memlock_limit - params[:MAX_MAP_COUNT] = new_resource.memlock_limit + params[:MAX_MAP_COUNT] = new_resource.max_map_count default_config_name = es_svc.service_name || es_svc.instance_name || new_resource.instance_name || 'elasticsearch' @@ -106,7 +106,7 @@ def whyrun_supported? # Create jvm.options file # jvm_options_template = template 'jvm_options' do - path "#{new_resource.path_conf[es_install.type]}/jvm.options" + path "#{new_resource.path_conf}/jvm.options" source new_resource.template_jvm_options cookbook new_resource.cookbook_jvm_options owner es_user.username @@ -125,7 +125,7 @@ def whyrun_supported? # Create ES logging file # logging_template = template 'log4j2_properties' do - path "#{new_resource.path_conf[es_install.type]}/log4j2.properties" + path "#{new_resource.path_conf}/log4j2.properties" source new_resource.template_log4j2_properties cookbook new_resource.cookbook_log4j2_properties owner es_user.username @@ -148,7 +148,7 @@ def whyrun_supported? end yml_template = template 'elasticsearch.yml' do - path "#{new_resource.path_conf[es_install.type]}/elasticsearch.yml" + path "#{new_resource.path_conf}/elasticsearch.yml" source new_resource.template_elasticsearch_yml cookbook new_resource.cookbook_elasticsearch_yml owner es_user.username diff --git a/libraries/provider_install.rb b/libraries/provider_install.rb index b91a3f34c..aef86e155 100644 --- a/libraries/provider_install.rb +++ b/libraries/provider_install.rb @@ -11,14 +11,9 @@ def whyrun_supported? end action :install do - install_type = determine_install_type(new_resource, node) - unless new_resource.version - new_resource.version determine_version(new_resource, node) - end - - if install_type == 'tarball' || install_type == 'tar' + if new_resource.type == 'tarball' install_tarball_wrapper_action - elsif install_type == 'package' + elsif new_resource.type == 'package' install_package_wrapper_action else raise "#{install_type} is not a valid install type" @@ -26,11 +21,9 @@ def whyrun_supported? end action :remove do - install_type = determine_install_type(new_resource, node) - - if install_type == 'tarball' || install_type == 'tar' + if new_resource.type == 'tarball' remove_tarball_wrapper_action - elsif install_type == 'package' + elsif new_resource.type == 'package' remove_package_wrapper_action else raise "#{install_type} is not a valid install type" @@ -101,15 +94,15 @@ def install_tarball_wrapper_action url determine_download_url(new_resource, node) owner es_user.username group es_user.groupname - version determine_version(new_resource, node) + version new_resource.version has_binaries ['bin/elasticsearch', 'bin/elasticsearch-plugin'] checksum determine_download_checksum(new_resource, node) - prefix_root new_resource.dir[new_resource.type] - prefix_home new_resource.dir[new_resource.type] + prefix_root new_resource.dir + prefix_home new_resource.dir not_if do link = "#{new_resource.dir}/elasticsearch" - target = "#{new_resource.dir}/elasticsearch-#{determine_version(new_resource, node)}" + target = "#{new_resource.dir}/elasticsearch-#{new_resource.version}" binary = "#{target}/bin/elasticsearch" ::File.directory?(link) && ::File.symlink?(link) && ::File.readlink(link) == target && ::File.exist?(binary) @@ -118,6 +111,16 @@ def install_tarball_wrapper_action end ark_r.run_action(:install) new_resource.updated_by_last_action(true) if ark_r.updated_by_last_action? + + # destroy the sample config directory for tarball installs, or it will + # take precedence beyond the default stuff in /etc/elasticsearch and within + # /etc/sysconfig or /etc/default + sample_r = directory "#{new_resource.dir}/elasticsearch/config" do + action :nothing + recursive true + end + sample_r.run_action(:delete) + new_resource.updated_by_last_action(true) if sample_r.updated_by_last_action? end def remove_tarball_wrapper_action @@ -125,7 +128,7 @@ def remove_tarball_wrapper_action link_r = link "#{new_resource.dir}/elasticsearch" do only_if do link = "#{new_resource.dir}/elasticsearch" - target = "#{new_resource.dir}/elasticsearch-#{determine_version(new_resource, node)}" + target = "#{new_resource.dir}/elasticsearch-#{new_resource.version}" ::File.directory?(link) && ::File.symlink?(link) && ::File.readlink(link) == target end @@ -135,7 +138,7 @@ def remove_tarball_wrapper_action new_resource.updated_by_last_action(true) if link_r.updated_by_last_action? # remove the specific version - d_r = directory "#{new_resource.dir}/elasticsearch-#{determine_version(new_resource, node)}" do + d_r = directory "#{new_resource.dir}/elasticsearch-#{new_resource.version}" do action :nothing end d_r.run_action(:delete) diff --git a/libraries/provider_plugin.rb b/libraries/provider_plugin.rb index 981d8dae4..a0c46f689 100644 --- a/libraries/provider_plugin.rb +++ b/libraries/provider_plugin.rb @@ -32,10 +32,10 @@ def manage_plugin(arguments) # shell_out! automatically raises on error, logs command output # required for package installs that show up with parent dir owned by root - plugin_dir_exists = ::File.exist?(es_conf.path_plugins[es_install.type]) - shell_out_as_user!("mkdir -p #{es_conf.path_plugins[es_install.type]}", run_context) unless plugin_dir_exists + plugin_dir_exists = ::File.exist?(es_conf.path_plugins) + shell_out_as_user!("mkdir -p #{es_conf.path_plugins}", run_context) unless plugin_dir_exists - command_array = "#{es_conf.path_bin[es_install.type]}/elasticsearch-plugin #{arguments.chomp(' ')} #{new_resource.options}".chomp(' ').split(' ') + command_array = "#{es_conf.path_bin}/elasticsearch-plugin #{arguments.chomp(' ')} #{new_resource.options}".chomp(' ').split(' ') shell_out_as_user!(command_array, run_context) new_resource.updated_by_last_action(true) end @@ -43,7 +43,7 @@ def manage_plugin(arguments) def plugin_exists(name) es_install = find_es_resource(run_context, :elasticsearch_install, new_resource) es_conf = find_es_resource(run_context, :elasticsearch_configure, new_resource) - path = es_conf.path_plugins[es_install.type] + path = es_conf.path_plugins Dir.entries(path).any? do |plugin| next if plugin =~ /^\./ @@ -54,12 +54,12 @@ def plugin_exists(name) end def assert_state_is_valid(es_user, es_install, es_conf) - unless es_conf.path_plugins[es_install.type] # we do not check existence (may not exist if no plugins installed) - raise "Could not determine the plugin directory (#{es_conf.path_plugins[es_install.type]}). Please check elasticsearch_configure[#{es_conf.name}]." + unless es_conf.path_plugins # we do not check existence (may not exist if no plugins installed) + raise "Could not determine the plugin directory (#{es_conf.path_plugins}). Please check elasticsearch_configure[#{es_conf.name}]." end - unless es_conf.path_bin[es_install.type] && ::File.exist?(es_conf.path_bin[es_install.type]) - raise "Could not determine the binary directory (#{es_conf.path_bin[es_install.type]}). Please check elasticsearch_configure[#{es_conf.name}]." + unless es_conf.path_bin && ::File.exist?(es_conf.path_bin) + raise "Could not determine the binary directory (#{es_conf.path_bin}). Please check elasticsearch_configure[#{es_conf.name}]." end true @@ -70,7 +70,7 @@ def shell_out_as_user!(command, run_ctx) # See this link for an explanation: # https://www.elastic.co/guide/en/elasticsearch/plugins/2.1/plugin-management.html - if es_install.type == :package + if es_install.type == 'package' # package installations should install plugins as root shell_out!(command) else diff --git a/libraries/provider_service.rb b/libraries/provider_service.rb index faa8b9260..cfcf410b1 100644 --- a/libraries/provider_service.rb +++ b/libraries/provider_service.rb @@ -16,7 +16,7 @@ def whyrun_supported? es_install = find_es_resource(run_context, :elasticsearch_install, new_resource) es_conf = find_es_resource(run_context, :elasticsearch_configure, new_resource) - d_r = directory es_conf.path_pid[es_install.type] do + d_r = directory es_conf.path_pid do owner es_user.username group es_user.groupname mode '0755' @@ -43,6 +43,13 @@ def whyrun_supported? init_r.run_action(:create) new_resource.updated_by_last_action(true) if init_r.updated_by_last_action? + systemd_parent_r = directory '/usr/lib/systemd/system' do + action :nothing + only_if { ::File.exist?('/usr/lib/systemd') } + end + systemd_parent_r.run_action(:create) + new_resource.updated_by_last_action(true) if systemd_parent_r.updated_by_last_action? + systemd_r = template "/usr/lib/systemd/system/#{new_resource.service_name}.service" do source new_resource.systemd_source cookbook new_resource.systemd_cookbook @@ -52,11 +59,19 @@ def whyrun_supported? # we need to include something about #{progname} fixed in here. program_name: new_resource.service_name ) - only_if { ::File.exist?('/usr/lib/systemd/system') } + only_if { ::File.exist?('/usr/lib/systemd') } action :nothing end systemd_r.run_action(:create) - new_resource.updated_by_last_action(true) if systemd_r.updated_by_last_action? + # special case here -- must reload unit files if we modified one + if systemd_r.updated_by_last_action? + new_resource.updated_by_last_action(true) + + reload_r = execute 'systemctl daemon-reload' do + action :nothing + end + reload_r.run_action(:run) + end # flatten in an array here, in case the service_actions are a symbol vs. array [new_resource.service_actions].flatten.each do |act| diff --git a/libraries/resource_configure.rb b/libraries/resource_configure.rb index dfdaf71cc..44071ef3d 100644 --- a/libraries/resource_configure.rb +++ b/libraries/resource_configure.rb @@ -10,34 +10,13 @@ class ElasticsearchCookbook::ConfigureResource < Chef::Resource::LWRPBase attribute(:instance_name, kind_of: String, default: nil) # if you override one of these, you should probably override them all - attribute(:path_home, kind_of: Hash, default: { - package: '/usr/share/elasticsearch', - tarball: '/usr/local/elasticsearch' - }.freeze) - attribute(:path_conf, kind_of: Hash, default: { - package: '/etc/elasticsearch', - tarball: '/usr/local/etc/elasticsearch' - }.freeze) - attribute(:path_data, kind_of: Hash, default: { - package: '/usr/share/elasticsearch', - tarball: '/usr/local/var/data/elasticsearch' - }.freeze) - attribute(:path_logs, kind_of: Hash, default: { - package: '/var/log/elasticsearch', - tarball: '/usr/local/var/log/elasticsearch' - }.freeze) - attribute(:path_pid, kind_of: Hash, default: { - package: '/var/run/elasticsearch', - tarball: '/usr/local/var/run' - }.freeze) - attribute(:path_plugins, kind_of: Hash, default: { - package: '/usr/share/elasticsearch/plugins', - tarball: '/usr/local/elasticsearch/plugins' - }.freeze) - attribute(:path_bin, kind_of: Hash, default: { - package: '/usr/share/elasticsearch/bin', - tarball: '/usr/local/bin' - }.freeze) + attribute(:path_home, kind_of: String, default: '/usr/share/elasticsearch') + attribute(:path_conf, kind_of: String, default: '/etc/elasticsearch') + attribute(:path_data, kind_of: String, default: '/var/lib/elasticsearch') + attribute(:path_logs, kind_of: String, default: '/var/log/elasticsearch') + attribute(:path_pid, kind_of: String, default: '/var/run/elasticsearch') + attribute(:path_plugins, kind_of: String, default: '/usr/share/elasticsearch/plugins') + attribute(:path_bin, kind_of: String, default: '/usr/share/elasticsearch/bin') attribute(:template_elasticsearch_env, kind_of: String, default: 'elasticsearch.in.sh.erb') attribute(:cookbook_elasticsearch_env, kind_of: String, default: 'elasticsearch') @@ -52,11 +31,14 @@ class ElasticsearchCookbook::ConfigureResource < Chef::Resource::LWRPBase attribute(:cookbook_log4j2_properties, kind_of: String, default: 'elasticsearch') attribute(:logging, kind_of: Hash, default: {}.freeze) - attribute(:java_home, kind_of: String, default: nil) - attribute(:restart_on_upgrade, kind_of: [TrueClass, FalseClass], default: false) + # other settings in /etc/default or /etc/sysconfig + attribute(:memlock_limit, kind_of: String, default: 'unlimited') + attribute(:max_map_count, kind_of: String, default: '65535') + attribute(:nofile_limit, kind_of: String, default: '64000') attribute(:startup_sleep_seconds, kind_of: [String, Integer], default: 5) + attribute(:restart_on_upgrade, kind_of: [TrueClass, FalseClass], default: false) # Calculations for this are done in the provider, as we can't do them in the # resource definition. default is 50% of RAM or 31GB, which ever is smaller. @@ -82,10 +64,6 @@ class ElasticsearchCookbook::ConfigureResource < Chef::Resource::LWRPBase ).freeze ) - # default user limits - attribute(:memlock_limit, kind_of: String, default: 'unlimited') - attribute(:nofile_limit, kind_of: String, default: '64000') - # These are the default settings. Most of the time, you want to override # the `configuration` attribute below. If you do override the defaults, you # must supply ALL needed defaults, and don't use nil as a value in the hash. diff --git a/libraries/resource_install.rb b/libraries/resource_install.rb index aa67d48d2..35d886f42 100644 --- a/libraries/resource_install.rb +++ b/libraries/resource_install.rb @@ -7,26 +7,22 @@ class ElasticsearchCookbook::InstallResource < Chef::Resource::LWRPBase default_action :install # this is what helps the various resources find each other - attribute(:instance_name, kind_of: String, default: nil) + attribute(:instance_name, kind_of: String) # if this version parameter is not set by the caller, we look at # `attributes/default.rb` for a default value to use, or we raise - attribute(:version, kind_of: String, default: nil) + attribute(:version, kind_of: String, default: '5.0.0') # we allow a string or symbol for this value - attribute(:type, kind_of: [Symbol], - equal_to: [:tarball, :package], default: :package) + attribute(:type, kind_of: String, equal_to: ['package', 'tarball'], default: 'package') # these use `attributes/default.rb` for default values per platform and install type - attribute(:download_url, kind_of: String, default: nil) - attribute(:download_checksum, kind_of: String, default: nil) # sha256 + attribute(:download_url, kind_of: String) + attribute(:download_checksum, kind_of: String) # sha256 - # these correspond to :type of install - attribute(:dir, kind_of: Hash, default: { - package: '/usr/share', - tarball: '/usr/local' - }.freeze) + # where to install? + attribute(:dir, kind_of: String, default: '/usr/share') # attributes used by the package-flavor provider - attribute(:package_options, kind_of: String, default: nil) + attribute(:package_options, kind_of: String) end diff --git a/libraries/resource_service.rb b/libraries/resource_service.rb index 71494add2..a73c52975 100644 --- a/libraries/resource_service.rb +++ b/libraries/resource_service.rb @@ -16,7 +16,7 @@ class ElasticsearchCookbook::ServiceResource < Chef::Resource::LWRPBase attribute(:args, kind_of: String, default: '-d') # service actions - attribute(:service_actions, kind_of: [Symbol, Array], default: [:enable].freeze) + attribute(:service_actions, kind_of: [Symbol, String, Array], default: [:enable, :start].freeze) # allow overridable init script attribute(:init_source, kind_of: String, default: 'initscript.erb') diff --git a/recipes/default.rb b/recipes/default.rb index 2c2cac4c3..efc7a1526 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -7,11 +7,40 @@ include_recipe 'chef-sugar' # see README.md and test/fixtures/cookbooks for more examples! -elasticsearch_user 'elasticsearch' +elasticsearch_user 'elasticsearch' do + node['elasticsearch']['user'].each do |key, value| + # Skip nils, use false if you want to disable something. + send(key, value) unless value.nil? + end +end + elasticsearch_install 'elasticsearch' do - type node['elasticsearch']['install_type'].to_sym # since TK can't symbol. + node['elasticsearch']['install'].each do |key, value| + # Skip nils, use false if you want to disable something. + send(key, value) unless value.nil? + end +end + +elasticsearch_configure 'elasticsearch' do + node['elasticsearch']['configure'].each do |key, value| + # Skip nils, use false if you want to disable something. + send(key, value) unless value.nil? + end +end + +elasticsearch_service 'elasticsearch' do + node['elasticsearch']['service'].each do |key, value| + # Skip nils, use false if you want to disable something. + send(key, value) unless value.nil? + end end -elasticsearch_configure 'elasticsearch' -elasticsearch_service 'elasticsearch' # by default, no plugins +node['elasticsearch']['plugin'].each do |plugin_name, plugin_value| + elasticsearch_plugin plugin_name do + plugin_value.each do |key, value| + # Skip nils, use false if you want to disable something. + send(key, value) unless value.nil? + end + end +end diff --git a/templates/amazon/initscript.erb b/templates/amazon/initscript.erb index b5f6f2ad1..e11e4147f 100644 --- a/templates/amazon/initscript.erb +++ b/templates/amazon/initscript.erb @@ -44,7 +44,7 @@ CONF_DIR="/etc/elasticsearch" PID_DIR="/var/run/elasticsearch" # Source the default env file -ES_ENV_FILE="/etc/sysconfig/elasticsearch" +ES_ENV_FILE="/etc/sysconfig/<%= @program_name %>" if [ -f "$ES_ENV_FILE" ]; then . "$ES_ENV_FILE" fi diff --git a/templates/centos/initscript.erb b/templates/centos/initscript.erb index b5f6f2ad1..e11e4147f 100755 --- a/templates/centos/initscript.erb +++ b/templates/centos/initscript.erb @@ -44,7 +44,7 @@ CONF_DIR="/etc/elasticsearch" PID_DIR="/var/run/elasticsearch" # Source the default env file -ES_ENV_FILE="/etc/sysconfig/elasticsearch" +ES_ENV_FILE="/etc/sysconfig/<%= @program_name %>" if [ -f "$ES_ENV_FILE" ]; then . "$ES_ENV_FILE" fi diff --git a/templates/centos/systemd_unit.erb b/templates/centos/systemd_unit.erb deleted file mode 100644 index 549520522..000000000 --- a/templates/centos/systemd_unit.erb +++ /dev/null @@ -1,61 +0,0 @@ -[Unit] -Description=Elasticsearch -Documentation=http://www.elastic.co -Wants=network-online.target -After=network-online.target - -[Service] -Environment=ES_HOME=/usr/share/elasticsearch -Environment=CONF_DIR=/etc/elasticsearch -Environment=DATA_DIR=/var/lib/elasticsearch -Environment=LOG_DIR=/var/log/elasticsearch -Environment=PID_DIR=/var/run/elasticsearch -EnvironmentFile=-/etc/sysconfig/elasticsearch - -WorkingDirectory=/usr/share/elasticsearch - -User=elasticsearch -Group=elasticsearch - -ExecStartPre=/usr/share/elasticsearch/bin/elasticsearch-systemd-pre-exec - -ExecStart=/usr/share/elasticsearch/bin/elasticsearch \ - -p ${PID_DIR}/elasticsearch.pid \ - --quiet \ - -Edefault.path.logs=${LOG_DIR} \ - -Edefault.path.data=${DATA_DIR} \ - -Edefault.path.conf=${CONF_DIR} - -# StandardOutput is configured to redirect to journalctl since -# some error messages may be logged in standard output before -# elasticsearch logging system is initialized. Elasticsearch -# stores its logs in /var/log/elasticsearch and does not use -# journalctl by default. If you also want to enable journalctl -# logging, you can simply remove the "quiet" option from ExecStart. -StandardOutput=journal -StandardError=inherit - -# Specifies the maximum file descriptor number that can be opened by this process -LimitNOFILE=65536 - -# Specifies the maximum number of bytes of memory that may be locked into RAM -# Set to "infinity" if you use the 'bootstrap.memory_lock: true' option -# in elasticsearch.yml and 'MAX_LOCKED_MEMORY=unlimited' in /etc/sysconfig/elasticsearch -#LimitMEMLOCK=infinity - -# Disable timeout logic and wait until process is stopped -TimeoutStopSec=0 - -# SIGTERM signal is used to stop the Java process -KillSignal=SIGTERM - -# Java process is never killed -SendSIGKILL=no - -# When a JVM receives a SIGTERM signal it exits with code 143 -SuccessExitStatus=143 - -[Install] -WantedBy=multi-user.target - -# Built for distribution-5.0.0 (distribution) diff --git a/templates/debian/initscript.erb b/templates/debian/initscript.erb index f04008ba7..2c8769e77 100644 --- a/templates/debian/initscript.erb +++ b/templates/debian/initscript.erb @@ -13,7 +13,7 @@ ### END INIT INFO PATH=/bin:/usr/bin:/sbin:/usr/sbin -NAME=elasticsearch +NAME=<%= @program_name %> DESC="Elasticsearch Server" DEFAULT=/etc/default/$NAME diff --git a/templates/debian/systemd_unit.erb b/templates/debian/systemd_unit.erb deleted file mode 100644 index a1ae52f50..000000000 --- a/templates/debian/systemd_unit.erb +++ /dev/null @@ -1,61 +0,0 @@ -[Unit] -Description=Elasticsearch -Documentation=http://www.elastic.co -Wants=network-online.target -After=network-online.target - -[Service] -Environment=ES_HOME=/usr/share/elasticsearch -Environment=CONF_DIR=/etc/elasticsearch -Environment=DATA_DIR=/var/lib/elasticsearch -Environment=LOG_DIR=/var/log/elasticsearch -Environment=PID_DIR=/var/run/elasticsearch -EnvironmentFile=-/etc/default/elasticsearch - -WorkingDirectory=/usr/share/elasticsearch - -User=elasticsearch -Group=elasticsearch - -ExecStartPre=/usr/share/elasticsearch/bin/elasticsearch-systemd-pre-exec - -ExecStart=/usr/share/elasticsearch/bin/elasticsearch \ - -p ${PID_DIR}/elasticsearch.pid \ - --quiet \ - -Edefault.path.logs=${LOG_DIR} \ - -Edefault.path.data=${DATA_DIR} \ - -Edefault.path.conf=${CONF_DIR} - -# StandardOutput is configured to redirect to journalctl since -# some error messages may be logged in standard output before -# elasticsearch logging system is initialized. Elasticsearch -# stores its logs in /var/log/elasticsearch and does not use -# journalctl by default. If you also want to enable journalctl -# logging, you can simply remove the "quiet" option from ExecStart. -StandardOutput=journal -StandardError=inherit - -# Specifies the maximum file descriptor number that can be opened by this process -LimitNOFILE=65536 - -# Specifies the maximum number of bytes of memory that may be locked into RAM -# Set to "infinity" if you use the 'bootstrap.memory_lock: true' option -# in elasticsearch.yml and 'MAX_LOCKED_MEMORY=unlimited' in /etc/default/elasticsearch -#LimitMEMLOCK=infinity - -# Disable timeout logic and wait until process is stopped -TimeoutStopSec=0 - -# SIGTERM signal is used to stop the Java process -KillSignal=SIGTERM - -# Java process is never killed -SendSIGKILL=no - -# When a JVM receives a SIGTERM signal it exits with code 143 -SuccessExitStatus=143 - -[Install] -WantedBy=multi-user.target - -# Built for distribution-5.0.0 (distribution) diff --git a/templates/amazon/systemd_unit.erb b/templates/default/systemd_unit.erb similarity index 97% rename from templates/amazon/systemd_unit.erb rename to templates/default/systemd_unit.erb index 549520522..5258390e9 100644 --- a/templates/amazon/systemd_unit.erb +++ b/templates/default/systemd_unit.erb @@ -10,7 +10,7 @@ Environment=CONF_DIR=/etc/elasticsearch Environment=DATA_DIR=/var/lib/elasticsearch Environment=LOG_DIR=/var/log/elasticsearch Environment=PID_DIR=/var/run/elasticsearch -EnvironmentFile=-/etc/sysconfig/elasticsearch +EnvironmentFile=-/etc/sysconfig/<%= @program_name %> WorkingDirectory=/usr/share/elasticsearch diff --git a/templates/oracle/initscript.erb b/templates/oracle/initscript.erb index b5f6f2ad1..e11e4147f 100755 --- a/templates/oracle/initscript.erb +++ b/templates/oracle/initscript.erb @@ -44,7 +44,7 @@ CONF_DIR="/etc/elasticsearch" PID_DIR="/var/run/elasticsearch" # Source the default env file -ES_ENV_FILE="/etc/sysconfig/elasticsearch" +ES_ENV_FILE="/etc/sysconfig/<%= @program_name %>" if [ -f "$ES_ENV_FILE" ]; then . "$ES_ENV_FILE" fi diff --git a/templates/oracle/systemd_unit.erb b/templates/oracle/systemd_unit.erb deleted file mode 100644 index 549520522..000000000 --- a/templates/oracle/systemd_unit.erb +++ /dev/null @@ -1,61 +0,0 @@ -[Unit] -Description=Elasticsearch -Documentation=http://www.elastic.co -Wants=network-online.target -After=network-online.target - -[Service] -Environment=ES_HOME=/usr/share/elasticsearch -Environment=CONF_DIR=/etc/elasticsearch -Environment=DATA_DIR=/var/lib/elasticsearch -Environment=LOG_DIR=/var/log/elasticsearch -Environment=PID_DIR=/var/run/elasticsearch -EnvironmentFile=-/etc/sysconfig/elasticsearch - -WorkingDirectory=/usr/share/elasticsearch - -User=elasticsearch -Group=elasticsearch - -ExecStartPre=/usr/share/elasticsearch/bin/elasticsearch-systemd-pre-exec - -ExecStart=/usr/share/elasticsearch/bin/elasticsearch \ - -p ${PID_DIR}/elasticsearch.pid \ - --quiet \ - -Edefault.path.logs=${LOG_DIR} \ - -Edefault.path.data=${DATA_DIR} \ - -Edefault.path.conf=${CONF_DIR} - -# StandardOutput is configured to redirect to journalctl since -# some error messages may be logged in standard output before -# elasticsearch logging system is initialized. Elasticsearch -# stores its logs in /var/log/elasticsearch and does not use -# journalctl by default. If you also want to enable journalctl -# logging, you can simply remove the "quiet" option from ExecStart. -StandardOutput=journal -StandardError=inherit - -# Specifies the maximum file descriptor number that can be opened by this process -LimitNOFILE=65536 - -# Specifies the maximum number of bytes of memory that may be locked into RAM -# Set to "infinity" if you use the 'bootstrap.memory_lock: true' option -# in elasticsearch.yml and 'MAX_LOCKED_MEMORY=unlimited' in /etc/sysconfig/elasticsearch -#LimitMEMLOCK=infinity - -# Disable timeout logic and wait until process is stopped -TimeoutStopSec=0 - -# SIGTERM signal is used to stop the Java process -KillSignal=SIGTERM - -# Java process is never killed -SendSIGKILL=no - -# When a JVM receives a SIGTERM signal it exits with code 143 -SuccessExitStatus=143 - -[Install] -WantedBy=multi-user.target - -# Built for distribution-5.0.0 (distribution) diff --git a/templates/redhat/initscript.erb b/templates/redhat/initscript.erb index b5f6f2ad1..e11e4147f 100644 --- a/templates/redhat/initscript.erb +++ b/templates/redhat/initscript.erb @@ -44,7 +44,7 @@ CONF_DIR="/etc/elasticsearch" PID_DIR="/var/run/elasticsearch" # Source the default env file -ES_ENV_FILE="/etc/sysconfig/elasticsearch" +ES_ENV_FILE="/etc/sysconfig/<%= @program_name %>" if [ -f "$ES_ENV_FILE" ]; then . "$ES_ENV_FILE" fi diff --git a/templates/redhat/systemd_unit.erb b/templates/redhat/systemd_unit.erb deleted file mode 100644 index 549520522..000000000 --- a/templates/redhat/systemd_unit.erb +++ /dev/null @@ -1,61 +0,0 @@ -[Unit] -Description=Elasticsearch -Documentation=http://www.elastic.co -Wants=network-online.target -After=network-online.target - -[Service] -Environment=ES_HOME=/usr/share/elasticsearch -Environment=CONF_DIR=/etc/elasticsearch -Environment=DATA_DIR=/var/lib/elasticsearch -Environment=LOG_DIR=/var/log/elasticsearch -Environment=PID_DIR=/var/run/elasticsearch -EnvironmentFile=-/etc/sysconfig/elasticsearch - -WorkingDirectory=/usr/share/elasticsearch - -User=elasticsearch -Group=elasticsearch - -ExecStartPre=/usr/share/elasticsearch/bin/elasticsearch-systemd-pre-exec - -ExecStart=/usr/share/elasticsearch/bin/elasticsearch \ - -p ${PID_DIR}/elasticsearch.pid \ - --quiet \ - -Edefault.path.logs=${LOG_DIR} \ - -Edefault.path.data=${DATA_DIR} \ - -Edefault.path.conf=${CONF_DIR} - -# StandardOutput is configured to redirect to journalctl since -# some error messages may be logged in standard output before -# elasticsearch logging system is initialized. Elasticsearch -# stores its logs in /var/log/elasticsearch and does not use -# journalctl by default. If you also want to enable journalctl -# logging, you can simply remove the "quiet" option from ExecStart. -StandardOutput=journal -StandardError=inherit - -# Specifies the maximum file descriptor number that can be opened by this process -LimitNOFILE=65536 - -# Specifies the maximum number of bytes of memory that may be locked into RAM -# Set to "infinity" if you use the 'bootstrap.memory_lock: true' option -# in elasticsearch.yml and 'MAX_LOCKED_MEMORY=unlimited' in /etc/sysconfig/elasticsearch -#LimitMEMLOCK=infinity - -# Disable timeout logic and wait until process is stopped -TimeoutStopSec=0 - -# SIGTERM signal is used to stop the Java process -KillSignal=SIGTERM - -# Java process is never killed -SendSIGKILL=no - -# When a JVM receives a SIGTERM signal it exits with code 143 -SuccessExitStatus=143 - -[Install] -WantedBy=multi-user.target - -# Built for distribution-5.0.0 (distribution) diff --git a/templates/ubuntu/initscript.erb b/templates/ubuntu/initscript.erb index f04008ba7..2c8769e77 100755 --- a/templates/ubuntu/initscript.erb +++ b/templates/ubuntu/initscript.erb @@ -13,7 +13,7 @@ ### END INIT INFO PATH=/bin:/usr/bin:/sbin:/usr/sbin -NAME=elasticsearch +NAME=<%= @program_name %> DESC="Elasticsearch Server" DEFAULT=/etc/default/$NAME diff --git a/templates/ubuntu/systemd_unit.erb b/templates/ubuntu/systemd_unit.erb deleted file mode 100644 index a1ae52f50..000000000 --- a/templates/ubuntu/systemd_unit.erb +++ /dev/null @@ -1,61 +0,0 @@ -[Unit] -Description=Elasticsearch -Documentation=http://www.elastic.co -Wants=network-online.target -After=network-online.target - -[Service] -Environment=ES_HOME=/usr/share/elasticsearch -Environment=CONF_DIR=/etc/elasticsearch -Environment=DATA_DIR=/var/lib/elasticsearch -Environment=LOG_DIR=/var/log/elasticsearch -Environment=PID_DIR=/var/run/elasticsearch -EnvironmentFile=-/etc/default/elasticsearch - -WorkingDirectory=/usr/share/elasticsearch - -User=elasticsearch -Group=elasticsearch - -ExecStartPre=/usr/share/elasticsearch/bin/elasticsearch-systemd-pre-exec - -ExecStart=/usr/share/elasticsearch/bin/elasticsearch \ - -p ${PID_DIR}/elasticsearch.pid \ - --quiet \ - -Edefault.path.logs=${LOG_DIR} \ - -Edefault.path.data=${DATA_DIR} \ - -Edefault.path.conf=${CONF_DIR} - -# StandardOutput is configured to redirect to journalctl since -# some error messages may be logged in standard output before -# elasticsearch logging system is initialized. Elasticsearch -# stores its logs in /var/log/elasticsearch and does not use -# journalctl by default. If you also want to enable journalctl -# logging, you can simply remove the "quiet" option from ExecStart. -StandardOutput=journal -StandardError=inherit - -# Specifies the maximum file descriptor number that can be opened by this process -LimitNOFILE=65536 - -# Specifies the maximum number of bytes of memory that may be locked into RAM -# Set to "infinity" if you use the 'bootstrap.memory_lock: true' option -# in elasticsearch.yml and 'MAX_LOCKED_MEMORY=unlimited' in /etc/default/elasticsearch -#LimitMEMLOCK=infinity - -# Disable timeout logic and wait until process is stopped -TimeoutStopSec=0 - -# SIGTERM signal is used to stop the Java process -KillSignal=SIGTERM - -# Java process is never killed -SendSIGKILL=no - -# When a JVM receives a SIGTERM signal it exits with code 143 -SuccessExitStatus=143 - -[Install] -WantedBy=multi-user.target - -# Built for distribution-5.0.0 (distribution) diff --git a/test/fixtures/cookbooks/elasticsearch_test/recipes/default_with_plugins.rb b/test/fixtures/cookbooks/elasticsearch_test/recipes/default_with_plugins.rb index 32a3dbacb..b9fec6531 100644 --- a/test/fixtures/cookbooks/elasticsearch_test/recipes/default_with_plugins.rb +++ b/test/fixtures/cookbooks/elasticsearch_test/recipes/default_with_plugins.rb @@ -9,18 +9,10 @@ # cookbook (unlike install, configure, and service, which we do ship in the # default cookbook). -# see README.md and test/fixtures/cookbooks for more examples! include_recipe 'chef-sugar' -# see README.md and test/fixtures/cookbooks for more examples! -elasticsearch_user 'elasticsearch' -elasticsearch_install 'elasticsearch' do - type node['elasticsearch']['install_type'].to_sym # since TK can't symbol. -end -elasticsearch_configure 'elasticsearch' -elasticsearch_service 'elasticsearch' do - service_actions [:enable, :start] -end +# see README.md +include_recipe 'elasticsearch::default' # by default, no plugins, but we do the x-pack elasticsearch_plugin 'x-pack' do diff --git a/test/fixtures/cookbooks/elasticsearch_test/recipes/doubleinstances.rb b/test/fixtures/cookbooks/elasticsearch_test/recipes/doubleinstances.rb index 60f22784b..44a53a77f 100644 --- a/test/fixtures/cookbooks/elasticsearch_test/recipes/doubleinstances.rb +++ b/test/fixtures/cookbooks/elasticsearch_test/recipes/doubleinstances.rb @@ -8,7 +8,7 @@ # for package install, share the various paths across instances elasticsearch_install 'elasticsearch' do - type :package + type 'package' end elasticsearch_plugin 'elasticsearch_xpack' do @@ -33,13 +33,13 @@ %w(alpha beta).each do |instance_name| elasticsearch_configure "elasticsearch_#{instance_name}" do instance_name instance_name - path_home package: '/usr/share/elasticsearch' - path_conf package: "/etc/elasticsearch-#{instance_name}" - path_data package: "/var/lib/elasticsearch/#{instance_name}" - path_logs package: "/var/log/elasticsearch-#{instance_name}" - path_pid package: "/var/run/elasticsearch-#{instance_name}" - path_plugins package: '/usr/share/elasticsearch/bin/plugin' - path_bin package: '/usr/share/elasticsearch/bin' + path_home '/usr/share/elasticsearch' + path_conf "/etc/elasticsearch-#{instance_name}" + path_data "/var/lib/elasticsearch/#{instance_name}" + path_logs "/var/log/elasticsearch-#{instance_name}" + path_pid "/var/run/elasticsearch-#{instance_name}" + path_plugins '/usr/share/elasticsearch/bin/plugin' + path_bin '/usr/share/elasticsearch/bin' allocated_memory '256m' configuration( 'cluster.name' => 'mycluster', diff --git a/test/fixtures/cookbooks/elasticsearch_test/recipes/package.rb b/test/fixtures/cookbooks/elasticsearch_test/recipes/package.rb index 9fce36907..c3542b593 100644 --- a/test/fixtures/cookbooks/elasticsearch_test/recipes/package.rb +++ b/test/fixtures/cookbooks/elasticsearch_test/recipes/package.rb @@ -4,7 +4,7 @@ # create user with all non-default overriden options elasticsearch_user 'foobar' do groupname 'bar' - username 'foo' + username 'elasticsearch' # can't override this in systemd, so can't test! uid 1111 gid 2222 shell '/bin/sh' @@ -13,7 +13,7 @@ # we're going to test both types on a single system! elasticsearch_install 'elasticsearch_p' do - type :package + type 'package' instance_name 'special_package_instance' end @@ -21,17 +21,17 @@ logging(action: 'INFO') allocated_memory '123m' - thread_stack_size '512k' - env_options '-DFOO=BAR' - gc_settings <<-CONFIG + jvm_options %w( + -server + -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDetails - CONFIG + ) configuration('node.name' => 'arbitrary_name') # plugin_dir '/usr/local/awesome/elasticsearch-1.7.3/plugins' diff --git a/test/fixtures/cookbooks/elasticsearch_test/recipes/tarball.rb b/test/fixtures/cookbooks/elasticsearch_test/recipes/tarball.rb index 6ecdce198..4111654c1 100644 --- a/test/fixtures/cookbooks/elasticsearch_test/recipes/tarball.rb +++ b/test/fixtures/cookbooks/elasticsearch_test/recipes/tarball.rb @@ -12,34 +12,32 @@ end elasticsearch_install 'elasticsearch_s' do - type :tarball - dir tarball: '/usr/local/awesome' + type 'tarball' + dir '/usr/local/awesome' instance_name 'special_tarball_instance' end elasticsearch_configure 'my_elasticsearch' do - path_home tarball: '/usr/local/awesome/elasticsearch' - path_conf tarball: '/usr/local/awesome/etc/elasticsearch' - path_data tarball: '/usr/local/awesome/var/data/elasticsearch' - path_logs tarball: '/usr/local/awesome/var/log/elasticsearch' - path_pid tarball: '/usr/local/awesome/var/run' - path_plugins tarball: '/usr/local/awesome/elasticsearch/plugins' - path_bin tarball: '/usr/local/bin' + path_home '/usr/local/awesome/elasticsearch' + path_conf '/usr/local/awesome/etc/elasticsearch' + path_data '/usr/local/awesome/var/data/elasticsearch' + path_logs '/usr/local/awesome/var/log/elasticsearch' + path_pid '/usr/local/awesome/var/run' + path_plugins '/usr/local/awesome/elasticsearch/plugins' + path_bin '/usr/local/bin' logging(action: 'INFO') allocated_memory '123m' - thread_stack_size '512k' - env_options '-DFOO=BAR' - gc_settings <<-CONFIG + jvm_options %w( -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDetails - CONFIG + ) configuration('node.name' => 'crazy') action :manage diff --git a/test/integration/helpers/serverspec/configure_examples.rb b/test/integration/helpers/serverspec/configure_examples.rb index 0c6d3b297..6303076a5 100644 --- a/test/integration/helpers/serverspec/configure_examples.rb +++ b/test/integration/helpers/serverspec/configure_examples.rb @@ -1,10 +1,10 @@ require_relative 'spec_helper' shared_examples_for 'elasticsearch configure' do |args = {}| - dir = args[:dir] || (package? ? '/usr/share/elasticsearch' : '/usr/local') - path_conf = args[:path_conf] || (package? ? '/etc/elasticsearch' : "#{dir}/etc/elasticsearch") - path_data = args[:path_data] || (package? ? '/var/lib/elasticsearch' : "#{dir}/var/data/elasticsearch") - path_logs = args[:path_logs] || (package? ? '/var/log/elasticsearch' : "#{dir}/var/log/elasticsearch") + dir = args[:dir] || '/usr/share' + path_conf = args[:path_conf] || '/etc/elasticsearch' + path_data = args[:path_data] || '/var/lib/elasticsearch' + path_logs = args[:path_logs] || '/var/log/elasticsearch' path_sysconfig = args[:path_sysconfig] || (rhel? ? '/etc/sysconfig/elasticsearch' : '/etc/default/elasticsearch') expected_user = args[:user] || 'elasticsearch' @@ -36,8 +36,6 @@ expected_jvm_options = args[:jvmopts] || [ 'server', 'HeapDumpOnOutOfMemoryError', - 'DisableExplicitGC', - 'AlwaysPreTouch', 'java.awt.headless=true' ] diff --git a/test/integration/helpers/serverspec/install_examples.rb b/test/integration/helpers/serverspec/install_examples.rb index cf9a484fd..0a77f045e 100644 --- a/test/integration/helpers/serverspec/install_examples.rb +++ b/test/integration/helpers/serverspec/install_examples.rb @@ -1,8 +1,8 @@ require_relative 'spec_helper' shared_examples_for 'elasticsearch install' do |args = {}| - dir = args[:dir] || (package? ? '/usr/share/elasticsearch' : '/usr/local') - version = args[:version] || '2.4.1' + dir = args[:dir] || '/usr/share' + version = args[:version] || '5.0.0' expected_user = args[:user] || 'elasticsearch' expected_group = args[:group] || expected_user || 'elasticsearch' diff --git a/test/integration/helpers/serverspec/plugin_examples.rb b/test/integration/helpers/serverspec/plugin_examples.rb index 87a645600..fa36e222c 100644 --- a/test/integration/helpers/serverspec/plugin_examples.rb +++ b/test/integration/helpers/serverspec/plugin_examples.rb @@ -3,7 +3,7 @@ shared_examples_for 'elasticsearch plugin' do |plugin_name, args = {}| expected_user = args[:user] || (package? ? 'root' : 'elasticsearch') expected_group = args[:group] || expected_user || 'elasticsearch' - expected_home = args[:home] || (package? ? '/usr/share/elasticsearch' : '/usr/local/elasticsearch') + expected_home = args[:home] || '/usr/share/elasticsearch' expected_plugin = args[:plugin] || "#{expected_home}/plugins/#{plugin_name}" expected_response_code = args[:response_code] || 200 auth_data = args[:auth_data] || 'elastic:changeme@' diff --git a/test/integration/override_package/serverspec/default_spec.rb b/test/integration/override_package/serverspec/default_spec.rb index bedf26c30..1b731a3c6 100644 --- a/test/integration/override_package/serverspec/default_spec.rb +++ b/test/integration/override_package/serverspec/default_spec.rb @@ -3,7 +3,7 @@ describe 'non-standard elasticsearch install and configure' do path_component = rhel? ? 'sysconfig' : 'default' - it_behaves_like 'elasticsearch user', user: 'foo', + it_behaves_like 'elasticsearch user', user: 'elasticsearch', uid: 1111, shell: '/bin/sh', group: 'bar', @@ -11,14 +11,14 @@ it_behaves_like 'elasticsearch install', dir: '/usr/local/awesome', package: 'elasticsearch', - user: 'foo', + user: 'elasticsearch', group: 'bar' it_behaves_like 'elasticsearch configure', dir: '/usr/local/awesome', - user: 'foo', + user: 'elasticsearch', group: 'bar', path_sysconfig: "/etc/#{path_component}/elasticsearch-crazy", - env: ['FOO=BAR', 'PrintGCDetails', '-Xss512k'] + env: ['ES_GROUP=bar'] it_behaves_like 'elasticsearch service', 'elasticsearch-crazy' end