diff --git a/.kitchen.yml b/.kitchen.yml index e729a58ff..312b48b75 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -94,12 +94,3 @@ suites: run_list: - recipe[java] - recipe[elasticsearch_test::default_with_plugins] - - - name: shieldwatcher # install licensed plugins for testing - require_chef_omnibus: true - run_list: - - recipe[java] - - recipe[elasticsearch_test::shieldwatcher] - attributes: - elasticsearch: - install_type: package diff --git a/README.md b/README.md index 0e1762f6a..b72977c7a 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [Java Runtime](https://www.java.com/en/) - This cookbook requires java, but does not provide it. Please install Java before using any recipe in this cookbook. Please also note that Elasticsearch itself has [specific minimum Java version requirements](https://www.elastic.co/guide/en/elasticsearch/reference/current/setup.html#jvm-version). We recommend [this cookbook](https://github.com/agileorbit-cookbooks/java) to install Java. -[Elasticsearch](https://www.elastic.co/products/elasticsearch) - This cookbook is being written and tested to support Elasticsearch 2.x and greater. If you must have a cookbook that works with older versions of Elasticsearch, please test and then pin to a specific, older `major.minor` version of this cookbook and only leave the patch release to float. +[Elasticsearch](https://www.elastic.co/products/elasticsearch) - This cookbook is being written and tested to support Elasticsearch 5.x and greater. If you must have a cookbook that works with older versions of Elasticsearch, please test and then pin to a specific, older `major.minor` version of this cookbook and only leave the patch release to float. Older versions can be found via [Git tags](https://github.com/elastic/cookbook-elasticsearch/tags) or on [Chef Supermarket](https://supermarket.chef.io/cookbooks/elasticsearch). We also maintain bugfix branches for major released lines (0.x, 1.x, 2.x) of this cookbook so that we can still release fixes for older cookbooks. [Chef](https://www.chef.io/) - The latest release of this cookbook is intended to support the three most recent releases of Chef, and tests against those. Earlier versions may also be supported, though we suggest that you use Chef 12.x at a minimum. It implements support for CI as well as more modern testing with chefspec and test-kitchen. It no longer supports some of the more extraneous features such as discovery (use [chef search](https://docs.chef.io/chef_search.html) in your wrapper cookbook) or EBS device creation (use [the aws cookbook](https://github.com/chef-cookbooks/aws)). @@ -24,7 +24,7 @@ the version parameter as a string into your download_url. |Name|Default|Other values| |----|-------|------------| -|`default['elasticsearch']['version']`|`'2.4.1'`|[See list](attributes/default.rb).| +|`default['elasticsearch']['version']`|`'5.0.0'`|[See list](attributes/default.rb).| |`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| @@ -88,10 +88,7 @@ elasticsearch_user 'elasticsearch' elasticsearch_install 'elasticsearch' elasticsearch_configure 'elasticsearch' elasticsearch_service 'elasticsearch' - -elasticsearch_plugin 'head' do - url 'mobz/elasticsearch-head' -end +elasticsearch_plugin 'x-pack' ``` ### elasticsearch_user @@ -185,7 +182,7 @@ end Actions: `:manage`, `:remove` Configures an elasticsearch instance; creates directories for configuration, -logs, and data. Writes files `logging.yml`, `elasticsearch.in.sh` and +logs, and data. Writes files `log4j2.properties`, `elasticsearch.in.sh` and `elasticsearch.yml`. The main attribute for this resource is `configuration`, @@ -340,8 +337,7 @@ To run multiple instances per machine, an explicit `plugin_dir` location has to be provided: ```ruby -elasticsearch_plugin 'head' do - url 'mobz/elasticsearch-head' +elasticsearch_plugin 'x-pack' do plugin_dir '/usr/share/elasticsearch_foo/plugins' end ``` diff --git a/attributes/default.rb b/attributes/default.rb index d080932bb..d8fa0c7a2 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1,90 +1,15 @@ # elasticsearch version & install type -default['elasticsearch']['version'] = '2.4.1' +default['elasticsearch']['version'] = '5.0.0' default['elasticsearch']['install_type'] = :package # platform_family keyed download URLs default['elasticsearch']['download_urls'] = { - 'debian' => 'https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-%s.deb', - 'rhel' => 'https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-%s.noarch.rpm', - 'tar' => 'https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-%s.tar.gz' -} - -default['elasticsearch']['download_urls_v2'] = { - 'debian' => 'https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/%s/elasticsearch-%s.deb', - 'rhel' => 'https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/%s/elasticsearch-%s.rpm', - 'tar' => 'https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/%s/elasticsearch-%s.tar.gz' + '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' } # platform_family keyed download sha256 checksums -default['elasticsearch']['checksums']['1.4.5']['debian'] = '68dce951181e9802e94fd83b894f4b628394fc44bb01c77eb61fdbd1940d94b5' -default['elasticsearch']['checksums']['1.4.5']['rhel'] = '29b005c4148036556f78d6bd01a5e7c8e4ea60e2c20f82b63d8362ab46d83a19' -default['elasticsearch']['checksums']['1.4.5']['tar'] = 'dc28aa9e441cbc3282ecc9cb498bea219355887b102aac872bdf05d5977356e2' -default['elasticsearch']['checksums']['1.5.0']['debian'] = '15a02a2bea74da2330bb78718efb3a8f83a2b2e040a6ee859e100a6556981f36' -default['elasticsearch']['checksums']['1.5.0']['rhel'] = 'b72a9fb9a2c0471e8fe1a35373cdcfe39d29e72b7281bfccbdc32d03ee0eff70' -default['elasticsearch']['checksums']['1.5.0']['tar'] = 'acf572c606552bc446cceef3f8e93814a363ba0d215b323a2864682b3abfbe45' -default['elasticsearch']['checksums']['1.6.2']['debian'] = 'da22c2df44ade970c7d8ec346fd37a440ed40f9e73fb3427b9eacf44baf298c2' -default['elasticsearch']['checksums']['1.6.2']['rhel'] = '60c75a6f386bd729c6af2995af0a5290dd0ed6286673d435fc52620721815d91' -default['elasticsearch']['checksums']['1.6.2']['tar'] = 'b7ef3aae0a263c2312bd1a25b191c3c108c92d5413c3527d776587e582c518d0' -default['elasticsearch']['checksums']['1.7.1']['debian'] = '5832808f2a4c77de5af225db11da00138d9ea07a17f7b9212f4d2aac5317169d' -default['elasticsearch']['checksums']['1.7.1']['rhel'] = '9b083f441490b32f98f9bf654e5e8ddec885838128726691103cfda5068423bc' -default['elasticsearch']['checksums']['1.7.1']['tar'] = '86a0c20eea6ef55b14345bff5adf896e6332437b19180c4582a346394abde019' -default['elasticsearch']['checksums']['1.7.2']['debian'] = '791fb9f2131be2cf8c1f86ca35e0b912d7155a53f89c2df67467ca2105e77ec2' -default['elasticsearch']['checksums']['1.7.2']['rhel'] = 'c5410b88494d5cc9fdadf59353430b46c28e58eddc5c610ea4c4516eacc2fa09' -default['elasticsearch']['checksums']['1.7.2']['tar'] = '6f81935e270c403681e120ec4395c28b2ddc87e659ff7784608b86beb5223dd2' -default['elasticsearch']['checksums']['1.7.3']['debian'] = '52950c688cb3d6a13686753b4e8b1c80183e81174059924ee08b2df172afbb1c' -default['elasticsearch']['checksums']['1.7.3']['rhel'] = '2380343487ffafc6a7a834cf51d2abbfb7c5ad9d9d45301671adebf97abc632a' -default['elasticsearch']['checksums']['1.7.3']['tar'] = 'af517611493374cfb2daa8897ae17e63e2efea4d0377d316baa351c1776a2bca' -default['elasticsearch']['checksums']['1.7.4']['debian'] = 'f46a2892e454030d267f087db1be6bd9ae556bb1708a12cf94eeb4180951bf1f' -default['elasticsearch']['checksums']['1.7.4']['rhel'] = 'a3469fa93e05029ae4ba9dd7ddf80828095b850bc5764c24bae4dafc2346ef1f' -default['elasticsearch']['checksums']['1.7.4']['tar'] = '395f3417c26a6b36125f6a062c1129b454a961efea09151c692adc63562e5a94' -default['elasticsearch']['checksums']['1.7.5']['debian'] = '4e5a4d29f5fbd737d203e7049f2e18515c3443f9e01e193583e2b5c60779cc0f' -default['elasticsearch']['checksums']['1.7.5']['rhel'] = '4e0a4ff1ae76337308ebed977fb29c2f2d1251b2780f751676e3b18a1d7db00f' -default['elasticsearch']['checksums']['1.7.5']['tar'] = '0aa58947d66b487488e86059352deb7c6cab5da4accdff043cce9fed7c3d2fa7' -default['elasticsearch']['checksums']['2.0.0-rc1']['debian'] = '6ba92f96676932756ff7113f42d8946679e9be2144acece59bd79367568eb712' -default['elasticsearch']['checksums']['2.0.0-rc1']['rhel'] = '4dd4bdd1b4333f221bc5d2a2638bdc89282d57923842ce4c76607497abafb44d' -default['elasticsearch']['checksums']['2.0.0-rc1']['tar'] = 'cfd97bba0c49000a2799fffd359ec351f0ca7ef5f0a8c160920137db6b057784' -default['elasticsearch']['checksums']['2.0.0']['debian'] = 'f846cab2b7e99159650d38767249275c2fd5d3574fe700ef199cd1cb06ef28bf' -default['elasticsearch']['checksums']['2.0.0']['rhel'] = '6bd2d7840447836450d8781fffa9e296dfb257b523598c6e55433850e37feb25' -default['elasticsearch']['checksums']['2.0.0']['tar'] = 'b25f13f615337c2072964fd9fc5c7250f8a2a983b22198daf93548285d5d16df' -default['elasticsearch']['checksums']['2.0.1']['debian'] = '815a7b7d3bbd862c3ec136aa7bfb1adec272bdecdae45233d9ffdf61d307e86c' -default['elasticsearch']['checksums']['2.0.1']['rhel'] = '69957ef5ee6a142adf02c1065faa29bda7e2cf7f2d5c56edad4852b7f644345a' -default['elasticsearch']['checksums']['2.0.1']['tar'] = '7be4a6c717002057e422073ca8e957df8b4cb198bf2399a0d79f42121e34798b' -default['elasticsearch']['checksums']['2.1.0']['debian'] = '099fdeb7b3903ce8cea7d39b577ed6445b78b64d14dd2664fd2ca1e0896691dd' -default['elasticsearch']['checksums']['2.1.0']['rhel'] = 'a79c1985224c1b57479275794b258f4eba973e0b65f5c62b1c38e02738a1ce71' -default['elasticsearch']['checksums']['2.1.0']['tar'] = '8a4e85bcb506daa369651506af1cbc55c09fd7ff387d111142ae14d0a85d4d14' -default['elasticsearch']['checksums']['2.1.1']['debian'] = '097400b0b46c826c6a8be837739ade0c0c326b47d38ef54df7bd48de9e9e9995' -default['elasticsearch']['checksums']['2.1.1']['rhel'] = '22fc646aed2b6900116589a5712ac9324682470336bbbb025b4a607efb735e5a' -default['elasticsearch']['checksums']['2.1.1']['tar'] = 'ebd69c0483f20ba7e51caa9606d4e3ce5fe2667e1216c799f0cdbb815c317ce6' -default['elasticsearch']['checksums']['2.2.0']['debian'] = 'c97ac75303a7ba042c45adff74e27c3584d64d8e0f6f24c43afdcbff484b43d5' -default['elasticsearch']['checksums']['2.2.0']['rhel'] = '13fe3717e7761f23cd41a148a31ee49496cbdb45f44bfaeb3ba5538a41fdd79a' -default['elasticsearch']['checksums']['2.2.0']['tar'] = 'ed70cc81e1f55cd5f0032beea2907227b6ad8e7457dcb75ddc97a2cc6e054d30' -default['elasticsearch']['checksums']['2.2.1']['debian'] = 'cb89f880e03276624b3529506c9d2ed6b537968d1c819026e087117cd4c60c7c' -default['elasticsearch']['checksums']['2.2.1']['rhel'] = 'ddb5e1545e90b45e2b9495c35d5336a40fc63e09d8ac9cac73079888405df7f4' -default['elasticsearch']['checksums']['2.2.1']['tar'] = '7d43d18a8ee8d715d827ed26b4ff3d939628f5a5b654c6e8de9d99bf3a9b2e03' -default['elasticsearch']['checksums']['2.2.2']['debian'] = '5d44d4151430e5c87455f8efba41475a50a228131711a803b7ba7e271764bd9c' -default['elasticsearch']['checksums']['2.2.2']['rhel'] = '988d1b3c9aef94b8ea74daef14889690000c9fd6c80b0cf032039b4d26c252a6' -default['elasticsearch']['checksums']['2.2.2']['tar'] = 'c706db594f1feb5051d90697c6c412eadd60e00a9ec3b4f345a122801183af69' -default['elasticsearch']['checksums']['2.3.0']['debian'] = '2645e341587f636edaca1ee1380eeb76596d99b596bf17e03e2c37c697523efd' -default['elasticsearch']['checksums']['2.3.0']['rhel'] = '7469808bc64bca0b2e1a9fe258ff04ba4acde6c86d13a5cd19d623966fecfffd' -default['elasticsearch']['checksums']['2.3.0']['tar'] = 'd68482c7633f2986263bc5f11f93b8a58c54c6cf5e337b615446d0a7c6fdcd8b' -default['elasticsearch']['checksums']['2.3.1']['debian'] = 'ff22da40b60ae216761c7f6148e12760f34e0e51bc2198d5022934dc520b7d6c' -default['elasticsearch']['checksums']['2.3.1']['rhel'] = '841946dfe9220a4fdae7bbd491114a0eccbcc6d096bf4343d02e7c6e7abb704f' -default['elasticsearch']['checksums']['2.3.1']['tar'] = 'f0092e73038e0472fcdd923e5f2792e13692ea0f09ca034a54dd49b217110ebb' -default['elasticsearch']['checksums']['2.3.2']['debian'] = '3d474b0123ec8ad4ebfa089f8cde607033e6cbef28a6a0df318bdc3d2a546cd8' -default['elasticsearch']['checksums']['2.3.2']['rhel'] = '7bc84521921af8e43089c4fd64eced9eb68167d73fc14c102732f78750dfc607' -default['elasticsearch']['checksums']['2.3.2']['tar'] = '04c4d3913d496d217e038da88df939108369ae2e78eea29cb1adf1c4ab3a000a' -default['elasticsearch']['checksums']['2.3.3']['debian'] = 'fa90c6aefc5e82e0e19cb0ec546b9a64fec354ede201cf24658ddcfe01762d92' -default['elasticsearch']['checksums']['2.3.3']['rhel'] = '9aef1abe334d3143d8347144d69a35f449c5ecd8eebc3d7277f224d18679585a' -default['elasticsearch']['checksums']['2.3.3']['tar'] = '5fe0a6887432bb8a8d3de2e79c9b81c83cfa241e6440f0f0379a686657789165' -default['elasticsearch']['checksums']['2.3.4']['debian'] = 'abf6ce899cb7f2d9fc6eae0ecba148a191093e62afd1e242ba0bb1a7c2686074' -default['elasticsearch']['checksums']['2.3.4']['rhel'] = '781af05407d88a7bf4cf743d49e8b595d9494ba7334794ed2e2f8f9e64b67e71' -default['elasticsearch']['checksums']['2.3.4']['tar'] = '371e0c5f4ded0a8548f1cce55faff3efebcfd5f895c2c816f220146521f6f06e' -default['elasticsearch']['checksums']['2.3.5']['debian'] = '9fd12eca701ccd7a1ae5767187882327262717154ba1fb7eab3c3a653874d3fb' -default['elasticsearch']['checksums']['2.3.5']['rhel'] = 'ad869bb0d91cdf97391f85832c7309d44684e867d7c74263808e4687c4ab8789' -default['elasticsearch']['checksums']['2.3.5']['tar'] = '1119a8c18620b98c4b85261318663a1f26dea92a26f34dfeb7f813fb7cbb468a' -default['elasticsearch']['checksums']['2.4.0']['debian'] = '5edf1ac795d6950781b20ecc8db992d6dc95e55abb1ff66e6b1234d85bd68514' -default['elasticsearch']['checksums']['2.4.0']['rhel'] = 'aa75abe581685cb5767ce91a042b8b395290d966bcb575ff2e3d1cf1fd06ff7f' -default['elasticsearch']['checksums']['2.4.0']['tar'] = '3ae01140ae7bcbb91436feef381fbed774e36ef6d1e8e6a3153640db82acf4c9' -default['elasticsearch']['checksums']['2.4.1']['debian'] = 'cdf94b84cbf3024961cd09a689957fe39df6da9afcfe76ceba20dbfb50b92945' -default['elasticsearch']['checksums']['2.4.1']['rhel'] = 'c8a275d12876165da532ebfde1eeb6a502613bda919d95516f30f6495ae5086d' -default['elasticsearch']['checksums']['2.4.1']['tar'] = '23a369ef42955c19aaaf9e34891eea3a055ed217d7fbe76da0998a7a54bbe167' +default['elasticsearch']['checksums']['5.0.0']['debian'] = '0a4f8842a1f7d7bd3015118298284383efcd4c25f9591c46bb5ab68189815268' +default['elasticsearch']['checksums']['5.0.0']['rhel'] = 'fb502a9754f2162f27590125aecc6b68fa999738051d8f230c4da4ed6deb8d62' +default['elasticsearch']['checksums']['5.0.0']['tar'] = 'a866534f0fa7428e980c985d712024feef1dee04709add6e360fc7b73bb1e7ae' diff --git a/libraries/helpers.rb b/libraries/helpers.rb index 75824c0a2..4f2f8cbc1 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -85,23 +85,18 @@ 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) - newer_url_style = version.to_f >= 2.0 - - # v2 and greater has a different set of URLs - url_hash_key = newer_url_style ? 'download_urls_v2' : 'download_urls' 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'][url_hash_key]['tar'] - elsif install_type.to_s == 'package' && node['elasticsearch'][url_hash_key][platform_family] - url_string = node['elasticsearch'][url_hash_key][platform_family] + url_string = node['elasticsearch']['download_urls']['tar'] + elsif install_type.to_s == 'package' && node['elasticsearch']['download_urls'][platform_family] + url_string = node['elasticsearch']['download_urls'][platform_family] end if url_string && version - # v2 and greater has two %s entries for version - return (newer_url_style ? format(url_string, version, version) : format(url_string, version)) + return format(url_string, version) elsif url_string return url_string end diff --git a/libraries/provider_configure.rb b/libraries/provider_configure.rb index a36a282f1..c8373e578 100644 --- a/libraries/provider_configure.rb +++ b/libraries/provider_configure.rb @@ -66,36 +66,29 @@ def whyrun_supported? new_resource.updated_by_last_action(true) if d.updated_by_last_action? end + # Create elasticsearch shell variables file + # # Valid values in /etc/sysconfig/elasticsearch or /etc/default/elasticsearch - # ES_HOME CONF_DIR CONF_FILE DATA_DIR LOG_DIR WORK_DIR PID_DIR - # ES_HEAP_SIZE ES_HEAP_NEWSIZE ES_DIRECT_SIZE ES_JAVA_OPTS - # ES_RESTART_ON_UPGRADE ES_GC_LOG_FILE ES_STARTUP_SLEEP_TIME - # ES_USER ES_GROUP MAX_OPEN_FILES MAX_LOCKED_MEMORY MAX_MAP_COUNT + # ES_HOME JAVA_HOME CONF_DIR DATA_DIR LOG_DIR PID_DIR ES_JAVA_OPTS + # RESTART_ON_UPGRADE ES_USER ES_GROUP ES_STARTUP_SLEEP_TIME MAX_OPEN_FILES + # MAX_LOCKED_MEMORY MAX_MAP_COUNT + # + # We provide these values as resource attributes/parameters directly + params = {} params[:ES_HOME] = new_resource.path_home[es_install.type] + 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[:ES_STARTUP_SLEEP_TIME] = new_resource.startup_sleep_seconds.to_s + params[:RESTART_ON_UPGRADE] = new_resource.restart_on_upgrade params[:ES_USER] = es_user.username params[:ES_GROUP] = es_user.groupname - - params[:JAVA_HOME] = new_resource.java_home - params[:ES_HEAP_SIZE] = new_resource.allocated_memory + 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[:ES_JAVA_OPTS] = '"' - params[:ES_JAVA_OPTS] << '-server ' - params[:ES_JAVA_OPTS] << '-Djava.awt.headless=true ' - params[:ES_JAVA_OPTS] << "-Xss#{new_resource.thread_stack_size} " - params[:ES_JAVA_OPTS] << "#{new_resource.gc_settings.tr("\n", ' ').strip.squeeze(' ')} " if new_resource.gc_settings - params[:ES_JAVA_OPTS] << '-Dfile.encoding=UTF-8 ' - params[:ES_JAVA_OPTS] << '-Djna.nosys=true' - params[:ES_JAVA_OPTS] << " #{new_resource.env_options}" if new_resource.env_options - params[:ES_JAVA_OPTS] << '"' + params[:MAX_MAP_COUNT] = new_resource.memlock_limit default_config_name = es_svc.service_name || es_svc.instance_name || new_resource.instance_name || 'elasticsearch' @@ -110,12 +103,31 @@ def whyrun_supported? shell_template.run_action(:create) new_resource.updated_by_last_action(true) if shell_template.updated_by_last_action? + # Create jvm.options file + # + jvm_options_template = template 'jvm_options' do + path "#{new_resource.path_conf[es_install.type]}/jvm.options" + source new_resource.template_jvm_options + cookbook new_resource.cookbook_jvm_options + owner es_user.username + group es_user.groupname + mode 0644 + variables(jvm_options: [ + "-Xms#{new_resource.allocated_memory}", + "-Xmx#{new_resource.allocated_memory}", + new_resource.jvm_options + ].flatten.join("\n")) + action :nothing + end + jvm_options_template.run_action(:create) + new_resource.updated_by_last_action(true) if jvm_options_template.updated_by_last_action? + # Create ES logging file # - logging_template = template 'logging.yml' do - path "#{new_resource.path_conf[es_install.type]}/logging.yml" - source new_resource.template_logging_yml - cookbook new_resource.cookbook_logging_yml + logging_template = template 'log4j2_properties' do + path "#{new_resource.path_conf[es_install.type]}/log4j2.properties" + source new_resource.template_log4j2_properties + cookbook new_resource.cookbook_log4j2_properties owner es_user.username group es_user.groupname mode 0644 @@ -125,6 +137,8 @@ def whyrun_supported? logging_template.run_action(:create) new_resource.updated_by_last_action(true) if logging_template.updated_by_last_action? + # Create ES elasticsearch.yml file + # merged_configuration = default_configuration.merge(new_resource.configuration.dup) # warn if someone is using symbols. we don't support. diff --git a/libraries/provider_install.rb b/libraries/provider_install.rb index afca876bf..b91a3f34c 100644 --- a/libraries/provider_install.rb +++ b/libraries/provider_install.rb @@ -102,7 +102,7 @@ def install_tarball_wrapper_action owner es_user.username group es_user.groupname version determine_version(new_resource, node) - has_binaries ['bin/elasticsearch', 'bin/plugin'] + 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] diff --git a/libraries/provider_plugin.rb b/libraries/provider_plugin.rb index 24eaa48c9..981d8dae4 100644 --- a/libraries/provider_plugin.rb +++ b/libraries/provider_plugin.rb @@ -35,7 +35,7 @@ def manage_plugin(arguments) 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 - command_array = "#{es_conf.path_bin[es_install.type]}/plugin #{arguments.chomp(' ')}".chomp(' ').split(' ') + command_array = "#{es_conf.path_bin[es_install.type]}/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 @@ -54,14 +54,6 @@ def plugin_exists(name) end def assert_state_is_valid(es_user, es_install, es_conf) - begin - if es_user.username != 'root' && es_install.version.to_f < 2.0 - Chef::Log.warn("Elasticsearch < 2.0.0 (you are using #{es_install.version}) requires plugins be installed as root (you are using #{es_user.username})") - end - rescue - Chef::Log.warn("Could not parse #{es_install.version} as floating point number") - end - 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}]." end diff --git a/libraries/provider_service.rb b/libraries/provider_service.rb index f4740b5dc..faa8b9260 100644 --- a/libraries/provider_service.rb +++ b/libraries/provider_service.rb @@ -26,7 +26,7 @@ def whyrun_supported? d_r.run_action(:create) new_resource.updated_by_last_action(true) if d_r.updated_by_last_action? - # Create service + # Create service for init and systemd # init_r = template "/etc/init.d/#{new_resource.service_name}" do source new_resource.init_source @@ -37,11 +37,27 @@ def whyrun_supported? # we need to include something about #{progname} fixed in here. program_name: new_resource.service_name ) + only_if { ::File.exist?('/etc/init.d') } action :nothing end init_r.run_action(:create) new_resource.updated_by_last_action(true) if init_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 + owner 'root' + mode 0755 + variables( + # we need to include something about #{progname} fixed in here. + program_name: new_resource.service_name + ) + only_if { ::File.exist?('/usr/lib/systemd/system') } + action :nothing + end + systemd_r.run_action(:create) + new_resource.updated_by_last_action(true) if systemd_r.updated_by_last_action? + # flatten in an array here, in case the service_actions are a symbol vs. array [new_resource.service_actions].flatten.each do |act| passthrough_action(act) diff --git a/libraries/resource_configure.rb b/libraries/resource_configure.rb index 310637eff..dfdaf71cc 100644 --- a/libraries/resource_configure.rb +++ b/libraries/resource_configure.rb @@ -42,34 +42,45 @@ class ElasticsearchCookbook::ConfigureResource < Chef::Resource::LWRPBase attribute(:template_elasticsearch_env, kind_of: String, default: 'elasticsearch.in.sh.erb') attribute(:cookbook_elasticsearch_env, kind_of: String, default: 'elasticsearch') + attribute(:template_jvm_options, kind_of: String, default: 'jvm_options.erb') + attribute(:cookbook_jvm_options, kind_of: String, default: 'elasticsearch') + attribute(:template_elasticsearch_yml, kind_of: String, default: 'elasticsearch.yml.erb') attribute(:cookbook_elasticsearch_yml, kind_of: String, default: 'elasticsearch') - attribute(:template_logging_yml, kind_of: String, default: 'logging.yml.erb') - attribute(:cookbook_logging_yml, kind_of: String, default: 'elasticsearch') + attribute(:template_log4j2_properties, kind_of: String, default: 'log4j2.properties.erb') + 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) attribute(:startup_sleep_seconds, kind_of: [String, Integer], default: 5) # 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. attribute(:allocated_memory, kind_of: String) - attribute(:thread_stack_size, kind_of: String, default: '256k') - attribute(:env_options, kind_of: String, default: nil) - attribute(:gc_settings, kind_of: String, default: - <<-CONFIG - -XX:+UseParNewGC + attribute(:jvm_options, kind_of: Array, default: + %w( -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly - -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC - CONFIG - ) + -XX:+AlwaysPreTouch + -server + -Djava.awt.headless=true + -Dfile.encoding=UTF-8 + -Djna.nosys=true + -Dio.netty.noUnsafe=true + -Dio.netty.noKeySetOptimization=true + -Dlog4j.shutdownHookEnabled=false + -Dlog4j2.disable.jmx=true + -Dlog4j.skipJansi=true + -XX:+HeapDumpOnOutOfMemoryError + ).freeze + ) # default user limits attribute(:memlock_limit, kind_of: String, default: 'unlimited') @@ -94,13 +105,6 @@ class ElasticsearchCookbook::ConfigureResource < Chef::Resource::LWRPBase # # 'node.data' => ?, # 'node.master' => ?, - - 'action.destructive_requires_name' => true, - 'node.max_local_storage_nodes' => 1, - - 'gateway.expected_nodes' => 0, - - 'http.port' => 9200 }.freeze) # These settings are merged with the `default_configuration` attribute, diff --git a/libraries/resource_plugin.rb b/libraries/resource_plugin.rb index 06a524dfd..28bf81a6c 100644 --- a/libraries/resource_plugin.rb +++ b/libraries/resource_plugin.rb @@ -12,6 +12,7 @@ class ElasticsearchCookbook::PluginResource < Chef::Resource::LWRPBase attribute(:plugin_name, kind_of: String, name_attribute: true) attribute(:url, kind_of: String, name_attribute: true) attribute(:chef_proxy, kind_of: [TrueClass, FalseClass], default: true) + attribute(:options, kind_of: String, default: '') # this is what helps the various resources find each other attribute(:instance_name, kind_of: String, default: nil) diff --git a/libraries/resource_service.rb b/libraries/resource_service.rb index ace872540..71494add2 100644 --- a/libraries/resource_service.rb +++ b/libraries/resource_service.rb @@ -21,4 +21,8 @@ class ElasticsearchCookbook::ServiceResource < Chef::Resource::LWRPBase # allow overridable init script attribute(:init_source, kind_of: String, default: 'initscript.erb') attribute(:init_cookbook, kind_of: String, default: 'elasticsearch') + + # allow overridable systemd unit + attribute(:systemd_source, kind_of: String, default: 'systemd_unit.erb') + attribute(:systemd_cookbook, kind_of: String, default: 'elasticsearch') end diff --git a/templates/amazon/initscript.erb b/templates/amazon/initscript.erb index 503b3fafd..b5f6f2ad1 100644 --- a/templates/amazon/initscript.erb +++ b/templates/amazon/initscript.erb @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # elasticsearch # @@ -35,7 +35,7 @@ fi ES_USER="elasticsearch" ES_GROUP="elasticsearch" ES_HOME="/usr/share/elasticsearch" -MAX_OPEN_FILES=65535 +MAX_OPEN_FILES=65536 MAX_MAP_COUNT=262144 LOG_DIR="/var/log/elasticsearch" DATA_DIR="/var/lib/elasticsearch" @@ -44,7 +44,7 @@ CONF_DIR="/etc/elasticsearch" PID_DIR="/var/run/elasticsearch" # Source the default env file -ES_ENV_FILE="/etc/sysconfig/<%= @program_name %>" +ES_ENV_FILE="/etc/sysconfig/elasticsearch" if [ -f "$ES_ENV_FILE" ]; then . "$ES_ENV_FILE" fi @@ -56,14 +56,10 @@ if [ ! -z "$CONF_FILE" ]; then fi exec="$ES_HOME/bin/elasticsearch" -prog="<%= @program_name %>" +prog="elasticsearch" pidfile="$PID_DIR/${prog}.pid" -export ES_HEAP_SIZE -export ES_HEAP_NEWSIZE -export ES_DIRECT_SIZE export ES_JAVA_OPTS -export ES_GC_LOG_FILE export ES_STARTUP_SLEEP_TIME export JAVA_HOME export ES_INCLUDE @@ -75,6 +71,11 @@ if [ -n $USER ] && [ -z $ES_USER ] ; then ES_USER=$USER fi +if [ ! -x "$exec" ]; then + echo "The elasticsearch startup script does not exists or it is not executable, tried: $exec" + exit 1 +fi + checkJava() { if [ -x "$JAVA_HOME/bin/java" ]; then JAVA="$JAVA_HOME/bin/java" @@ -91,10 +92,7 @@ checkJava() { start() { checkJava [ -x $exec ] || exit 5 - if [ -n "$MAX_LOCKED_MEMORY" -a -z "$ES_HEAP_SIZE" ]; then - echo "MAX_LOCKED_MEMORY is set - ES_HEAP_SIZE must also be set" - return 7 - fi + if [ -n "$MAX_OPEN_FILES" ]; then ulimit -n $MAX_OPEN_FILES fi @@ -104,7 +102,6 @@ start() { if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT fi - export ES_GC_LOG_FILE # Ensure that the PID_DIR exists (it is cleaned at OS startup time) if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then @@ -117,7 +114,7 @@ start() { cd $ES_HOME echo -n $"Starting $prog: " # if not running, start it up here, usually something like "daemon $exec" - daemon --user $ES_USER --pidfile $pidfile $exec -p $pidfile -d -Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR -Des.default.path.data=$DATA_DIR -Des.default.path.conf=$CONF_DIR + daemon --user $ES_USER --pidfile $pidfile $exec -p $pidfile -d -Edefault.path.logs=$LOG_DIR -Edefault.path.data=$DATA_DIR -Edefault.path.conf=$CONF_DIR retval=$? echo [ $retval -eq 0 ] && touch $lockfile diff --git a/templates/amazon/systemd_unit.erb b/templates/amazon/systemd_unit.erb new file mode 100644 index 000000000..549520522 --- /dev/null +++ b/templates/amazon/systemd_unit.erb @@ -0,0 +1,61 @@ +[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/centos/initscript.erb b/templates/centos/initscript.erb index 503b3fafd..b5f6f2ad1 100755 --- a/templates/centos/initscript.erb +++ b/templates/centos/initscript.erb @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # elasticsearch # @@ -35,7 +35,7 @@ fi ES_USER="elasticsearch" ES_GROUP="elasticsearch" ES_HOME="/usr/share/elasticsearch" -MAX_OPEN_FILES=65535 +MAX_OPEN_FILES=65536 MAX_MAP_COUNT=262144 LOG_DIR="/var/log/elasticsearch" DATA_DIR="/var/lib/elasticsearch" @@ -44,7 +44,7 @@ CONF_DIR="/etc/elasticsearch" PID_DIR="/var/run/elasticsearch" # Source the default env file -ES_ENV_FILE="/etc/sysconfig/<%= @program_name %>" +ES_ENV_FILE="/etc/sysconfig/elasticsearch" if [ -f "$ES_ENV_FILE" ]; then . "$ES_ENV_FILE" fi @@ -56,14 +56,10 @@ if [ ! -z "$CONF_FILE" ]; then fi exec="$ES_HOME/bin/elasticsearch" -prog="<%= @program_name %>" +prog="elasticsearch" pidfile="$PID_DIR/${prog}.pid" -export ES_HEAP_SIZE -export ES_HEAP_NEWSIZE -export ES_DIRECT_SIZE export ES_JAVA_OPTS -export ES_GC_LOG_FILE export ES_STARTUP_SLEEP_TIME export JAVA_HOME export ES_INCLUDE @@ -75,6 +71,11 @@ if [ -n $USER ] && [ -z $ES_USER ] ; then ES_USER=$USER fi +if [ ! -x "$exec" ]; then + echo "The elasticsearch startup script does not exists or it is not executable, tried: $exec" + exit 1 +fi + checkJava() { if [ -x "$JAVA_HOME/bin/java" ]; then JAVA="$JAVA_HOME/bin/java" @@ -91,10 +92,7 @@ checkJava() { start() { checkJava [ -x $exec ] || exit 5 - if [ -n "$MAX_LOCKED_MEMORY" -a -z "$ES_HEAP_SIZE" ]; then - echo "MAX_LOCKED_MEMORY is set - ES_HEAP_SIZE must also be set" - return 7 - fi + if [ -n "$MAX_OPEN_FILES" ]; then ulimit -n $MAX_OPEN_FILES fi @@ -104,7 +102,6 @@ start() { if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT fi - export ES_GC_LOG_FILE # Ensure that the PID_DIR exists (it is cleaned at OS startup time) if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then @@ -117,7 +114,7 @@ start() { cd $ES_HOME echo -n $"Starting $prog: " # if not running, start it up here, usually something like "daemon $exec" - daemon --user $ES_USER --pidfile $pidfile $exec -p $pidfile -d -Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR -Des.default.path.data=$DATA_DIR -Des.default.path.conf=$CONF_DIR + daemon --user $ES_USER --pidfile $pidfile $exec -p $pidfile -d -Edefault.path.logs=$LOG_DIR -Edefault.path.data=$DATA_DIR -Edefault.path.conf=$CONF_DIR retval=$? echo [ $retval -eq 0 ] && touch $lockfile diff --git a/templates/centos/systemd_unit.erb b/templates/centos/systemd_unit.erb new file mode 100644 index 000000000..549520522 --- /dev/null +++ b/templates/centos/systemd_unit.erb @@ -0,0 +1,61 @@ +[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 a908c7fc9..f04008ba7 100644 --- a/templates/debian/initscript.erb +++ b/templates/debian/initscript.erb @@ -1,14 +1,7 @@ -#!/bin/sh +#!/bin/bash # # /etc/init.d/elasticsearch -- startup script for Elasticsearch # -# Written by Miquel van Smoorenburg . -# Modified for Debian GNU/Linux by Ian Murdock . -# Modified for Tomcat by Stefan Gybas . -# Modified for Tomcat6 by Thierry Carrez . -# Additional improvements by Jason Brittain . -# Modified by Nicolas Huray for Elasticsearch . -# ### BEGIN INIT INFO # Provides: elasticsearch # Required-Start: $network $remote_fs $named @@ -20,7 +13,7 @@ ### END INIT INFO PATH=/bin:/usr/bin:/sbin:/usr/sbin -NAME=<%= @program_name %> +NAME=elasticsearch DESC="Elasticsearch Server" DEFAULT=/etc/default/$NAME @@ -46,21 +39,11 @@ ES_GROUP=elasticsearch # Directory where the Elasticsearch binary distribution resides ES_HOME=/usr/share/$NAME -# Heap size defaults to 256m min, 1g max -# Set ES_HEAP_SIZE to 50% of available RAM, but no more than 31g -#ES_HEAP_SIZE=2g - -# Heap new generation -#ES_HEAP_NEWSIZE= - -# max direct memory -#ES_DIRECT_SIZE= - # Additional Java OPTS #ES_JAVA_OPTS= # Maximum number of open files -MAX_OPEN_FILES=65535 +MAX_OPEN_FILES=65536 # Maximum amount of locked memory #MAX_LOCKED_MEMORY= @@ -77,9 +60,6 @@ CONF_DIR=/etc/$NAME # Maximum number of VMA (Virtual Memory Areas) a process can own MAX_MAP_COUNT=262144 -# Path to the GC log file -#ES_GC_LOG_FILE=/var/log/elasticsearch/gc.log - # Elasticsearch PID file directory PID_DIR="/var/run/elasticsearch" @@ -99,18 +79,16 @@ fi # Define other required variables PID_FILE="$PID_DIR/$NAME.pid" DAEMON=$ES_HOME/bin/elasticsearch -DAEMON_OPTS="-d -p $PID_FILE --default.path.home=$ES_HOME --default.path.logs=$LOG_DIR --default.path.data=$DATA_DIR --default.path.conf=$CONF_DIR" +DAEMON_OPTS="-d -p $PID_FILE -Edefault.path.logs=$LOG_DIR -Edefault.path.data=$DATA_DIR -Edefault.path.conf=$CONF_DIR" -export ES_HEAP_SIZE -export ES_HEAP_NEWSIZE -export ES_DIRECT_SIZE export ES_JAVA_OPTS -export ES_GC_LOG_FILE export JAVA_HOME export ES_INCLUDE -# Check DAEMON exists -test -x $DAEMON || exit 0 +if [ ! -x "$DAEMON" ]; then + echo "The elasticsearch startup script does not exists or it is not executable, tried: $DAEMON" + exit 1 +fi checkJava() { if [ -x "$JAVA_HOME/bin/java" ]; then @@ -129,11 +107,6 @@ case "$1" in start) checkJava - if [ -n "$MAX_LOCKED_MEMORY" -a -z "$ES_HEAP_SIZE" ]; then - log_failure_msg "MAX_LOCKED_MEMORY is set - ES_HEAP_SIZE must also be set" - exit 1 - fi - log_daemon_msg "Starting $DESC" pid=`pidofproc -p $PID_FILE elasticsearch` @@ -143,9 +116,6 @@ case "$1" in exit 0 fi - # Prepare environment - mkdir -p "$LOG_DIR" "$DATA_DIR" && chown "$ES_USER":"$ES_GROUP" "$LOG_DIR" "$DATA_DIR" - # Ensure that the PID_DIR exists (it is cleaned at OS startup time) if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then mkdir -p "$PID_DIR" && chown "$ES_USER":"$ES_GROUP" "$PID_DIR" @@ -213,7 +183,6 @@ case "$1" in restart|force-reload) if [ -f "$PID_FILE" ]; then $0 stop - sleep 1 fi $0 start ;; diff --git a/templates/debian/systemd_unit.erb b/templates/debian/systemd_unit.erb new file mode 100644 index 000000000..a1ae52f50 --- /dev/null +++ b/templates/debian/systemd_unit.erb @@ -0,0 +1,61 @@ +[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/default/jvm_options.erb b/templates/default/jvm_options.erb new file mode 100644 index 000000000..35d710ca3 --- /dev/null +++ b/templates/default/jvm_options.erb @@ -0,0 +1,3 @@ +## JVM configuration + +<%= @jvm_options %> diff --git a/templates/default/log4j2.properties.erb b/templates/default/log4j2.properties.erb new file mode 100644 index 000000000..d16af9cfc --- /dev/null +++ b/templates/default/log4j2.properties.erb @@ -0,0 +1,78 @@ +status = error + +# log action execution errors for easier debugging +logger.action.name = org.elasticsearch.action +logger.action.level = debug + +appender.console.type = Console +appender.console.name = console +appender.console.layout.type = PatternLayout +appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%m%n + +appender.rolling.type = RollingFile +appender.rolling.name = rolling +appender.rolling.fileName = ${sys:es.logs}.log +appender.rolling.layout.type = PatternLayout +appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%.10000m%n +appender.rolling.filePattern = ${sys:es.logs}-%d{yyyy-MM-dd}.log +appender.rolling.policies.type = Policies +appender.rolling.policies.time.type = TimeBasedTriggeringPolicy +appender.rolling.policies.time.interval = 1 +appender.rolling.policies.time.modulate = true + +rootLogger.level = info +rootLogger.appenderRef.console.ref = console +rootLogger.appenderRef.rolling.ref = rolling + +appender.deprecation_rolling.type = RollingFile +appender.deprecation_rolling.name = deprecation_rolling +appender.deprecation_rolling.fileName = ${sys:es.logs}_deprecation.log +appender.deprecation_rolling.layout.type = PatternLayout +appender.deprecation_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%.10000m%n +appender.deprecation_rolling.filePattern = ${sys:es.logs}_deprecation-%i.log.gz +appender.deprecation_rolling.policies.type = Policies +appender.deprecation_rolling.policies.size.type = SizeBasedTriggeringPolicy +appender.deprecation_rolling.policies.size.size = 1GB +appender.deprecation_rolling.strategy.type = DefaultRolloverStrategy +appender.deprecation_rolling.strategy.max = 4 + +logger.deprecation.name = org.elasticsearch.deprecation +logger.deprecation.level = warn +logger.deprecation.appenderRef.deprecation_rolling.ref = deprecation_rolling +logger.deprecation.additivity = false + +appender.index_search_slowlog_rolling.type = RollingFile +appender.index_search_slowlog_rolling.name = index_search_slowlog_rolling +appender.index_search_slowlog_rolling.fileName = ${sys:es.logs}_index_search_slowlog.log +appender.index_search_slowlog_rolling.layout.type = PatternLayout +appender.index_search_slowlog_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] %marker%.10000m%n +appender.index_search_slowlog_rolling.filePattern = ${sys:es.logs}_index_search_slowlog-%d{yyyy-MM-dd}.log +appender.index_search_slowlog_rolling.policies.type = Policies +appender.index_search_slowlog_rolling.policies.time.type = TimeBasedTriggeringPolicy +appender.index_search_slowlog_rolling.policies.time.interval = 1 +appender.index_search_slowlog_rolling.policies.time.modulate = true + +logger.index_search_slowlog_rolling.name = index.search.slowlog +logger.index_search_slowlog_rolling.level = trace +logger.index_search_slowlog_rolling.appenderRef.index_search_slowlog_rolling.ref = index_search_slowlog_rolling +logger.index_search_slowlog_rolling.additivity = false + +appender.index_indexing_slowlog_rolling.type = RollingFile +appender.index_indexing_slowlog_rolling.name = index_indexing_slowlog_rolling +appender.index_indexing_slowlog_rolling.fileName = ${sys:es.logs}_index_indexing_slowlog.log +appender.index_indexing_slowlog_rolling.layout.type = PatternLayout +appender.index_indexing_slowlog_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] %marker%.10000m%n +appender.index_indexing_slowlog_rolling.filePattern = ${sys:es.logs}_index_indexing_slowlog-%d{yyyy-MM-dd}.log +appender.index_indexing_slowlog_rolling.policies.type = Policies +appender.index_indexing_slowlog_rolling.policies.time.type = TimeBasedTriggeringPolicy +appender.index_indexing_slowlog_rolling.policies.time.interval = 1 +appender.index_indexing_slowlog_rolling.policies.time.modulate = true + +logger.index_indexing_slowlog.name = index.indexing.slowlog.index +logger.index_indexing_slowlog.level = trace +logger.index_indexing_slowlog.appenderRef.index_indexing_slowlog_rolling.ref = index_indexing_slowlog_rolling +logger.index_indexing_slowlog.additivity = false + +<% @logging.each do |k,v| %> +<%= k %>=<%= v %> +<% end %> diff --git a/templates/default/logging.yml.erb b/templates/default/logging.yml.erb deleted file mode 100755 index 3a40215eb..000000000 --- a/templates/default/logging.yml.erb +++ /dev/null @@ -1,104 +0,0 @@ -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# THIS FILE IS MANAGED BY CHEF, DO NOT EDIT MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN! -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# -# See the source file for context and more information: -# -# -# You may also supply your own template to the elasticsearch cookbook's -# elasticsearch_configure resource using the template_logging_yml and cookbook_logging_yml -# parameters defined here: -# -# - -# you can override this using by setting a system property, for example -Des.logger.level=DEBUG -es.logger.level: INFO -rootLogger: ${es.logger.level}, console, file -logger: - # log action execution errors for easier debugging - action: DEBUG - - # deprecation logging, turn to DEBUG to see them - deprecation: INFO, deprecation_log_file - - # reduce the logging for aws, too much is logged under the default INFO - com.amazonaws: WARN - # aws will try to do some sketchy JMX stuff, but its not needed. - com.amazonaws.jmx.SdkMBeanRegistrySupport: ERROR - com.amazonaws.metrics.AwsSdkMetrics: ERROR - - org.apache.http: INFO - - # gateway - #gateway: DEBUG - #index.gateway: DEBUG - - # peer shard recovery - #indices.recovery: DEBUG - - # discovery - #discovery: TRACE - - index.search.slowlog: TRACE, index_search_slow_log_file - index.indexing.slowlog: TRACE, index_indexing_slow_log_file - -# ----- Configuration set by Chef --------------------------------------------- -<% @logging.sort.each do |key, value| %> -logger.<%= key %>: <%= value %> -<% end %> -# ----------------------------------------------------------------------------- - -additivity: - index.search.slowlog: false - index.indexing.slowlog: false - deprecation: false - -appender: - console: - type: console - layout: - type: consolePattern - conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n" - - file: - type: dailyRollingFile - file: ${path.logs}/${cluster.name}.log - datePattern: "'.'yyyy-MM-dd" - layout: - type: pattern - conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %.10000m%n" - - # Use the following log4j-extras RollingFileAppender to enable gzip compression of log files. - # For more information see https://logging.apache.org/log4j/extras/apidocs/org/apache/log4j/rolling/RollingFileAppender.html - #file: - #type: extrasRollingFile - #file: ${path.logs}/${cluster.name}.log - #rollingPolicy: timeBased - #rollingPolicy.FileNamePattern: ${path.logs}/${cluster.name}.log.%d{yyyy-MM-dd}.gz - #layout: - #type: pattern - #conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n" - - deprecation_log_file: - type: dailyRollingFile - file: ${path.logs}/${cluster.name}_deprecation.log - datePattern: "'.'yyyy-MM-dd" - layout: - type: pattern - conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n" - - index_search_slow_log_file: - type: dailyRollingFile - file: ${path.logs}/${cluster.name}_index_search_slowlog.log - datePattern: "'.'yyyy-MM-dd" - layout: - type: pattern - conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n" - - index_indexing_slow_log_file: - type: dailyRollingFile - file: ${path.logs}/${cluster.name}_index_indexing_slowlog.log - datePattern: "'.'yyyy-MM-dd" - layout: - type: pattern - conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n" diff --git a/templates/oracle/initscript.erb b/templates/oracle/initscript.erb index 503b3fafd..b5f6f2ad1 100755 --- a/templates/oracle/initscript.erb +++ b/templates/oracle/initscript.erb @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # elasticsearch # @@ -35,7 +35,7 @@ fi ES_USER="elasticsearch" ES_GROUP="elasticsearch" ES_HOME="/usr/share/elasticsearch" -MAX_OPEN_FILES=65535 +MAX_OPEN_FILES=65536 MAX_MAP_COUNT=262144 LOG_DIR="/var/log/elasticsearch" DATA_DIR="/var/lib/elasticsearch" @@ -44,7 +44,7 @@ CONF_DIR="/etc/elasticsearch" PID_DIR="/var/run/elasticsearch" # Source the default env file -ES_ENV_FILE="/etc/sysconfig/<%= @program_name %>" +ES_ENV_FILE="/etc/sysconfig/elasticsearch" if [ -f "$ES_ENV_FILE" ]; then . "$ES_ENV_FILE" fi @@ -56,14 +56,10 @@ if [ ! -z "$CONF_FILE" ]; then fi exec="$ES_HOME/bin/elasticsearch" -prog="<%= @program_name %>" +prog="elasticsearch" pidfile="$PID_DIR/${prog}.pid" -export ES_HEAP_SIZE -export ES_HEAP_NEWSIZE -export ES_DIRECT_SIZE export ES_JAVA_OPTS -export ES_GC_LOG_FILE export ES_STARTUP_SLEEP_TIME export JAVA_HOME export ES_INCLUDE @@ -75,6 +71,11 @@ if [ -n $USER ] && [ -z $ES_USER ] ; then ES_USER=$USER fi +if [ ! -x "$exec" ]; then + echo "The elasticsearch startup script does not exists or it is not executable, tried: $exec" + exit 1 +fi + checkJava() { if [ -x "$JAVA_HOME/bin/java" ]; then JAVA="$JAVA_HOME/bin/java" @@ -91,10 +92,7 @@ checkJava() { start() { checkJava [ -x $exec ] || exit 5 - if [ -n "$MAX_LOCKED_MEMORY" -a -z "$ES_HEAP_SIZE" ]; then - echo "MAX_LOCKED_MEMORY is set - ES_HEAP_SIZE must also be set" - return 7 - fi + if [ -n "$MAX_OPEN_FILES" ]; then ulimit -n $MAX_OPEN_FILES fi @@ -104,7 +102,6 @@ start() { if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT fi - export ES_GC_LOG_FILE # Ensure that the PID_DIR exists (it is cleaned at OS startup time) if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then @@ -117,7 +114,7 @@ start() { cd $ES_HOME echo -n $"Starting $prog: " # if not running, start it up here, usually something like "daemon $exec" - daemon --user $ES_USER --pidfile $pidfile $exec -p $pidfile -d -Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR -Des.default.path.data=$DATA_DIR -Des.default.path.conf=$CONF_DIR + daemon --user $ES_USER --pidfile $pidfile $exec -p $pidfile -d -Edefault.path.logs=$LOG_DIR -Edefault.path.data=$DATA_DIR -Edefault.path.conf=$CONF_DIR retval=$? echo [ $retval -eq 0 ] && touch $lockfile diff --git a/templates/oracle/systemd_unit.erb b/templates/oracle/systemd_unit.erb new file mode 100644 index 000000000..549520522 --- /dev/null +++ b/templates/oracle/systemd_unit.erb @@ -0,0 +1,61 @@ +[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 503b3fafd..b5f6f2ad1 100644 --- a/templates/redhat/initscript.erb +++ b/templates/redhat/initscript.erb @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # elasticsearch # @@ -35,7 +35,7 @@ fi ES_USER="elasticsearch" ES_GROUP="elasticsearch" ES_HOME="/usr/share/elasticsearch" -MAX_OPEN_FILES=65535 +MAX_OPEN_FILES=65536 MAX_MAP_COUNT=262144 LOG_DIR="/var/log/elasticsearch" DATA_DIR="/var/lib/elasticsearch" @@ -44,7 +44,7 @@ CONF_DIR="/etc/elasticsearch" PID_DIR="/var/run/elasticsearch" # Source the default env file -ES_ENV_FILE="/etc/sysconfig/<%= @program_name %>" +ES_ENV_FILE="/etc/sysconfig/elasticsearch" if [ -f "$ES_ENV_FILE" ]; then . "$ES_ENV_FILE" fi @@ -56,14 +56,10 @@ if [ ! -z "$CONF_FILE" ]; then fi exec="$ES_HOME/bin/elasticsearch" -prog="<%= @program_name %>" +prog="elasticsearch" pidfile="$PID_DIR/${prog}.pid" -export ES_HEAP_SIZE -export ES_HEAP_NEWSIZE -export ES_DIRECT_SIZE export ES_JAVA_OPTS -export ES_GC_LOG_FILE export ES_STARTUP_SLEEP_TIME export JAVA_HOME export ES_INCLUDE @@ -75,6 +71,11 @@ if [ -n $USER ] && [ -z $ES_USER ] ; then ES_USER=$USER fi +if [ ! -x "$exec" ]; then + echo "The elasticsearch startup script does not exists or it is not executable, tried: $exec" + exit 1 +fi + checkJava() { if [ -x "$JAVA_HOME/bin/java" ]; then JAVA="$JAVA_HOME/bin/java" @@ -91,10 +92,7 @@ checkJava() { start() { checkJava [ -x $exec ] || exit 5 - if [ -n "$MAX_LOCKED_MEMORY" -a -z "$ES_HEAP_SIZE" ]; then - echo "MAX_LOCKED_MEMORY is set - ES_HEAP_SIZE must also be set" - return 7 - fi + if [ -n "$MAX_OPEN_FILES" ]; then ulimit -n $MAX_OPEN_FILES fi @@ -104,7 +102,6 @@ start() { if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT fi - export ES_GC_LOG_FILE # Ensure that the PID_DIR exists (it is cleaned at OS startup time) if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then @@ -117,7 +114,7 @@ start() { cd $ES_HOME echo -n $"Starting $prog: " # if not running, start it up here, usually something like "daemon $exec" - daemon --user $ES_USER --pidfile $pidfile $exec -p $pidfile -d -Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR -Des.default.path.data=$DATA_DIR -Des.default.path.conf=$CONF_DIR + daemon --user $ES_USER --pidfile $pidfile $exec -p $pidfile -d -Edefault.path.logs=$LOG_DIR -Edefault.path.data=$DATA_DIR -Edefault.path.conf=$CONF_DIR retval=$? echo [ $retval -eq 0 ] && touch $lockfile diff --git a/templates/redhat/systemd_unit.erb b/templates/redhat/systemd_unit.erb new file mode 100644 index 000000000..549520522 --- /dev/null +++ b/templates/redhat/systemd_unit.erb @@ -0,0 +1,61 @@ +[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 a908c7fc9..f04008ba7 100755 --- a/templates/ubuntu/initscript.erb +++ b/templates/ubuntu/initscript.erb @@ -1,14 +1,7 @@ -#!/bin/sh +#!/bin/bash # # /etc/init.d/elasticsearch -- startup script for Elasticsearch # -# Written by Miquel van Smoorenburg . -# Modified for Debian GNU/Linux by Ian Murdock . -# Modified for Tomcat by Stefan Gybas . -# Modified for Tomcat6 by Thierry Carrez . -# Additional improvements by Jason Brittain . -# Modified by Nicolas Huray for Elasticsearch . -# ### BEGIN INIT INFO # Provides: elasticsearch # Required-Start: $network $remote_fs $named @@ -20,7 +13,7 @@ ### END INIT INFO PATH=/bin:/usr/bin:/sbin:/usr/sbin -NAME=<%= @program_name %> +NAME=elasticsearch DESC="Elasticsearch Server" DEFAULT=/etc/default/$NAME @@ -46,21 +39,11 @@ ES_GROUP=elasticsearch # Directory where the Elasticsearch binary distribution resides ES_HOME=/usr/share/$NAME -# Heap size defaults to 256m min, 1g max -# Set ES_HEAP_SIZE to 50% of available RAM, but no more than 31g -#ES_HEAP_SIZE=2g - -# Heap new generation -#ES_HEAP_NEWSIZE= - -# max direct memory -#ES_DIRECT_SIZE= - # Additional Java OPTS #ES_JAVA_OPTS= # Maximum number of open files -MAX_OPEN_FILES=65535 +MAX_OPEN_FILES=65536 # Maximum amount of locked memory #MAX_LOCKED_MEMORY= @@ -77,9 +60,6 @@ CONF_DIR=/etc/$NAME # Maximum number of VMA (Virtual Memory Areas) a process can own MAX_MAP_COUNT=262144 -# Path to the GC log file -#ES_GC_LOG_FILE=/var/log/elasticsearch/gc.log - # Elasticsearch PID file directory PID_DIR="/var/run/elasticsearch" @@ -99,18 +79,16 @@ fi # Define other required variables PID_FILE="$PID_DIR/$NAME.pid" DAEMON=$ES_HOME/bin/elasticsearch -DAEMON_OPTS="-d -p $PID_FILE --default.path.home=$ES_HOME --default.path.logs=$LOG_DIR --default.path.data=$DATA_DIR --default.path.conf=$CONF_DIR" +DAEMON_OPTS="-d -p $PID_FILE -Edefault.path.logs=$LOG_DIR -Edefault.path.data=$DATA_DIR -Edefault.path.conf=$CONF_DIR" -export ES_HEAP_SIZE -export ES_HEAP_NEWSIZE -export ES_DIRECT_SIZE export ES_JAVA_OPTS -export ES_GC_LOG_FILE export JAVA_HOME export ES_INCLUDE -# Check DAEMON exists -test -x $DAEMON || exit 0 +if [ ! -x "$DAEMON" ]; then + echo "The elasticsearch startup script does not exists or it is not executable, tried: $DAEMON" + exit 1 +fi checkJava() { if [ -x "$JAVA_HOME/bin/java" ]; then @@ -129,11 +107,6 @@ case "$1" in start) checkJava - if [ -n "$MAX_LOCKED_MEMORY" -a -z "$ES_HEAP_SIZE" ]; then - log_failure_msg "MAX_LOCKED_MEMORY is set - ES_HEAP_SIZE must also be set" - exit 1 - fi - log_daemon_msg "Starting $DESC" pid=`pidofproc -p $PID_FILE elasticsearch` @@ -143,9 +116,6 @@ case "$1" in exit 0 fi - # Prepare environment - mkdir -p "$LOG_DIR" "$DATA_DIR" && chown "$ES_USER":"$ES_GROUP" "$LOG_DIR" "$DATA_DIR" - # Ensure that the PID_DIR exists (it is cleaned at OS startup time) if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then mkdir -p "$PID_DIR" && chown "$ES_USER":"$ES_GROUP" "$PID_DIR" @@ -213,7 +183,6 @@ case "$1" in restart|force-reload) if [ -f "$PID_FILE" ]; then $0 stop - sleep 1 fi $0 start ;; diff --git a/templates/ubuntu/systemd_unit.erb b/templates/ubuntu/systemd_unit.erb new file mode 100644 index 000000000..a1ae52f50 --- /dev/null +++ b/templates/ubuntu/systemd_unit.erb @@ -0,0 +1,61 @@ +[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 415a8d461..32a3dbacb 100644 --- a/test/fixtures/cookbooks/elasticsearch_test/recipes/default_with_plugins.rb +++ b/test/fixtures/cookbooks/elasticsearch_test/recipes/default_with_plugins.rb @@ -22,16 +22,8 @@ service_actions [:enable, :start] end -# by default, no plugins, but we do one here. -elasticsearch_plugin 'head' do - url 'mobz/elasticsearch-head' - notifies :restart, 'elasticsearch_service[elasticsearch]', :delayed -end - -# remove an installed plugin -elasticsearch_plugin 'kopf' do - url 'lmenezes/elasticsearch-kopf' - action [:install, :remove] +# by default, no plugins, but we do the x-pack +elasticsearch_plugin 'x-pack' do notifies :restart, 'elasticsearch_service[elasticsearch]', :delayed end diff --git a/test/fixtures/cookbooks/elasticsearch_test/recipes/doubleinstances.rb b/test/fixtures/cookbooks/elasticsearch_test/recipes/doubleinstances.rb index b9fe06dda..60f22784b 100644 --- a/test/fixtures/cookbooks/elasticsearch_test/recipes/doubleinstances.rb +++ b/test/fixtures/cookbooks/elasticsearch_test/recipes/doubleinstances.rb @@ -11,11 +11,10 @@ type :package end -elasticsearch_plugin 'elasticsearch_head' do - instance_name 'alpha' - url 'mobz/elasticsearch-head' +elasticsearch_plugin 'elasticsearch_xpack' do + instance_name 'x-pack' # notifies :restart, "elasticsearch_service[elasticsearch]", :delayed - not_if { ::File.exist?('/usr/share/elasticsearch/plugins/head') } + not_if { ::File.exist?('/usr/share/elasticsearch/plugins/x-pack') } end settings = { diff --git a/test/fixtures/cookbooks/elasticsearch_test/recipes/package.rb b/test/fixtures/cookbooks/elasticsearch_test/recipes/package.rb index 2aa051002..9fce36907 100644 --- a/test/fixtures/cookbooks/elasticsearch_test/recipes/package.rb +++ b/test/fixtures/cookbooks/elasticsearch_test/recipes/package.rb @@ -39,9 +39,8 @@ instance_name 'special_package_instance' end -elasticsearch_plugin 'head' do +elasticsearch_plugin 'x-pack' do instance_name 'special_package_instance' - url 'mobz/elasticsearch-head' end elasticsearch_service 'elasticsearch-crazy' do diff --git a/test/fixtures/cookbooks/elasticsearch_test/recipes/shieldwatcher.rb b/test/fixtures/cookbooks/elasticsearch_test/recipes/shieldwatcher.rb deleted file mode 100644 index fc64474d7..000000000 --- a/test/fixtures/cookbooks/elasticsearch_test/recipes/shieldwatcher.rb +++ /dev/null @@ -1,11 +0,0 @@ -# Cookbook Name:: elasticsearch_test -# Recipe:: shieldwatcher - -include_recipe "#{cookbook_name}::default_with_plugins" - -# test these since they need to write to 'bin' directory -%w(license shield watcher).each do |plugin_name| - elasticsearch_plugin plugin_name do - notifies :restart, 'elasticsearch_service[elasticsearch]', :delayed - end -end diff --git a/test/fixtures/cookbooks/elasticsearch_test/recipes/tarball.rb b/test/fixtures/cookbooks/elasticsearch_test/recipes/tarball.rb index 8ffce2637..6ecdce198 100644 --- a/test/fixtures/cookbooks/elasticsearch_test/recipes/tarball.rb +++ b/test/fixtures/cookbooks/elasticsearch_test/recipes/tarball.rb @@ -46,8 +46,7 @@ instance_name 'special_tarball_instance' end -elasticsearch_plugin 'head' do - url 'mobz/elasticsearch-head' +elasticsearch_plugin 'x-pack' do instance_name 'special_tarball_instance' end diff --git a/test/integration/chef-12.13.37/serverspec/default_spec.rb b/test/integration/chef-12.13.37/serverspec/default_spec.rb index 72a418e16..7c1a56ef1 100644 --- a/test/integration/chef-12.13.37/serverspec/default_spec.rb +++ b/test/integration/chef-12.13.37/serverspec/default_spec.rb @@ -4,7 +4,7 @@ it_behaves_like 'elasticsearch user' it_behaves_like 'elasticsearch install' it_behaves_like 'elasticsearch configure' - it_behaves_like 'elasticsearch plugin', 'head' + it_behaves_like 'elasticsearch plugin', 'x-pack' it_behaves_like 'elasticsearch service' it_behaves_like 'chef version', '12.13.37' diff --git a/test/integration/chef-12.14.89/serverspec/default_spec.rb b/test/integration/chef-12.14.89/serverspec/default_spec.rb index f71a5ed1f..18b24492d 100644 --- a/test/integration/chef-12.14.89/serverspec/default_spec.rb +++ b/test/integration/chef-12.14.89/serverspec/default_spec.rb @@ -4,7 +4,7 @@ it_behaves_like 'elasticsearch user' it_behaves_like 'elasticsearch install' it_behaves_like 'elasticsearch configure' - it_behaves_like 'elasticsearch plugin', 'head' + it_behaves_like 'elasticsearch plugin', 'x-pack' it_behaves_like 'elasticsearch service' it_behaves_like 'chef version', '12.14.89' diff --git a/test/integration/helpers/serverspec/configure_examples.rb b/test/integration/helpers/serverspec/configure_examples.rb index aa38f579f..0c6d3b297 100644 --- a/test/integration/helpers/serverspec/configure_examples.rb +++ b/test/integration/helpers/serverspec/configure_examples.rb @@ -19,18 +19,26 @@ ] expected_environment = args[:env] || [ + 'CONF_DIR=.+', + 'DATA_DIR=.+', + 'ES_GROUP=.+', 'ES_HOME=.+', + 'ES_STARTUP_SLEEP_TIME=.+', 'ES_USER=.+', - 'ES_HEAP_SIZE="?[0-9]+m"?', - 'ES_JAVA_OPTS=', - '-server', - 'CONF_DIR=\/.+', - '-Xss256k', - 'UseParNewGC', - 'UseConcMarkSweepGC', - 'CMSInitiatingOccupancyFraction=75', - 'UseCMSInitiatingOccupancyOnly', - 'HeapDumpOnOutOfMemoryError' + 'LOG_DIR=.+', + 'MAX_LOCKED_MEMORY=.+', + 'MAX_MAP_COUNT=.+', + 'MAX_OPEN_FILES=.+', + 'PID_DIR=.+', + 'RESTART_ON_UPGRADE=.+' + ] + + expected_jvm_options = args[:jvmopts] || [ + 'server', + 'HeapDumpOnOutOfMemoryError', + 'DisableExplicitGC', + 'AlwaysPreTouch', + 'java.awt.headless=true' ] [path_conf, path_data, path_logs].each do |p| @@ -62,18 +70,23 @@ end end - describe file("#{path_conf}/logging.yml") do + describe file("#{path_conf}/jvm.options") do it { should be_file } it { should be_mode 644 } it { should be_owned_by expected_user } it { should be_grouped_into expected_group } - [ - 'Configuration set by Chef', - 'es.logger.level: INFO', - 'rootLogger: \$\{es.logger.level\}, console, file' - ].each do |line| - its(:content) { should match(/#{line}/) } + expected_jvm_options.each do |line| + its(:content) { should contain(/#{line}/) } end end + + describe file("#{path_conf}/log4j2.properties") do + it { should be_file } + it { should be_mode 644 } + it { should be_owned_by expected_user } + it { should be_grouped_into expected_group } + + its(:content) { should match(/logger.action.name = org.elasticsearch.action/) } + end end diff --git a/test/integration/helpers/serverspec/plugin_examples.rb b/test/integration/helpers/serverspec/plugin_examples.rb index 4fae01eb1..87a645600 100644 --- a/test/integration/helpers/serverspec/plugin_examples.rb +++ b/test/integration/helpers/serverspec/plugin_examples.rb @@ -6,6 +6,7 @@ expected_home = args[:home] || (package? ? '/usr/share/elasticsearch' : '/usr/local/elasticsearch') expected_plugin = args[:plugin] || "#{expected_home}/plugins/#{plugin_name}" expected_response_code = args[:response_code] || 200 + auth_data = args[:auth_data] || 'elastic:changeme@' describe file(expected_plugin) do it { should be_directory } @@ -13,7 +14,13 @@ it { should be_grouped_into expected_group } end - describe command("curl -s -o /dev/null -w \"%{http_code}\" http://127.0.0.1:9200/_plugin/#{plugin_name}/") do + describe command("curl -s -o /dev/null -w \"%{http_code}\" http://#{auth_data}127.0.0.1:9200/_nodes/plugins") do its(:stdout) { should match(/#{expected_response_code}/) } end + + if expected_response_code == 200 + describe command("curl -v http://#{auth_data}127.0.0.1:9200/_nodes/plugins") do + its(:stdout) { should match(/#{plugin_name}/) } + end + end end diff --git a/test/integration/helpers/serverspec/service_examples.rb b/test/integration/helpers/serverspec/service_examples.rb index f7c7d5b5f..633764b44 100644 --- a/test/integration/helpers/serverspec/service_examples.rb +++ b/test/integration/helpers/serverspec/service_examples.rb @@ -8,7 +8,7 @@ it { should be_running } end - describe command('curl http://localhost:9200') do + describe command('curl http://elastic:changeme@localhost:9200') do its(:stdout) { should match(/#{content_match}/) } end end diff --git a/test/integration/package/serverspec/default_spec.rb b/test/integration/package/serverspec/default_spec.rb index c20060b08..5229cce54 100644 --- a/test/integration/package/serverspec/default_spec.rb +++ b/test/integration/package/serverspec/default_spec.rb @@ -4,7 +4,7 @@ it_behaves_like 'elasticsearch user' it_behaves_like 'elasticsearch install' it_behaves_like 'elasticsearch configure' - it_behaves_like 'elasticsearch plugin', 'head' + it_behaves_like 'elasticsearch plugin', 'x-pack' it_behaves_like 'elasticsearch service' end diff --git a/test/integration/shieldwatcher/serverspec/default_spec.rb b/test/integration/shieldwatcher/serverspec/default_spec.rb index 10a1c8666..fc1e6054b 100644 --- a/test/integration/shieldwatcher/serverspec/default_spec.rb +++ b/test/integration/shieldwatcher/serverspec/default_spec.rb @@ -6,8 +6,8 @@ it_behaves_like 'elasticsearch configure' # because shield, these now should return failures - it_behaves_like 'elasticsearch plugin', 'head', response_code: 401 - it_behaves_like 'elasticsearch service', 'elasticsearch', content: 'missing authentication' + it_behaves_like 'elasticsearch plugin', 'x-pack', auth_data: '', response_code: 401 + it_behaves_like 'elasticsearch service', 'elasticsearch', auth_data: '', content: 'missing authentication' end describe package('elasticsearch') do diff --git a/test/integration/tarball/serverspec/default_spec.rb b/test/integration/tarball/serverspec/default_spec.rb index f275dfe58..62a0b9a7c 100644 --- a/test/integration/tarball/serverspec/default_spec.rb +++ b/test/integration/tarball/serverspec/default_spec.rb @@ -4,6 +4,6 @@ it_behaves_like 'elasticsearch user' it_behaves_like 'elasticsearch install' it_behaves_like 'elasticsearch configure' - it_behaves_like 'elasticsearch plugin', 'head' + it_behaves_like 'elasticsearch plugin', 'x-pack' it_behaves_like 'elasticsearch service' end