From 7684cdc82b1cf4deb3de01c2f3d72e81fd41d64a Mon Sep 17 00:00:00 2001 From: Jacob Dearing Date: Thu, 23 Jul 2015 05:47:21 -0500 Subject: [PATCH 01/10] testing new formats --- .kitchen.yml | 11 +- Gemfile | 5 + libraries/provider_elasticsearch.rb | 72 +++++++ libraries/provider_elasticsearch_config.rb | 33 ---- libraries/provider_elasticsearch_service.rb | 73 -------- ...r_kibana_service.rb => provider_kibana.rb} | 30 +-- libraries/resource_elasticsearch.rb | 32 ++++ libraries/resource_elasticsearch_service.rb | 11 -- ...e_kibana_service.rb => resource_kibana.rb} | 8 +- .../elasticsearch/elasticsearch.initd.erb | 176 ------------------ .../elasticsearch/elasticsearch.sysconfig.erb | 0 .../elasticsearch/elasticsearch.yml.erb | 0 .../elasticsearch/sv-elasticsearch-run.erb | 6 + .../kibana/kibana.initd.erb | 0 .../{centos => default}/kibana/kibana.yml.erb | 0 .../logrotate/logstash.erb | 0 .../logstash-forwarder.conf.erb | 0 .../logstash-forwarder/logstash-forwarder.erb | 0 .../logstash-forwarder.initd.erb | 0 .../logstash/conf.d/00-input.conf.erb | 0 .../logstash/conf.d/10-syslog.conf.erb | 0 .../logstash/conf.d/99-output.conf.erb | 0 .../logstash/logging.yml.erb | 0 .../logstash/logstash.initd.erb | 0 .../logstash/logstash.sysconfig.erb | 0 templates/default/sv-elasticsearch-run.erb | 6 + .../{centos => default}/sv-kibana-run.erb | 0 test/cookbooks/elktest/metadata.rb | 2 +- test/cookbooks/elktest/recipes/default.rb | 16 +- .../elktest/recipes/elasticsearch.rb | 7 +- test/cookbooks/elktest/recipes/kibana.rb | 6 +- 31 files changed, 165 insertions(+), 329 deletions(-) mode change 100755 => 100644 .kitchen.yml create mode 100644 libraries/provider_elasticsearch.rb mode change 100755 => 100644 libraries/provider_elasticsearch_config.rb delete mode 100755 libraries/provider_elasticsearch_service.rb rename libraries/{provider_kibana_service.rb => provider_kibana.rb} (66%) create mode 100644 libraries/resource_elasticsearch.rb delete mode 100755 libraries/resource_elasticsearch_service.rb rename libraries/{resource_kibana_service.rb => resource_kibana.rb} (79%) mode change 100755 => 100644 delete mode 100644 templates/centos/elasticsearch/elasticsearch.initd.erb rename templates/{centos => default}/elasticsearch/elasticsearch.sysconfig.erb (100%) rename templates/{centos => default}/elasticsearch/elasticsearch.yml.erb (100%) create mode 100644 templates/default/elasticsearch/sv-elasticsearch-run.erb rename templates/{centos => default}/kibana/kibana.initd.erb (100%) rename templates/{centos => default}/kibana/kibana.yml.erb (100%) rename templates/{centos => default}/logrotate/logstash.erb (100%) rename templates/{centos => default}/logstash-forwarder/logstash-forwarder.conf.erb (100%) rename templates/{centos => default}/logstash-forwarder/logstash-forwarder.erb (100%) rename templates/{centos => default}/logstash-forwarder/logstash-forwarder.initd.erb (100%) rename templates/{centos => default}/logstash/conf.d/00-input.conf.erb (100%) rename templates/{centos => default}/logstash/conf.d/10-syslog.conf.erb (100%) rename templates/{centos => default}/logstash/conf.d/99-output.conf.erb (100%) rename templates/{centos => default}/logstash/logging.yml.erb (100%) rename templates/{centos => default}/logstash/logstash.initd.erb (100%) rename templates/{centos => default}/logstash/logstash.sysconfig.erb (100%) create mode 100644 templates/default/sv-elasticsearch-run.erb rename templates/{centos => default}/sv-kibana-run.erb (100%) mode change 100755 => 100644 test/cookbooks/elktest/recipes/elasticsearch.rb diff --git a/.kitchen.yml b/.kitchen.yml old mode 100755 new mode 100644 index 2e992eb..e265296 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -1,16 +1,21 @@ --- -driver_plugin: vagrant +driver: + name: docker +# dockerfile: test/Dockerfile-centos66 +# provision_command: curl -L http://www.chef.io/chef/install.sh | bash +driver_config: + publish_all: true platforms: - name: centos-6.6 provisioner: name: chef_zero - require_chef_omnibus: '12.4.0' + require_chef_omnibus: '12.4.1' data_bags_path: 'test/integration/data_bags' suites: - name: default run_list: - - recipe[elktest] \ No newline at end of file + - recipe[elktest] diff --git a/Gemfile b/Gemfile index 3017623..c209eb8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,8 @@ source 'https://rubygems.org' gem 'berkshelf' + +group :integration do + gem 'test-kitchen' + gem 'kitchen-docker' +end diff --git a/libraries/provider_elasticsearch.rb b/libraries/provider_elasticsearch.rb new file mode 100644 index 0000000..e0d3546 --- /dev/null +++ b/libraries/provider_elasticsearch.rb @@ -0,0 +1,72 @@ +class Chef + class Provider + class Elasticsearch < Chef::Provider::LWRPBase + use_inline_resources if defined?(use_inline_resources) + + provides :elasticsearch + + service_name = 'elasticsearch' + + action :install do + user new_resource.user + group new_resource.group + + ark service_name do + checksum new_resource.checksum + group new_resource.group + has_binaries new_resource.has_binaries + owner new_resource.user + prefix_root new_resource.path + url new_resource.url + version new_resource.version + end + + runit_service service_name do + default_logger true + owner new_resource.user + group new_resource.user + cookbook new_resource.source + action [:create, :enable] + end + end + + action :remove do + service service_name do + action :stop + end + end + + # SERVICES + + action :enable do + service service_name do + action :enable + end + end + + action :disable do + service service_name do + action :disable + end + end + + action :start do + service service_name do + action :start + end + end + + action :stop do + service service_name do + action :stop + end + end + + action :restart do + service service_name do + action [:stop, :start] + end + end + end + end +end diff --git a/libraries/provider_elasticsearch_config.rb b/libraries/provider_elasticsearch_config.rb old mode 100755 new mode 100644 index 5f560e7..d4fc93d --- a/libraries/provider_elasticsearch_config.rb +++ b/libraries/provider_elasticsearch_config.rb @@ -32,44 +32,11 @@ class ElasticsearchConfig < Chef::Provider::LWRPBase 'work_dir' => new_resource.work_dir } end - - # TODO: probably better to let it source the sysconfig template instead - template '/etc/init.d/elasticsearch' do - source 'elasticsearch/elasticsearch.initd.erb' - owner 'root' - group 'root' - mode '0755' - cookbook new_resource.source - variables options: { - 'conf_dir' => new_resource.conf_dir, - 'conf_file' => new_resource.conf_file, - 'data_dir' => new_resource.data_dir, - 'es_direct_size' => new_resource.es_direct_size, - 'es_group' => new_resource.es_group, - 'es_heap_newsize' => new_resource.es_heap_newsize, - 'es_heap_size' => new_resource.es_heap_size, - 'es_home' => new_resource.es_home, - 'es_java_opts' => new_resource.es_java_opts, - 'es_user' => new_resource.es_user, - 'log_dir' => new_resource.log_dir, - 'max_locked_memory' => new_resource.max_locked_memory, - 'max_map_count' => new_resource.max_map_count, - 'max_open_files' => new_resource.max_open_files, - 'pid_dir' => new_resource.pid_dir, - 'restart_on_upgrade' => new_resource.restart_on_upgrade, - 'work_dir' => new_resource.work_dir - } - end end - action :delete do file '/etc/sysconfig/elasticsearc' do action :delete end - - file '/etc/init.d/elasticsearch' do - action :delete - end end end end diff --git a/libraries/provider_elasticsearch_service.rb b/libraries/provider_elasticsearch_service.rb deleted file mode 100755 index 04159a2..0000000 --- a/libraries/provider_elasticsearch_service.rb +++ /dev/null @@ -1,73 +0,0 @@ -class Chef - class Provider - class ElasticsearchService < Chef::Provider::LWRPBase - use_inline_resources if defined?(use_inline_resources) - - provides :elasticsearch_service - - service_name = 'elasticsearch' - - action :create do - install_repository - package service_name do - action :install - end - end - - action :delete do - service service_name do - action :stop - end - package service_name do - action :remove - end - remove_repository - end - - action :enable do - service service_name do - action :enable - end - end - - action :disable do - service service_name do - action :disable - end - end - - action :restart do - service service_name do - action :restart - end - end - - action :start do - service service_name do - action :start - end - end - - action :stop do - service service_name do - action :stop - end - end - - def install_repository - yum_repository 'elasticsearch-1.6' do - description 'Elasticsearch repository for 1.6.x packages' - baseurl 'http://packages.elastic.co/elasticsearch/1.6/centos' - gpgkey 'https://packages.elastic.co/GPG-KEY-elasticsearch' - action :create - end - end - - def remove_repository - yum_repository 'elasticsearch-1.6' do - action :delete - end - end - end - end -end diff --git a/libraries/provider_kibana_service.rb b/libraries/provider_kibana.rb similarity index 66% rename from libraries/provider_kibana_service.rb rename to libraries/provider_kibana.rb index 8eee5b6..1b0e240 100644 --- a/libraries/provider_kibana_service.rb +++ b/libraries/provider_kibana.rb @@ -1,15 +1,17 @@ class Chef class Provider - class KibanaService < Chef::Provider::LWRPBase + class Kibana < Chef::Provider::LWRPBase use_inline_resources if defined?(use_inline_resources) - provides :kibana_service + provides :kibana - action :create do + service_name = 'kibana' + + action :install do user new_resource.user group new_resource.group - ark 'kibana' do + ark service_name do checksum new_resource.checksum group new_resource.group has_binaries ['bin/kibana'] @@ -21,45 +23,45 @@ class KibanaService < Chef::Provider::LWRPBase runit_service 'kibana' do default_logger true - owner "kibana" - group "kibana" + owner new_resource.user + group new_resource.group cookbook new_resource.source action [:create, :enable] end end - action :delete do - runit_service 'kibana' do + action :remove do + runit_service service_name do action :stop end end action :enable do - runit_service 'kibana' do + runit_service service_name do action :enable end end action :disable do - runit_service 'kibana' do + runit_service service_name do action :disable end end action :restart do - runit_service 'kibana' do - action [:stop, :start] + runit_service service_name do + action :restart end end action :start do - runit_service 'kibana' do + runit_service service_name do action :start end end action :stop do - runit_service 'kibana' do + runit_service service_name do action :stop end end diff --git a/libraries/resource_elasticsearch.rb b/libraries/resource_elasticsearch.rb new file mode 100644 index 0000000..0263215 --- /dev/null +++ b/libraries/resource_elasticsearch.rb @@ -0,0 +1,32 @@ +require 'chef/resource' + +class Chef + class Resource + class Elasticsearch < Chef::Resource::LWRPBase + resource_name :elasticsearch + default_action :install + actions [:install, :remove, :enable, :disable, :restart, :start, :stop] + + require 'chef/resource' + + # used to target any files/templates; default to self + attribute :source, kind_of: String, default: 'elk' + + # url and sha256 of the archive to download and unpack + attribute :url, kind_of: String, default: 'https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.0.tar.gz' + attribute :checksum, kind_of: String, default: '6fabed2db09e1b88587df15269df328ecef33e155b3c675a2a6d2299bda09c95' + + # ARK tracks verioning by appending the :name with this for symlinking to a path + attribute :version, kind_of: String, default: '1.7.0' + attribute :has_binaries, kind_of: Array, default: ['/bin/elasticsearch'] + attribute :append_env_path, kind_of: [TrueClass, FalseClass], default: false + + # USER/GROUP to install by, also creates users on the OS for them + attribute :user, kind_of: String, default: 'elasticsearch' + attribute :group, kind_of: String, default: 'elasticsearch' + attribute :owner, kind_of: String, default: 'elasticsearch' + + attribute :path, kind_of: String, default: '/opt/elasticsearch' + end + end +end diff --git a/libraries/resource_elasticsearch_service.rb b/libraries/resource_elasticsearch_service.rb deleted file mode 100755 index 76cbb6b..0000000 --- a/libraries/resource_elasticsearch_service.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'chef/resource' - -class Chef - class Resource - class ElasticsearchService < Chef::Resource::LWRPBase - resource_name :elasticsearch_service - default_action :create - actions [:create, :delete, :enable, :disable, :restart, :start, :stop] - end - end -end diff --git a/libraries/resource_kibana_service.rb b/libraries/resource_kibana.rb old mode 100755 new mode 100644 similarity index 79% rename from libraries/resource_kibana_service.rb rename to libraries/resource_kibana.rb index 185974e..12ef25d --- a/libraries/resource_kibana_service.rb +++ b/libraries/resource_kibana.rb @@ -2,10 +2,10 @@ class Chef class Resource - class KibanaService < Chef::Resource::LWRPBase - resource_name :kibana_service - default_action :create - actions [:create, :delete, :enable, :disable, :restart, :start, :stop] + class Kibana < Chef::Resource::LWRPBase + resource_name :kibana + default_action :install + actions [:install, :remove, :enable, :disable, :restart, :start, :stop] attribute :checksum, kind_of: String, default: '6f42d25f337fd49f38e2af81b9ab6e0c987a199a8c0b2e1410d072f812cb4520' attribute :group, kind_of: String, default: 'kibana' diff --git a/templates/centos/elasticsearch/elasticsearch.initd.erb b/templates/centos/elasticsearch/elasticsearch.initd.erb deleted file mode 100644 index 7cac7bf..0000000 --- a/templates/centos/elasticsearch/elasticsearch.initd.erb +++ /dev/null @@ -1,176 +0,0 @@ -#!/bin/sh -# -# elasticsearch -# -# chkconfig: 2345 80 20 -# description: Starts and stops a single elasticsearch instance on this system -# - -### BEGIN INIT INFO -# Provides: Elasticsearch -# Required-Start: $network $named -# Required-Stop: $network $named -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: This service manages the elasticsearch daemon -# Description: Elasticsearch is a very scalable, schema-free and high-performance search solution supporting multi-tenancy and near realtime search. -### END INIT INFO - -# -# init.d / servicectl compatibility (openSUSE) -# -if [ -f /etc/rc.status ]; then - . /etc/rc.status - rc_reset -fi - -# -# Source function library. -# -if [ -f /etc/rc.d/init.d/functions ]; then - . /etc/rc.d/init.d/functions -fi - -# Sets the default values for elasticsearch variables used in this script -ES_USER=<%= @options['es_user'] %> -ES_GROUP=<%= @options['es_group'] %> -ES_HOME=<%= @options['es_home'] %> -MAX_OPEN_FILES=<%= @options['max_open_files'] %> -MAX_MAP_COUNT=<%= @options['max_map_count'] %> -LOG_DIR=<%= @options['log_dir'] %> -DATA_DIR=<%= @options['data_dir'] %> -WORK_DIR=<%= @options['work_dir'] %> -CONF_DIR=<%= @options['conf_dir'] %> -CONF_FILE=<%= @options['conf_file'] %> -PID_DIR=<%= @options['pid_dir'] %> - -# Source the default env file -ES_ENV_FILE="/etc/sysconfig/elasticsearch" -if [ -f "$ES_ENV_FILE" ]; then - . "$ES_ENV_FILE" -fi - -exec="$ES_HOME/bin/elasticsearch" -prog="elasticsearch" -pidfile="$PID_DIR/${prog}.pid" - -export ES_HEAP_SIZE -export ES_HEAP_NEWSIZE -export ES_DIRECT_SIZE -export ES_JAVA_OPTS -export JAVA_HOME - -lockfile=/var/lock/subsys/$prog - -# backwards compatibility for old config sysconfig files, pre 0.90.1 -if [ -n $USER ] && [ -z $ES_USER ] ; then - ES_USER=$USER -fi - -checkJava() { - if [ -x "$JAVA_HOME/bin/java" ]; then - JAVA="$JAVA_HOME/bin/java" - else - JAVA=`which java` - fi - - if [ ! -x "$JAVA" ]; then - echo "Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME" - exit 1 - fi -} - -start() { - checkJava - [ -x $exec ] || exit 5 - [ -f $CONF_FILE ] || exit 6 - 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 - if [ -n "$MAX_LOCKED_MEMORY" ]; then - ulimit -l $MAX_LOCKED_MEMORY - fi - 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 - if [ -n "$WORK_DIR" ]; then - mkdir -p "$WORK_DIR" - chown "$ES_USER":"$ES_GROUP" "$WORK_DIR" - fi - 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.work=$WORK_DIR -Des.default.path.conf=$CONF_DIR - retval=$? - echo - [ $retval -eq 0 ] && touch $lockfile - return $retval -} - -stop() { - echo -n $"Stopping $prog: " - # stop it here, often "killproc $prog" - killproc -p $pidfile -d 20 $prog - retval=$? - echo - [ $retval -eq 0 ] && rm -f $lockfile - return $retval -} - -restart() { - stop - start -} - -reload() { - restart -} - -force_reload() { - restart -} - -rh_status() { - # run checks to determine if the service is running or use generic status - status -p $pidfile $prog -} - -rh_status_q() { - rh_status >/dev/null 2>&1 -} - - -case "$1" in - start) - rh_status_q && exit 0 - $1 - ;; - stop) - rh_status_q || exit 0 - $1 - ;; - restart) - $1 - ;; - reload) - rh_status_q || exit 7 - $1 - ;; - force-reload) - force_reload - ;; - status) - rh_status - ;; - condrestart|try-restart) - rh_status_q || exit 0 - restart - ;; - *) - echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" - exit 2 -esac -exit $? diff --git a/templates/centos/elasticsearch/elasticsearch.sysconfig.erb b/templates/default/elasticsearch/elasticsearch.sysconfig.erb similarity index 100% rename from templates/centos/elasticsearch/elasticsearch.sysconfig.erb rename to templates/default/elasticsearch/elasticsearch.sysconfig.erb diff --git a/templates/centos/elasticsearch/elasticsearch.yml.erb b/templates/default/elasticsearch/elasticsearch.yml.erb similarity index 100% rename from templates/centos/elasticsearch/elasticsearch.yml.erb rename to templates/default/elasticsearch/elasticsearch.yml.erb diff --git a/templates/default/elasticsearch/sv-elasticsearch-run.erb b/templates/default/elasticsearch/sv-elasticsearch-run.erb new file mode 100644 index 0000000..2e1fd4e --- /dev/null +++ b/templates/default/elasticsearch/sv-elasticsearch-run.erb @@ -0,0 +1,6 @@ +#!/bin/sh + +cd /opt/elasticsearch +exec 2>&1 + +exec /usr/bin/env elasticsearch diff --git a/templates/centos/kibana/kibana.initd.erb b/templates/default/kibana/kibana.initd.erb similarity index 100% rename from templates/centos/kibana/kibana.initd.erb rename to templates/default/kibana/kibana.initd.erb diff --git a/templates/centos/kibana/kibana.yml.erb b/templates/default/kibana/kibana.yml.erb similarity index 100% rename from templates/centos/kibana/kibana.yml.erb rename to templates/default/kibana/kibana.yml.erb diff --git a/templates/centos/logrotate/logstash.erb b/templates/default/logrotate/logstash.erb similarity index 100% rename from templates/centos/logrotate/logstash.erb rename to templates/default/logrotate/logstash.erb diff --git a/templates/centos/logstash-forwarder/logstash-forwarder.conf.erb b/templates/default/logstash-forwarder/logstash-forwarder.conf.erb similarity index 100% rename from templates/centos/logstash-forwarder/logstash-forwarder.conf.erb rename to templates/default/logstash-forwarder/logstash-forwarder.conf.erb diff --git a/templates/centos/logstash-forwarder/logstash-forwarder.erb b/templates/default/logstash-forwarder/logstash-forwarder.erb similarity index 100% rename from templates/centos/logstash-forwarder/logstash-forwarder.erb rename to templates/default/logstash-forwarder/logstash-forwarder.erb diff --git a/templates/centos/logstash-forwarder/logstash-forwarder.initd.erb b/templates/default/logstash-forwarder/logstash-forwarder.initd.erb similarity index 100% rename from templates/centos/logstash-forwarder/logstash-forwarder.initd.erb rename to templates/default/logstash-forwarder/logstash-forwarder.initd.erb diff --git a/templates/centos/logstash/conf.d/00-input.conf.erb b/templates/default/logstash/conf.d/00-input.conf.erb similarity index 100% rename from templates/centos/logstash/conf.d/00-input.conf.erb rename to templates/default/logstash/conf.d/00-input.conf.erb diff --git a/templates/centos/logstash/conf.d/10-syslog.conf.erb b/templates/default/logstash/conf.d/10-syslog.conf.erb similarity index 100% rename from templates/centos/logstash/conf.d/10-syslog.conf.erb rename to templates/default/logstash/conf.d/10-syslog.conf.erb diff --git a/templates/centos/logstash/conf.d/99-output.conf.erb b/templates/default/logstash/conf.d/99-output.conf.erb similarity index 100% rename from templates/centos/logstash/conf.d/99-output.conf.erb rename to templates/default/logstash/conf.d/99-output.conf.erb diff --git a/templates/centos/logstash/logging.yml.erb b/templates/default/logstash/logging.yml.erb similarity index 100% rename from templates/centos/logstash/logging.yml.erb rename to templates/default/logstash/logging.yml.erb diff --git a/templates/centos/logstash/logstash.initd.erb b/templates/default/logstash/logstash.initd.erb similarity index 100% rename from templates/centos/logstash/logstash.initd.erb rename to templates/default/logstash/logstash.initd.erb diff --git a/templates/centos/logstash/logstash.sysconfig.erb b/templates/default/logstash/logstash.sysconfig.erb similarity index 100% rename from templates/centos/logstash/logstash.sysconfig.erb rename to templates/default/logstash/logstash.sysconfig.erb diff --git a/templates/default/sv-elasticsearch-run.erb b/templates/default/sv-elasticsearch-run.erb new file mode 100644 index 0000000..2e1fd4e --- /dev/null +++ b/templates/default/sv-elasticsearch-run.erb @@ -0,0 +1,6 @@ +#!/bin/sh + +cd /opt/elasticsearch +exec 2>&1 + +exec /usr/bin/env elasticsearch diff --git a/templates/centos/sv-kibana-run.erb b/templates/default/sv-kibana-run.erb similarity index 100% rename from templates/centos/sv-kibana-run.erb rename to templates/default/sv-kibana-run.erb diff --git a/test/cookbooks/elktest/metadata.rb b/test/cookbooks/elktest/metadata.rb index c91096d..5d81c09 100644 --- a/test/cookbooks/elktest/metadata.rb +++ b/test/cookbooks/elktest/metadata.rb @@ -7,4 +7,4 @@ version '0.1.0' depends 'elk' -depends 'runit' \ No newline at end of file +depends 'runit' diff --git a/test/cookbooks/elktest/recipes/default.rb b/test/cookbooks/elktest/recipes/default.rb index a22f48c..f8f854f 100644 --- a/test/cookbooks/elktest/recipes/default.rb +++ b/test/cookbooks/elktest/recipes/default.rb @@ -1,13 +1,15 @@ # test a single node with all three projects -package 'htop' -package 'java-1.8.0-openjdk-headless' -package 'nginx' +# package 'htop' +# package 'java-1.8.0-openjdk-headless' +# package 'nginx' -include_recipe 'runit::default' +package 'tar' +package 'nano' -include_recipe 'elktest::elasticsearch' -include_recipe 'elktest::logstash' -include_recipe 'elktest::logstash_forwarder' +include_recipe 'runit::default' +# include_recipe 'elktest::elasticsearch' +# include_recipe 'elktest::logstash' +# include_recipe 'elktest::logstash_forwarder' include_recipe 'elktest::kibana' diff --git a/test/cookbooks/elktest/recipes/elasticsearch.rb b/test/cookbooks/elktest/recipes/elasticsearch.rb old mode 100755 new mode 100644 index b29f552..c22eef9 --- a/test/cookbooks/elktest/recipes/elasticsearch.rb +++ b/test/cookbooks/elktest/recipes/elasticsearch.rb @@ -1,8 +1,9 @@ -elasticsearch_service 'default' do - action [:create, :start, :enable] + +elasticsearch 'default' do + action [:install, :start, :enable] end elasticsearch_config 'default' do action :create - notifies :restart, 'elasticsearch_service[default]' + notifies :restart, 'elasticsearch[default]' end diff --git a/test/cookbooks/elktest/recipes/kibana.rb b/test/cookbooks/elktest/recipes/kibana.rb index 6d37c11..f2e4a0c 100644 --- a/test/cookbooks/elktest/recipes/kibana.rb +++ b/test/cookbooks/elktest/recipes/kibana.rb @@ -1,9 +1,7 @@ -kibana_service 'default' do - action [:create] -end +kibana 'default' kibana_config 'default' do port 8080 action :create - notifies :restart, 'kibana_service[default]' + notifies :restart, 'kibana[default]' end From 91d80d77410118f149cc96aa3beb35f6b9602773 Mon Sep 17 00:00:00 2001 From: Jacob Dearing Date: Mon, 27 Jul 2015 11:38:10 -0500 Subject: [PATCH 02/10] massive reorg; not complete --- .kitchen.yml | 4 +- libraries/helpers.rb | 21 --- libraries/provider_elasticsearch.rb | 8 +- libraries/provider_elasticsearch_config.rb | 17 +- libraries/provider_kibana.rb | 15 +- libraries/provider_kibana_config.rb | 8 +- libraries/provider_logstash.rb | 65 ++++++++ libraries/provider_logstash_config.rb | 36 ++--- libraries/provider_logstash_forwarder.rb | 70 ++++++++ .../provider_logstash_forwarder_config.rb | 38 ++--- .../provider_logstash_forwarder_service.rb | 73 --------- libraries/provider_logstash_service.rb | 67 -------- libraries/resource_elasticsearch.rb | 3 +- libraries/resource_logstash.rb | 30 ++++ libraries/resource_logstash_config.rb | 4 +- libraries/resource_logstash_forwarder.rb | 18 +++ .../resource_logstash_forwarder_config.rb | 6 +- .../resource_logstash_forwarder_service.rb | 11 -- libraries/resource_logstash_service.rb | 11 -- .../elasticsearch/sv-elasticsearch-run.erb | 6 - templates/default/kibana/kibana.initd.erb | 98 ----------- templates/default/logrotate/logstash.erb | 9 -- .../logstash-forwarder/logstash-forwarder.erb | 6 - .../logstash-forwarder.initd.erb | 151 ----------------- templates/default/logstash/logstash.initd.erb | 152 ------------------ templates/default/sv-elasticsearch-run.erb | 2 +- templates/default/sv-logstash-run.erb | 6 + .../default/sv-logstash_forwarder-run.erb | 6 + test/cookbooks/elktest/recipes/default.rb | 11 +- .../elktest/recipes/elasticsearch.rb | 7 +- test/cookbooks/elktest/recipes/logstash.rb | 16 +- .../elktest/recipes/logstash_forwarder.rb | 10 +- 32 files changed, 277 insertions(+), 708 deletions(-) delete mode 100755 libraries/helpers.rb create mode 100644 libraries/provider_logstash.rb mode change 100755 => 100644 libraries/provider_logstash_config.rb create mode 100644 libraries/provider_logstash_forwarder.rb mode change 100755 => 100644 libraries/provider_logstash_forwarder_config.rb delete mode 100755 libraries/provider_logstash_forwarder_service.rb delete mode 100755 libraries/provider_logstash_service.rb create mode 100644 libraries/resource_logstash.rb mode change 100755 => 100644 libraries/resource_logstash_config.rb create mode 100644 libraries/resource_logstash_forwarder.rb mode change 100755 => 100644 libraries/resource_logstash_forwarder_config.rb delete mode 100755 libraries/resource_logstash_forwarder_service.rb delete mode 100755 libraries/resource_logstash_service.rb delete mode 100644 templates/default/elasticsearch/sv-elasticsearch-run.erb delete mode 100644 templates/default/kibana/kibana.initd.erb delete mode 100755 templates/default/logrotate/logstash.erb delete mode 100755 templates/default/logstash-forwarder/logstash-forwarder.erb delete mode 100755 templates/default/logstash-forwarder/logstash-forwarder.initd.erb delete mode 100755 templates/default/logstash/logstash.initd.erb create mode 100644 templates/default/sv-logstash-run.erb create mode 100644 templates/default/sv-logstash_forwarder-run.erb mode change 100755 => 100644 test/cookbooks/elktest/recipes/logstash.rb mode change 100755 => 100644 test/cookbooks/elktest/recipes/logstash_forwarder.rb diff --git a/.kitchen.yml b/.kitchen.yml index e265296..d020f8a 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -1,6 +1,6 @@ --- -driver: - name: docker +#driver: +# name: docker # dockerfile: test/Dockerfile-centos66 # provision_command: curl -L http://www.chef.io/chef/install.sh | bash diff --git a/libraries/helpers.rb b/libraries/helpers.rb deleted file mode 100755 index ace9957..0000000 --- a/libraries/helpers.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'chef' - -module Elasticsearch - module Helpers - end -end - -module Logstash - module Helpers - end -end - -module LogstashForwarder - module Helpers - end -end - -module Kibana - module Helpers - end -end diff --git a/libraries/provider_elasticsearch.rb b/libraries/provider_elasticsearch.rb index e0d3546..bb1f4fb 100644 --- a/libraries/provider_elasticsearch.rb +++ b/libraries/provider_elasticsearch.rb @@ -4,7 +4,6 @@ class Elasticsearch < Chef::Provider::LWRPBase use_inline_resources if defined?(use_inline_resources) provides :elasticsearch - service_name = 'elasticsearch' action :install do @@ -16,6 +15,7 @@ class Elasticsearch < Chef::Provider::LWRPBase group new_resource.group has_binaries new_resource.has_binaries owner new_resource.user + prefix_bin new_resource.prefix_bin prefix_root new_resource.path url new_resource.url version new_resource.version @@ -24,7 +24,7 @@ class Elasticsearch < Chef::Provider::LWRPBase runit_service service_name do default_logger true owner new_resource.user - group new_resource.user + group new_resource.group cookbook new_resource.source action [:create, :enable] end @@ -36,7 +36,7 @@ class Elasticsearch < Chef::Provider::LWRPBase end end - # SERVICES + ## SERVICES action :enable do service service_name do @@ -64,7 +64,7 @@ class Elasticsearch < Chef::Provider::LWRPBase action :restart do service service_name do - action [:stop, :start] + action :restart end end end diff --git a/libraries/provider_elasticsearch_config.rb b/libraries/provider_elasticsearch_config.rb index d4fc93d..5869e7b 100644 --- a/libraries/provider_elasticsearch_config.rb +++ b/libraries/provider_elasticsearch_config.rb @@ -6,10 +6,16 @@ class ElasticsearchConfig < Chef::Provider::LWRPBase provides :elasticsearch_config action :create do - template '/etc/sysconfig/elasticsearch' do - source 'elasticsearch/elasticsearch.sysconfig.erb' - owner 'root' - group 'root' + directory '/etc/elasticsearch' do + mode '0755' + action :create + recursive true + end + + template '/etc/elasticsearch/elasticsearch.yml' do + source 'elasticsearch/elasticsearch.yml.erb' + owner 'elasticsearch' + group 'elasticsearch' mode '0644' cookbook new_resource.source variables options: { @@ -34,9 +40,6 @@ class ElasticsearchConfig < Chef::Provider::LWRPBase end end action :delete do - file '/etc/sysconfig/elasticsearc' do - action :delete - end end end end diff --git a/libraries/provider_kibana.rb b/libraries/provider_kibana.rb index 1b0e240..8197d0a 100644 --- a/libraries/provider_kibana.rb +++ b/libraries/provider_kibana.rb @@ -21,7 +21,7 @@ class Kibana < Chef::Provider::LWRPBase version new_resource.version end - runit_service 'kibana' do + runit_service service_name do default_logger true owner new_resource.user group new_resource.group @@ -36,6 +36,7 @@ class Kibana < Chef::Provider::LWRPBase end end + ## SERVICES action :enable do runit_service service_name do action :enable @@ -48,12 +49,6 @@ class Kibana < Chef::Provider::LWRPBase end end - action :restart do - runit_service service_name do - action :restart - end - end - action :start do runit_service service_name do action :start @@ -65,6 +60,12 @@ class Kibana < Chef::Provider::LWRPBase action :stop end end + + action :restart do + runit_service service_name do + action :restart + end + end end end end diff --git a/libraries/provider_kibana_config.rb b/libraries/provider_kibana_config.rb index faed7b0..d336a0f 100644 --- a/libraries/provider_kibana_config.rb +++ b/libraries/provider_kibana_config.rb @@ -6,7 +6,13 @@ class KibanaConfig < Chef::Provider::LWRPBase provides :kibana_config action :create do - template '/etc/kibana.yml' do + directory '/etc/kibana' do + mode '0755' + action :create + recursive true + end + + template '/etc/kibana/kibana.yml' do source 'kibana/kibana.yml.erb' owner new_resource.user owner new_resource.group diff --git a/libraries/provider_logstash.rb b/libraries/provider_logstash.rb new file mode 100644 index 0000000..9c8a1a5 --- /dev/null +++ b/libraries/provider_logstash.rb @@ -0,0 +1,65 @@ +class Chef + class Provider + class Logstash < Chef::Provider::LWRPBase + use_inline_resources if defined?(use_inline_resources) + + provides :logstash + + service_name = 'logstash' + + action :install do + user new_resource.user + group new_resource.group + + ark service_name do + checksum new_resource.checksum + group new_resource.group + has_binaries new_resource.has_binaries + owner new_resource.user + prefix_root new_resource.path + url new_resource.url + version new_resource.version + end + + runit_service service_name do + default_logger true + owner new_resource.user + group new_resource.user + cookbook new_resource.source + action [:create, :enable] + end + end + + action :remove do + runit_service service_name do + action :stop + end + end + ## SERVICE + + action :enable do + service service_name do + action :enable + end + end + + action :restart do + service service_name do + action :restart + end + end + + action :start do + service service_name do + action :start + end + end + + action :stop do + service service_name do + action :stop + end + end + end + end +end diff --git a/libraries/provider_logstash_config.rb b/libraries/provider_logstash_config.rb old mode 100755 new mode 100644 index 505b429..da280b0 --- a/libraries/provider_logstash_config.rb +++ b/libraries/provider_logstash_config.rb @@ -6,7 +6,19 @@ class LogstashConfig < Chef::Provider::LWRPBase provides :logstash_config action :create do - template '/etc/sysconfig/logstash' do + [new_resource.ls_conf_dir, + new_resource.ls_home, + '/var/log/logstash/', + '/etc/logstash' + ].each do |dir| + directory dir do + mode '0755' + action :create + recursive true + end + end + + template '/etc/logstash/config' do source 'logstash/logstash.sysconfig.erb' owner 'root' group 'root' @@ -28,28 +40,6 @@ class LogstashConfig < Chef::Provider::LWRPBase 'ls_nice' => new_resource.ls_nice } end - template '/etc/init.d/logstash' do - source 'logstash/logstash.initd.erb' - owner 'root' - group 'root' - mode '0755' - cookbook new_resource.source - variables options: { - 'javacmd' => new_resource.javacmd, - 'ls_home' => new_resource.ls_home, - 'ls_opts' => new_resource.ls_opts, - 'ls_heap_size' => new_resource.ls_heap_size, - 'ls_java_opts' => new_resource.ls_java_opts, - 'ls_pidfile' => new_resource.ls_pidfile, - 'ls_user' => new_resource.ls_user, - 'ls_group' => new_resource.ls_group, - 'ls_log_file' => new_resource.ls_log_file, - 'ls_use_gc_logging' => new_resource.ls_use_gc_logging, - 'ls_conf_dir' => new_resource.ls_conf_dir, - 'ls_open_files' => new_resource.ls_open_files, - 'ls_nice' => new_resource.ls_nice - } - end template "#{new_resource.ls_conf_dir}/00-input.conf" do source 'logstash/conf.d/00-input.conf.erb' diff --git a/libraries/provider_logstash_forwarder.rb b/libraries/provider_logstash_forwarder.rb new file mode 100644 index 0000000..52b5442 --- /dev/null +++ b/libraries/provider_logstash_forwarder.rb @@ -0,0 +1,70 @@ +class Chef + class Provider + class LogstashForwarder < Chef::Provider::LWRPBase + use_inline_resources if defined?(use_inline_resources) + + provides :logstash_forwarder + service_name = 'logstash_forwarder' + + action :install do + user new_resource.user + group new_resource.group + + # TODO: react to os/arch + remote_file '/opt/bin/logstash-forwarder' do + owner new_resource.user + group new_resource.group + mode '0755' + source 'https://download.elastic.co/logstash-forwarder/binaries/logstash-forwarder_linux_amd64' + checksum '5f49c5be671fff981b5ad1f8c5557a7e9973b24e8c73dbf0648326d400e6a4a1' + end + + runit_service service_name do + default_logger true + owner new_resource.user + group new_resource.user + cookbook new_resource.source + action [:create, :enable] + end + end + + action :remove do + runit_service service_name do + action :stop + end + end + + ## SERVICE + + action :enable do + service service_name do + action :enable + end + end + + action :disable do + service service_name do + action :disable + end + end + + action :restart do + service service_name do + action :restart + end + end + + action :start do + service service_name do + action :start + end + end + + action :stop do + service service_name do + action :stop + end + end + end + end +end diff --git a/libraries/provider_logstash_forwarder_config.rb b/libraries/provider_logstash_forwarder_config.rb old mode 100755 new mode 100644 index d20844f..3ba74b7 --- a/libraries/provider_logstash_forwarder_config.rb +++ b/libraries/provider_logstash_forwarder_config.rb @@ -6,40 +6,22 @@ class LogstashForwarderConfig < Chef::Provider::LWRPBase provides :logstash_forwarder_config action :create do - template '/etc/init.d/logstash-forwarder' do - source 'logstash-forwarder/logstash-forwarder.initd.erb' - owner 'root' - group 'root' + directory '/etc/logstash-forwarder' do mode '0755' - cookbook new_resource.source - variables options: { - 'user' => new_resource.user, - 'group' => new_resource.group, - 'chroot' => new_resource.chroot, - 'chdir' => new_resource.chdir, - 'nice' => new_resource.nice - } + action :create + recursive true end - template '/etc/default/logstash-forwarder' do - source 'logstash-forwarder/logstash-forwarder.erb' - owner 'root' - group 'root' - mode '0644' - cookbook new_resource.source - variables options: { - 'user' => new_resource.user, - 'group' => new_resource.group, - 'chroot' => new_resource.chroot, - 'chdir' => new_resource.chdir, - 'nice' => new_resource.nice - } + directory '/etc/logstash-forwarder/config.d' do + mode '0755' + action :create + recursive true end - template '/etc/logstash-forwarder.conf' do + template '/etc/logstash-forwarder/logstash-forwarder.conf' do source 'logstash-forwarder/logstash-forwarder.conf.erb' - owner 'root' - group 'root' + owner 'logstash' + group 'logstash' mode '0644' cookbook new_resource.source variables options: { diff --git a/libraries/provider_logstash_forwarder_service.rb b/libraries/provider_logstash_forwarder_service.rb deleted file mode 100755 index 8a083cd..0000000 --- a/libraries/provider_logstash_forwarder_service.rb +++ /dev/null @@ -1,73 +0,0 @@ -class Chef - class Provider - class LogstashForwarderService < Chef::Provider::LWRPBase - use_inline_resources if defined?(use_inline_resources) - - provides :logstash_forwarder_service - - service_name = 'logstash-forwarder' - - action :create do - install_repository - package service_name do - action :install - end - end - - action :delete do - service service_name do - action :stop - end - package service_name do - action :remove - end - remove_repository - end - - action :enable do - service service_name do - action :enable - end - end - - action :disable do - service service_name do - action :disable - end - end - - action :restart do - service service_name do - action :restart - end - end - - action :start do - service service_name do - action :start - end - end - - action :stop do - service service_name do - action :stop - end - end - - def install_repository - yum_repository 'logstash-forwarder' do - description 'logstash repository for 1.5.x packages' - baseurl 'http://packages.elasticsearch.org/logstashforwarder/centos' - gpgkey 'https://packages.elastic.co/GPG-KEY-elasticsearch' - action :create - end - end - - def remove_repository - yum_repository 'logstash-forwarder' do - action :delete - end - end - end - end -end diff --git a/libraries/provider_logstash_service.rb b/libraries/provider_logstash_service.rb deleted file mode 100755 index e918fdd..0000000 --- a/libraries/provider_logstash_service.rb +++ /dev/null @@ -1,67 +0,0 @@ -class Chef - class Provider - class LogstashService < Chef::Provider::LWRPBase - use_inline_resources if defined?(use_inline_resources) - - provides :logstash_service - - service_name = 'logstash' - - action :create do - install_repository - package service_name do - action :install - end - end - - action :delete do - service service_name do - action :stop - end - package service_name do - action :remove - end - remove_repository - end - - action :enable do - service service_name do - action :enable - end - end - - action :restart do - service service_name do - action :restart - end - end - - action :start do - service service_name do - action :start - end - end - - action :stop do - service service_name do - action :stop - end - end - - def install_repository - yum_repository 'logstash-1.5' do - description 'logstash repository for 1.5.x packages' - baseurl 'http://packages.elasticsearch.org/logstash/1.5/centos' - gpgkey 'https://packages.elastic.co/GPG-KEY-elasticsearch' - action :create - end - end - - def remove_repository - yum_repository 'logstash-1.5' do - action :delete - end - end - end - end -end diff --git a/libraries/resource_elasticsearch.rb b/libraries/resource_elasticsearch.rb index 0263215..3533efb 100644 --- a/libraries/resource_elasticsearch.rb +++ b/libraries/resource_elasticsearch.rb @@ -18,7 +18,7 @@ class Elasticsearch < Chef::Resource::LWRPBase # ARK tracks verioning by appending the :name with this for symlinking to a path attribute :version, kind_of: String, default: '1.7.0' - attribute :has_binaries, kind_of: Array, default: ['/bin/elasticsearch'] + attribute :has_binaries, kind_of: Array, default: ['bin/elasticsearch'] attribute :append_env_path, kind_of: [TrueClass, FalseClass], default: false # USER/GROUP to install by, also creates users on the OS for them @@ -27,6 +27,7 @@ class Elasticsearch < Chef::Resource::LWRPBase attribute :owner, kind_of: String, default: 'elasticsearch' attribute :path, kind_of: String, default: '/opt/elasticsearch' + attribute :prefix_bin, kind_of: String, default: '/opt/bin' end end end diff --git a/libraries/resource_logstash.rb b/libraries/resource_logstash.rb new file mode 100644 index 0000000..746df30 --- /dev/null +++ b/libraries/resource_logstash.rb @@ -0,0 +1,30 @@ +require 'chef/resource' + +class Chef + class Resource + class Logstash < Chef::Resource::LWRPBase + resource_name :logstash + default_action :install + actions [:install, :remove, :enable, :disable, :restart, :start, :stop] + + # used to target any files/templates; default to self + attribute :source, kind_of: String, default: 'elk' + + # url and sha256 of the archive to download and unpack + attribute :url, kind_of: String, default: 'https://download.elastic.co/logstash/logstash/logstash-1.5.3.tar.gz' + attribute :checksum, kind_of: String, default: 'eb3c366074e561d777348bfe9db3d4d1cccbf2fa8e7406776f500b4ca639c4aa' + + # ARK tracks verioning by appending the :name with this for symlinking to a path + attribute :version, kind_of: String, default: '1.5.3' + attribute :has_binaries, kind_of: Array, default: ['bin/logstash'] + attribute :append_env_path, kind_of: [TrueClass, FalseClass], default: false + + # USER/GROUP to install by, also creates users on the OS for them + attribute :user, kind_of: String, default: 'logstash' + attribute :group, kind_of: String, default: 'logstash' + attribute :owner, kind_of: String, default: 'logstash' + + attribute :path, kind_of: String, default: '/opt/logstash' + end + end +end diff --git a/libraries/resource_logstash_config.rb b/libraries/resource_logstash_config.rb old mode 100755 new mode 100644 index 443d819..869eeb4 --- a/libraries/resource_logstash_config.rb +++ b/libraries/resource_logstash_config.rb @@ -8,10 +8,10 @@ class LogstashConfig < Chef::Resource::LWRPBase actions [:create, :delete] attribute :crt, kind_of: String, default: '' - attribute :crt_location, kind_of: String, default: '/opt/logstash/logstash.crt' + attribute :crt_location, kind_of: String, default: '/etc/logstash/logstash.crt' attribute :javacmd, kind_of: String, default: '/usr/bin/java' attribute :key, kind_of: String, default: '' - attribute :key_location, kind_of: String, default: '/opt/logstash/logstash.key' + attribute :key_location, kind_of: String, default: '/etc/logstash/logstash.key' attribute :ls_conf_dir, kind_of: String, default: '/etc/logstash/conf.d' attribute :ls_group, kind_of: String, default: 'logstash' attribute :ls_heap_size, kind_of: String, default: '500m' diff --git a/libraries/resource_logstash_forwarder.rb b/libraries/resource_logstash_forwarder.rb new file mode 100644 index 0000000..2d6e108 --- /dev/null +++ b/libraries/resource_logstash_forwarder.rb @@ -0,0 +1,18 @@ +require 'chef/resource' + +class Chef + class Resource + class LogstashForwarder < Chef::Resource::LWRPBase + resource_name :logstash_forwarder + default_action :install + actions [:install, :remove, :enable, :disable, :restart, :start, :stop] + + # used to target any files/templates; default to self + attribute :source, kind_of: String, default: 'elk' + + attribute :group, kind_of: String, default: 'logstash' + attribute :user, kind_of: String, default: 'logstash' + attribute :version, kind_of: String, default: '0.4.0' + end + end +end diff --git a/libraries/resource_logstash_forwarder_config.rb b/libraries/resource_logstash_forwarder_config.rb old mode 100755 new mode 100644 index c9a9049..eab5c62 --- a/libraries/resource_logstash_forwarder_config.rb +++ b/libraries/resource_logstash_forwarder_config.rb @@ -2,7 +2,7 @@ class Chef class Resource - class LogstashForwarder < Chef::Resource::LWRPBase + class LogstashForwarderConfig < Chef::Resource::LWRPBase resource_name :logstash_forwarder_config default_action :create actions [:create, :delete] @@ -10,10 +10,10 @@ class LogstashForwarder < Chef::Resource::LWRPBase attribute :chdir, kind_of: String, default: '/var/lib/logstash-forwarder' attribute :chroot, kind_of: String, default: '/' attribute :crt, kind_of: String, default: '' - attribute :crt_location, kind_of: String, default: '/opt/logstash-forwarder/logstash.crt' + attribute :crt_location, kind_of: String, default: '/etc/logstash-forwarder/logstash.crt' attribute :group, kind_of: String, default: 'root' attribute :key, kind_of: String, default: '' - attribute :key_location, kind_of: String, default: '/opt/logstash-forwarder/logstash.key' + attribute :key_location, kind_of: String, default: '/etc/logstash-forwarder/logstash.key' attribute :nice, kind_of: String, default: '' attribute :port, kind_of: Integer, default: 5043 attribute :source, kind_of: String, default: 'elk' diff --git a/libraries/resource_logstash_forwarder_service.rb b/libraries/resource_logstash_forwarder_service.rb deleted file mode 100755 index 7ad8047..0000000 --- a/libraries/resource_logstash_forwarder_service.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'chef/resource' - -class Chef - class Resource - class LogstashForwarderService < Chef::Resource::LWRPBase - resource_name :logstash_forwarder_service - default_action :create - actions [:create, :delete, :enable, :disable, :restart, :start, :stop] - end - end -end diff --git a/libraries/resource_logstash_service.rb b/libraries/resource_logstash_service.rb deleted file mode 100755 index 7995466..0000000 --- a/libraries/resource_logstash_service.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'chef/resource' - -class Chef - class Resource - class LogstashService < Chef::Resource::LWRPBase - resource_name :logstash_service - default_action :create - actions [:create, :delete, :enable, :disable, :restart, :start, :stop] - end - end -end diff --git a/templates/default/elasticsearch/sv-elasticsearch-run.erb b/templates/default/elasticsearch/sv-elasticsearch-run.erb deleted file mode 100644 index 2e1fd4e..0000000 --- a/templates/default/elasticsearch/sv-elasticsearch-run.erb +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -cd /opt/elasticsearch -exec 2>&1 - -exec /usr/bin/env elasticsearch diff --git a/templates/default/kibana/kibana.initd.erb b/templates/default/kibana/kibana.initd.erb deleted file mode 100644 index 800dc84..0000000 --- a/templates/default/kibana/kibana.initd.erb +++ /dev/null @@ -1,98 +0,0 @@ -#!/bin/bash -### BEGIN INIT INFO -# Provides: kibana -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Runs kibana daemon -# Description: Runs the kibana daemon as a non-root user -### END INIT INFO - -# Process name -NAME=kibana -DESC="Kibana4" -PROG="/etc/init.d/kibana" -PID_FOLDER=/var/run/kibana/ -# pid file for daemon -PID_FILE=/var/run/kibana/$NAME.pid -LOCK_FILE=/var/lock/subsys/$NAME -PATH=/bin:/usr/bin:/sbin:/usr/sbin:$KIBANA_BIN - -# Configure the daemon & kibana variables based on Kibana location -KIBANA_BIN=/usr/local/bin/ -KIBANA_LOG=/var/log/kibana.log -# Daemon name -DAEMON="$KIBANA_BIN/kibana -c /etc/kibana.yml" -# User to run as daemon process -DAEMON_USER=kibana - -RETVAL=0 - -if [ `id -u` -ne 0 ]; then - echo "You need root privileges to run this script" - exit 1 -fi - -# Function library -. /etc/init.d/functions - -start() { - echo -n "Starting $DESC : " - - pid=`pidofproc -p $PID_FILE kibana` - if [ -n "$pid" ] ; then - echo "Already running." - exit 0 - else - # Start Daemon - if [ ! -d "$PID_FOLDER" ] ; then - mkdir $PID_FOLDER - fi - daemon --user=$DAEMON_USER --pidfile=$PID_FILE "$DAEMON" 1>"$KIBANA_LOG" 2>&1 & - sleep 2 - pidofproc node > $PID_FILE - RETVAL=$? - [[ $? -eq 0 ]] && success || failure - echo - [ $RETVAL = 0 ] && touch $LOCK_FILE - return $RETVAL - fi -} - -reload() -{ - echo "Reload command is not implemented for this service." - return $RETVAL -} - -stop() { - echo -n "Stopping $DESC : " - killproc -p $PID_FILE $DAEMON - RETVAL=$? - echo - [ $RETVAL = 0 ] && rm -f $PID_FILE $LOCK_FILE -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - status) - status -p $PID_FILE $DAEMON - RETVAL=$? - ;; - restart) - stop - start - ;; - reload) - reload - ;; - *) - # Invalid Arguments, print the following message. - echo "Usage: $0 {start|stop|status|restart}" >&2 - exit 2 - ;; -esac \ No newline at end of file diff --git a/templates/default/logrotate/logstash.erb b/templates/default/logrotate/logstash.erb deleted file mode 100755 index 69977ae..0000000 --- a/templates/default/logrotate/logstash.erb +++ /dev/null @@ -1,9 +0,0 @@ -/var/log/logstash/*.log { - daily - rotate 7 - copytruncate - compress - delaycompress - missingok - notifempty -} diff --git a/templates/default/logstash-forwarder/logstash-forwarder.erb b/templates/default/logstash-forwarder/logstash-forwarder.erb deleted file mode 100755 index db189be..0000000 --- a/templates/default/logstash-forwarder/logstash-forwarder.erb +++ /dev/null @@ -1,6 +0,0 @@ -user=<%= @options['user'] %> -group=<%= @options['group'] %> -chroot=<%= @options['chroot'] %> -chdir=<%= @options['chdir'] %> -nice=<%= @options['nice'] %> - diff --git a/templates/default/logstash-forwarder/logstash-forwarder.initd.erb b/templates/default/logstash-forwarder/logstash-forwarder.initd.erb deleted file mode 100755 index 406d928..0000000 --- a/templates/default/logstash-forwarder/logstash-forwarder.initd.erb +++ /dev/null @@ -1,151 +0,0 @@ -#!/bin/sh -# Init script for logstash-forwarder -# Maintained by -# Generated by pleaserun. -# Implemented based on LSB Core 3.1: -# * Sections: 20.2, 20.3 -# -### BEGIN INIT INFO -# Provides: logstash-forwarder -# Required-Start: $remote_fs $syslog -# Required-Stop: $remote_fs $syslog -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: -# Description: no description given -### END INIT INFO - -PATH=/sbin:/usr/sbin:/bin:/usr/bin -export PATH - -name=logstash-forwarder -program=/opt/logstash-forwarder/bin/logstash-forwarder -args=-config\ /etc/logstash-forwarder.conf -pidfile="/var/run/$name.pid" - -[ -r /etc/default/$name ] && . /etc/default/$name -[ -r /etc/sysconfig/$name ] && . /etc/sysconfig/$name - -trace() { - logger -t "/etc/init.d/logstash-forwarder" "$@" -} - -emit() { - trace "$@" - echo "$@" -} - -start() { - - - # Setup any environmental stuff beforehand - - - # Run the program! - - chroot --userspec "$user":"$group" "$chroot" sh -c " - - cd \"$chdir\" - exec \"$program\" $args - " >> /var/log/logstash-forwarder/logstash-forwarder.log 2>> /var/log/logstash-forwarder/logstash-forwarder.err & - - # Generate the pidfile from here. If we instead made the forked process - # generate it there will be a race condition between the pidfile writing - # and a process possibly asking for status. - echo $! > $pidfile - - emit "$name started" - return 0 -} - -stop() { - # Try a few times to kill TERM the program - if status ; then - pid=$(cat "$pidfile") - trace "Killing $name (pid $pid) with SIGTERM" - kill -TERM $pid - # Wait for it to exit. - for i in 1 2 3 4 5 ; do - trace "Waiting $name (pid $pid) to die..." - status || break - sleep 1 - done - if status ; then - emit "$name stop failed; still running." - else - emit "$name stopped." - fi - fi -} - -status() { - if [ -f "$pidfile" ] ; then - pid=$(cat "$pidfile") - if ps -p $pid > /dev/null 2> /dev/null ; then - # process by this pid is running. - # It may not be our pid, but that's what you get with just pidfiles. - # TODO(sissel): Check if this process seems to be the same as the one we - # expect. It'd be nice to use flock here, but flock uses fork, not exec, - # so it makes it quite awkward to use in this case. - return 0 - else - return 2 # program is dead but pid file exists - fi - else - return 3 # program is not running - fi -} - -force_stop() { - if status ; then - stop - status && kill -KILL $(cat "$pidfile") - fi -} - - -case "$1" in - force-start|start|stop|force-stop|restart) - trace "Attempting '$1' on logstash-forwarder" - ;; -esac - -case "$1" in - force-start) - PRESTART=no - exec "$0" start - ;; - start) - status - code=$? - if [ $code -eq 0 ]; then - emit "$name is already running" - exit $code - else - start - exit $? - fi - ;; - stop) stop ;; - force-stop) force_stop ;; - status) - status - code=$? - if [ $code -eq 0 ] ; then - emit "$name is running" - else - emit "$name is not running" - fi - exit $code - ;; - restart) - - stop && start - ;; - *) - echo "Usage: $SCRIPTNAME {start|force-start|stop|force-start|force-stop|status|restart}" >&2 - exit 3 - ;; -esac - -exit $? diff --git a/templates/default/logstash/logstash.initd.erb b/templates/default/logstash/logstash.initd.erb deleted file mode 100755 index 93209c3..0000000 --- a/templates/default/logstash/logstash.initd.erb +++ /dev/null @@ -1,152 +0,0 @@ -#!/bin/sh -# Init script for logstash -# Maintained by Elasticsearch -# Generated by pleaserun. -# Implemented based on LSB Core 3.1: -# * Sections: 20.2, 20.3 -# -### BEGIN INIT INFO -# Provides: logstash -# Required-Start: $remote_fs $syslog -# Required-Stop: $remote_fs $syslog -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: -# Description: Starts Logstash as a daemon. -### END INIT INFO - -PATH=/sbin:/usr/sbin:/bin:/usr/bin -export PATH - -if [ `id -u` -ne 0 ]; then - echo "You need root privileges to run this script" - exit 1 -fi - -name=logstash -pidfile="/var/run/$name.pid" - -LS_USER=<%= @options['ls_user'] %> -LS_GROUP=<%= @options['ls_group'] %> -LS_HOME=/var/lib/<%= @options['ls_home'] %> -LS_HEAP_SIZE=<%= @options['ls_heap_size'] %> -LS_LOG_DIR=<%= @options['ls_log_dir'] %> -LS_LOG_FILE=<%= @options['ls_log_file'] %> -LS_CONF_DIR=<%= @options['ls_conf_dir'] %> -LS_OPEN_FILES=<%= @options['ls_open_files'] %> -LS_NICE=<%= @options['ls_nice'] %> -LS_OPTS=<%= @options['ls_opts'] %> - - -[ -r /etc/default/$name ] && . /etc/default/$name -[ -r /etc/sysconfig/$name ] && . /etc/sysconfig/$name - -program=/opt/logstash/bin/logstash -args="agent -f ${LS_CONF_DIR} -l ${LS_LOG_FILE} ${LS_OPTS}" - -start() { - - LS_JAVA_OPTS="${LS_JAVA_OPTS} -Djava.io.tmpdir=${LS_HOME}" - HOME=${LS_HOME} - export PATH HOME LS_HEAP_SIZE LS_JAVA_OPTS LS_USE_GC_LOGGING - - # set ulimit as (root, presumably) first, before we drop privileges - ulimit -n ${LS_OPEN_FILES} - - # Run the program! - nice -n ${LS_NICE} chroot --userspec $LS_USER:$LS_GROUP / sh -c " - cd $LS_HOME - ulimit -n ${LS_OPEN_FILES} - exec \"$program\" $args - " > "${LS_LOG_DIR}/$name.stdout" 2> "${LS_LOG_DIR}/$name.err" & - - # Generate the pidfile from here. If we instead made the forked process - # generate it there will be a race condition between the pidfile writing - # and a process possibly asking for status. - echo $! > $pidfile - - echo "$name started." - return 0 -} - -stop() { - # Try a few times to kill TERM the program - if status ; then - pid=`cat "$pidfile"` - echo "Killing $name (pid $pid) with SIGTERM" - kill -TERM $pid - # Wait for it to exit. - for i in 1 2 3 4 5 ; do - echo "Waiting $name (pid $pid) to die..." - status || break - sleep 1 - done - if status ; then - echo "$name stop failed; still running." - else - echo "$name stopped." - fi - fi -} - -status() { - if [ -f "$pidfile" ] ; then - pid=`cat "$pidfile"` - if kill -0 $pid > /dev/null 2> /dev/null ; then - # process by this pid is running. - # It may not be our pid, but that's what you get with just pidfiles. - # TODO(sissel): Check if this process seems to be the same as the one we - # expect. It'd be nice to use flock here, but flock uses fork, not exec, - # so it makes it quite awkward to use in this case. - return 0 - else - return 2 # program is dead but pid file exists - fi - else - return 3 # program is not running - fi -} - -force_stop() { - if status ; then - stop - status && kill -KILL `cat "$pidfile"` - fi -} - - -case "$1" in - start) - status - code=$? - if [ $code -eq 0 ]; then - echo "$name is already running" - else - start - code=$? - fi - exit $code - ;; - stop) stop ;; - force-stop) force_stop ;; - status) - status - code=$? - if [ $code -eq 0 ] ; then - echo "$name is running" - else - echo "$name is not running" - fi - exit $code - ;; - restart) - - stop && start - ;; - *) - echo "Usage: $SCRIPTNAME {start|stop|force-stop|status|restart}" >&2 - exit 3 - ;; -esac - -exit $? diff --git a/templates/default/sv-elasticsearch-run.erb b/templates/default/sv-elasticsearch-run.erb index 2e1fd4e..fb801ab 100644 --- a/templates/default/sv-elasticsearch-run.erb +++ b/templates/default/sv-elasticsearch-run.erb @@ -3,4 +3,4 @@ cd /opt/elasticsearch exec 2>&1 -exec /usr/bin/env elasticsearch +exec ./bin/elasticsearch diff --git a/templates/default/sv-logstash-run.erb b/templates/default/sv-logstash-run.erb new file mode 100644 index 0000000..4790176 --- /dev/null +++ b/templates/default/sv-logstash-run.erb @@ -0,0 +1,6 @@ +#!/bin/sh + +cd /home/logstash +exec 2>&1 + +exec /usr/bin/env logstash -c /etc/logstash/config diff --git a/templates/default/sv-logstash_forwarder-run.erb b/templates/default/sv-logstash_forwarder-run.erb new file mode 100644 index 0000000..f680fae --- /dev/null +++ b/templates/default/sv-logstash_forwarder-run.erb @@ -0,0 +1,6 @@ +#!/bin/sh + +cd /home/logstash +exec 2>&1 + +exec /usr/bin/env logstash-forwarder -c /etc/logstash-forwarder/logstash-forwarder.yml diff --git a/test/cookbooks/elktest/recipes/default.rb b/test/cookbooks/elktest/recipes/default.rb index f8f854f..ed52bb3 100644 --- a/test/cookbooks/elktest/recipes/default.rb +++ b/test/cookbooks/elktest/recipes/default.rb @@ -1,15 +1,12 @@ # test a single node with all three projects -# package 'htop' -# package 'java-1.8.0-openjdk-headless' -# package 'nginx' - +package 'java-1.8.0-openjdk-headless' package 'tar' package 'nano' include_recipe 'runit::default' -# include_recipe 'elktest::elasticsearch' -# include_recipe 'elktest::logstash' -# include_recipe 'elktest::logstash_forwarder' +include_recipe 'elktest::elasticsearch' +include_recipe 'elktest::logstash' +include_recipe 'elktest::logstash_forwarder' include_recipe 'elktest::kibana' diff --git a/test/cookbooks/elktest/recipes/elasticsearch.rb b/test/cookbooks/elktest/recipes/elasticsearch.rb index c22eef9..1599aee 100644 --- a/test/cookbooks/elktest/recipes/elasticsearch.rb +++ b/test/cookbooks/elktest/recipes/elasticsearch.rb @@ -1,9 +1,6 @@ - -elasticsearch 'default' do - action [:install, :start, :enable] -end +elasticsearch 'default' elasticsearch_config 'default' do action :create - notifies :restart, 'elasticsearch[default]' + notifies :start, 'elasticsearch[default]' end diff --git a/test/cookbooks/elktest/recipes/logstash.rb b/test/cookbooks/elktest/recipes/logstash.rb old mode 100755 new mode 100644 index 5d5c04a..6698214 --- a/test/cookbooks/elktest/recipes/logstash.rb +++ b/test/cookbooks/elktest/recipes/logstash.rb @@ -1,15 +1,19 @@ -logstash_service 'default' do - action [:create, :start, :enable] -end +logstash 'default' secrets = Chef::DataBagItem.load('secrets', 'logstash') logstash_key = Base64.decode64(secrets['key']) logstash_crt = Base64.decode64(secrets['certificate']) -file '/opt/logstash/logstash.key' do +directory '/etc/logstash-forwarder' do + mode '0755' + action :create + recursive true +end + +file '/etc/logstash/logstash.key' do content logstash_key end -file '/opt/logstash/logstash.crt' do +file '/etc/logstash/logstash.crt' do content logstash_crt end @@ -17,5 +21,5 @@ action :create key logstash_key crt logstash_crt - notifies :restart, 'logstash_service[default]' + notifies :restart, 'logstash[default]' end diff --git a/test/cookbooks/elktest/recipes/logstash_forwarder.rb b/test/cookbooks/elktest/recipes/logstash_forwarder.rb old mode 100755 new mode 100644 index f394917..670f0c9 --- a/test/cookbooks/elktest/recipes/logstash_forwarder.rb +++ b/test/cookbooks/elktest/recipes/logstash_forwarder.rb @@ -1,15 +1,13 @@ -logstash_forwarder_service 'default' do - action [:create, :start] -end +logstash_forwarder 'default' secrets = Chef::DataBagItem.load('secrets', 'logstash') logstash_key = Base64.decode64(secrets['key']) logstash_crt = Base64.decode64(secrets['certificate']) -file '/opt/logstash-forwarder/logstash.key' do +file '/etc/logstash-forwarder/logstash.key' do content logstash_key end -file '/opt/logstash-forwarder/logstash.crt' do +file '/etc/logstash-forwarder/logstash.crt' do content logstash_crt end @@ -17,5 +15,5 @@ action :create key logstash_key crt logstash_crt - notifies :restart, 'logstash_forwarder_service[default]' + notifies :restart, 'logstash_forwarder[default]' end From f706310f50100c654723726cfefe5f4009c5b233 Mon Sep 17 00:00:00 2001 From: Jacob Dearing Date: Mon, 27 Jul 2015 11:40:52 -0500 Subject: [PATCH 03/10] cosmetic elktest changes --- test/cookbooks/elktest/recipes/default.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/cookbooks/elktest/recipes/default.rb b/test/cookbooks/elktest/recipes/default.rb index ed52bb3..2afbb10 100644 --- a/test/cookbooks/elktest/recipes/default.rb +++ b/test/cookbooks/elktest/recipes/default.rb @@ -1,9 +1,9 @@ -# test a single node with all three projects +# test a single node with all four projects -package 'java-1.8.0-openjdk-headless' -package 'tar' -package 'nano' +%w( tar nano htop java-1.8.0-openjdk-headless).each do |pkg| + package pkg +end include_recipe 'runit::default' include_recipe 'elktest::elasticsearch' From b64e87c6050f0df7428d437e74cd5c46d9815dd5 Mon Sep 17 00:00:00 2001 From: Jacob Dearing Date: Mon, 27 Jul 2015 12:06:57 -0500 Subject: [PATCH 04/10] rethrow resources --- libraries/resource_elasticsearch.rb | 25 ++++++++++++++ libraries/resource_elasticsearch_config.rb | 30 ---------------- libraries/resource_kibana.rb | 29 ++++++++++++++++ libraries/resource_kibana_config.rb | 34 ------------------- libraries/resource_logstash.rb | 26 ++++++++++++++ libraries/resource_logstash_config.rb | 31 ----------------- libraries/resource_logstash_forwarder.rb | 18 ++++++++++ .../resource_logstash_forwarder_config.rb | 23 ------------- 8 files changed, 98 insertions(+), 118 deletions(-) delete mode 100755 libraries/resource_elasticsearch_config.rb delete mode 100755 libraries/resource_kibana_config.rb delete mode 100644 libraries/resource_logstash_config.rb delete mode 100644 libraries/resource_logstash_forwarder_config.rb diff --git a/libraries/resource_elasticsearch.rb b/libraries/resource_elasticsearch.rb index 3533efb..fd85270 100644 --- a/libraries/resource_elasticsearch.rb +++ b/libraries/resource_elasticsearch.rb @@ -29,5 +29,30 @@ class Elasticsearch < Chef::Resource::LWRPBase attribute :path, kind_of: String, default: '/opt/elasticsearch' attribute :prefix_bin, kind_of: String, default: '/opt/bin' end + + class ElasticsearchConfig < Chef::Resource::LWRPBase + resource_name :elasticsearch_config + default_action :create + actions [:create, :delete] + + attribute :conf_dir, kind_of: String, default: '/etc/elasticsearch' + attribute :conf_file, kind_of: String, default: '/etc/elasticsearch/elasticsearch.yml' + attribute :data_dir, kind_of: String, default: '/var/lib/elasticsearch' + attribute :es_direct_size, kind_of: String, default: nil + attribute :es_group, kind_of: String, default: 'elasticsearch' + attribute :es_heap_newsize, kind_of: String, default: nil + attribute :es_heap_size, kind_of: String, default: '1g' + attribute :es_home, kind_of: String, default: '/usr/share/elasticsearch' + attribute :es_java_opts, kind_of: String, default: nil + attribute :es_user, kind_of: String, default: 'elasticsearch' + attribute :log_dir, kind_of: String, default: '/var/log/elasticsearch' + attribute :max_locked_memory, kind_of: String, default: 'unlimited' + attribute :max_map_count, kind_of: Integer, default: 65_535 + attribute :max_open_files, kind_of: Integer, default: 65_535 + attribute :pid_dir, kind_of: String, default: '/var/run/elasticsearch' + attribute :restart_on_upgrade, kind_of: [TrueClass, FalseClass], default: false + attribute :source, kind_of: String, default: 'elk' + attribute :work_dir, kind_of: String, default: '/tmp/elasticsearch' + end end end diff --git a/libraries/resource_elasticsearch_config.rb b/libraries/resource_elasticsearch_config.rb deleted file mode 100755 index 859afd4..0000000 --- a/libraries/resource_elasticsearch_config.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'chef/resource' - -class Chef - class Resource - class ElasticsearchConfig < Chef::Resource::LWRPBase - resource_name :elasticsearch_config - default_action :create - actions [:create, :delete] - - attribute :conf_dir, kind_of: String, default: '/etc/elasticsearch' - attribute :conf_file, kind_of: String, default: '/etc/elasticsearch/elasticsearch.yml' - attribute :data_dir, kind_of: String, default: '/var/lib/elasticsearch' - attribute :es_direct_size, kind_of: String, default: nil - attribute :es_group, kind_of: String, default: 'elasticsearch' - attribute :es_heap_newsize, kind_of: String, default: nil - attribute :es_heap_size, kind_of: String, default: '1g' - attribute :es_home, kind_of: String, default: '/usr/share/elasticsearch' - attribute :es_java_opts, kind_of: String, default: nil - attribute :es_user, kind_of: String, default: 'elasticsearch' - attribute :log_dir, kind_of: String, default: '/var/log/elasticsearch' - attribute :max_locked_memory, kind_of: String, default: 'unlimited' - attribute :max_map_count, kind_of: Integer, default: 65_535 - attribute :max_open_files, kind_of: Integer, default: 65_535 - attribute :pid_dir, kind_of: String, default: '/var/run/elasticsearch' - attribute :restart_on_upgrade, kind_of: [TrueClass, FalseClass], default: false - attribute :source, kind_of: String, default: 'elk' - attribute :work_dir, kind_of: String, default: '/tmp/elasticsearch' - end - end -end diff --git a/libraries/resource_kibana.rb b/libraries/resource_kibana.rb index 12ef25d..dee3ede 100644 --- a/libraries/resource_kibana.rb +++ b/libraries/resource_kibana.rb @@ -18,5 +18,34 @@ class Kibana < Chef::Resource::LWRPBase attribute :source, kind_of: String, default: 'elk' end + + class KibanaConfig < Chef::Resource::LWRPBase + resource_name :kibana_config + default_action :create + actions [:create, :delete] + + attribute :group, kind_of: String, default: 'kibana' + attribute :kibana_elasticsearch_password, kind_of: String, default: nil + attribute :user, kind_of: String, default: 'kibana' + attribute :default_app_id, kind_of: String, default: 'discover' + attribute :elasticsearch_preserve_host, kind_of: [TrueClass, FalseClass], default: true + attribute :elasticsearch_url, kind_of: String, default: 'http://localhost:9200' + attribute :host, kind_of: String, default: '0.0.0.0' + attribute :kibana_elasticsearch_client_crt, kind_of: String, default: nil + attribute :kibana_elasticsearch_client_key, kind_of: String, default: nil + attribute :kibana_elasticsearch_username, kind_of: String, default: nil + attribute :kibana_index, kind_of: String, default: '.kibana' + attribute :log_file, kind_of: Integer, default: './kibana.log' + attribute :pid_file, kind_of: String, default: '/var/run/kibana.pid' + attribute :ping_timeout, kind_of: Integer, default: 1500 + attribute :port, kind_of: Integer, default: 5601 + attribute :request_timeout, kind_of: Integer, default: 30_000 + attribute :shard_timeout, kind_of: Integer, default: 0 + attribute :ssl_cert_file, kind_of: String, default: nil + attribute :ssl_key_file, kind_of: String, default: nil + attribute :source, kind_of: String, default: 'elk' + attribute :startup_timeout, kind_of: Integer, default: 5000 + attribute :verify_ssl, kind_of: [TrueClass, FalseClass], default: true + end end end diff --git a/libraries/resource_kibana_config.rb b/libraries/resource_kibana_config.rb deleted file mode 100755 index 39dddc4..0000000 --- a/libraries/resource_kibana_config.rb +++ /dev/null @@ -1,34 +0,0 @@ -require 'chef/resource' - -class Chef - class Resource - class KibanaConfig < Chef::Resource::LWRPBase - resource_name :kibana_config - default_action :create - actions [:create, :delete] - - attribute :group, kind_of: String, default: 'kibana' - attribute :kibana_elasticsearch_password, kind_of: String, default: nil - attribute :user, kind_of: String, default: 'kibana' - attribute :default_app_id, kind_of: String, default: 'discover' - attribute :elasticsearch_preserve_host, kind_of: [TrueClass, FalseClass], default: true - attribute :elasticsearch_url, kind_of: String, default: 'http://localhost:9200' - attribute :host, kind_of: String, default: '0.0.0.0' - attribute :kibana_elasticsearch_client_crt, kind_of: String, default: nil - attribute :kibana_elasticsearch_client_key, kind_of: String, default: nil - attribute :kibana_elasticsearch_username, kind_of: String, default: nil - attribute :kibana_index, kind_of: String, default: '.kibana' - attribute :log_file, kind_of: Integer, default: './kibana.log' - attribute :pid_file, kind_of: String, default: '/var/run/kibana.pid' - attribute :ping_timeout, kind_of: Integer, default: 1500 - attribute :port, kind_of: Integer, default: 5601 - attribute :request_timeout, kind_of: Integer, default: 30_000 - attribute :shard_timeout, kind_of: Integer, default: 0 - attribute :ssl_cert_file, kind_of: String, default: nil - attribute :ssl_key_file, kind_of: String, default: nil - attribute :source, kind_of: String, default: 'elk' - attribute :startup_timeout, kind_of: Integer, default: 5000 - attribute :verify_ssl, kind_of: [TrueClass, FalseClass], default: true - end - end -end diff --git a/libraries/resource_logstash.rb b/libraries/resource_logstash.rb index 746df30..fb223dc 100644 --- a/libraries/resource_logstash.rb +++ b/libraries/resource_logstash.rb @@ -26,5 +26,31 @@ class Logstash < Chef::Resource::LWRPBase attribute :path, kind_of: String, default: '/opt/logstash' end + + class LogstashConfig < Chef::Resource::LWRPBase + resource_name :logstash_config + default_action :create + actions [:create, :delete] + + attribute :crt, kind_of: String, default: '' + attribute :crt_location, kind_of: String, default: '/etc/logstash/logstash.crt' + attribute :javacmd, kind_of: String, default: '/usr/bin/java' + attribute :key, kind_of: String, default: '' + attribute :key_location, kind_of: String, default: '/etc/logstash/logstash.key' + attribute :ls_conf_dir, kind_of: String, default: '/etc/logstash/conf.d' + attribute :ls_group, kind_of: String, default: 'logstash' + attribute :ls_heap_size, kind_of: String, default: '500m' + attribute :ls_home, kind_of: String, default: '/var/lib/logstash' + attribute :ls_java_opts, kind_of: String, default: '-Djava.io.tmpdir=$HOME' + attribute :ls_log_file, kind_of: String, default: '/var/log/logstash/logstash.log' + attribute :ls_nice, kind_of: Integer, default: 19 + attribute :ls_open_files, kind_of: Integer, default: 16_384 + attribute :ls_opts, kind_of: String, default: '' + attribute :ls_pidfile, kind_of: String, default: '/var/run/logstash.pid' + attribute :ls_use_gc_logging, kind_of: [TrueClass, FalseClass], default: true + attribute :ls_user, kind_of: String, default: 'logstash' + attribute :port, kind_of: Integer, default: 5043 + attribute :source, kind_of: String, default: 'elk' + end end end diff --git a/libraries/resource_logstash_config.rb b/libraries/resource_logstash_config.rb deleted file mode 100644 index 869eeb4..0000000 --- a/libraries/resource_logstash_config.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'chef/resource' - -class Chef - class Resource - class LogstashConfig < Chef::Resource::LWRPBase - resource_name :logstash_config - default_action :create - actions [:create, :delete] - - attribute :crt, kind_of: String, default: '' - attribute :crt_location, kind_of: String, default: '/etc/logstash/logstash.crt' - attribute :javacmd, kind_of: String, default: '/usr/bin/java' - attribute :key, kind_of: String, default: '' - attribute :key_location, kind_of: String, default: '/etc/logstash/logstash.key' - attribute :ls_conf_dir, kind_of: String, default: '/etc/logstash/conf.d' - attribute :ls_group, kind_of: String, default: 'logstash' - attribute :ls_heap_size, kind_of: String, default: '500m' - attribute :ls_home, kind_of: String, default: '/var/lib/logstash' - attribute :ls_java_opts, kind_of: String, default: '-Djava.io.tmpdir=$HOME' - attribute :ls_log_file, kind_of: String, default: '/var/log/logstash/logstash.log' - attribute :ls_nice, kind_of: Integer, default: 19 - attribute :ls_open_files, kind_of: Integer, default: 16_384 - attribute :ls_opts, kind_of: String, default: '' - attribute :ls_pidfile, kind_of: String, default: '/var/run/logstash.pid' - attribute :ls_use_gc_logging, kind_of: [TrueClass, FalseClass], default: true - attribute :ls_user, kind_of: String, default: 'logstash' - attribute :port, kind_of: Integer, default: 5043 - attribute :source, kind_of: String, default: 'elk' - end - end -end diff --git a/libraries/resource_logstash_forwarder.rb b/libraries/resource_logstash_forwarder.rb index 2d6e108..09f1ab2 100644 --- a/libraries/resource_logstash_forwarder.rb +++ b/libraries/resource_logstash_forwarder.rb @@ -14,5 +14,23 @@ class LogstashForwarder < Chef::Resource::LWRPBase attribute :user, kind_of: String, default: 'logstash' attribute :version, kind_of: String, default: '0.4.0' end + + class LogstashForwarderConfig < Chef::Resource::LWRPBase + resource_name :logstash_forwarder_config + default_action :create + actions [:create, :delete] + + attribute :chdir, kind_of: String, default: '/var/lib/logstash-forwarder' + attribute :chroot, kind_of: String, default: '/' + attribute :crt, kind_of: String, default: '' + attribute :crt_location, kind_of: String, default: '/etc/logstash-forwarder/logstash.crt' + attribute :group, kind_of: String, default: 'root' + attribute :key, kind_of: String, default: '' + attribute :key_location, kind_of: String, default: '/etc/logstash-forwarder/logstash.key' + attribute :nice, kind_of: String, default: '' + attribute :port, kind_of: Integer, default: 5043 + attribute :source, kind_of: String, default: 'elk' + attribute :user, kind_of: String, default: 'root' + end end end diff --git a/libraries/resource_logstash_forwarder_config.rb b/libraries/resource_logstash_forwarder_config.rb deleted file mode 100644 index eab5c62..0000000 --- a/libraries/resource_logstash_forwarder_config.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'chef/resource' - -class Chef - class Resource - class LogstashForwarderConfig < Chef::Resource::LWRPBase - resource_name :logstash_forwarder_config - default_action :create - actions [:create, :delete] - - attribute :chdir, kind_of: String, default: '/var/lib/logstash-forwarder' - attribute :chroot, kind_of: String, default: '/' - attribute :crt, kind_of: String, default: '' - attribute :crt_location, kind_of: String, default: '/etc/logstash-forwarder/logstash.crt' - attribute :group, kind_of: String, default: 'root' - attribute :key, kind_of: String, default: '' - attribute :key_location, kind_of: String, default: '/etc/logstash-forwarder/logstash.key' - attribute :nice, kind_of: String, default: '' - attribute :port, kind_of: Integer, default: 5043 - attribute :source, kind_of: String, default: 'elk' - attribute :user, kind_of: String, default: 'root' - end - end -end From 8717beef0d4dc9dab176f9c56d6e7766f4aec13a Mon Sep 17 00:00:00 2001 From: Jacob Dearing Date: Mon, 27 Jul 2015 14:49:33 -0500 Subject: [PATCH 05/10] further refinement --- libraries/helpers.rb | 6 + libraries/provider_elasticsearch.rb | 10 +- libraries/provider_elasticsearch_config.rb | 46 --- libraries/provider_kibana.rb | 42 ++ libraries/provider_kibana_config.rb | 48 --- libraries/resource_elasticsearch.rb | 61 +-- libraries/resource_kibana.rb | 36 +- libraries/resource_logstash.rb | 2 +- libraries/resource_logstash_forwarder.rb | 2 +- .../elasticsearch/elasticsearch.sysconfig.erb | 76 ---- .../elasticsearch/elasticsearch.yml.erb | 387 ------------------ templates/default/sv-elasticsearch-run.erb | 3 +- templates/default/sv-kibana-run.erb | 5 +- test/cookbooks/elktest/recipes/default.rb | 4 +- .../elktest/recipes/elasticsearch.rb | 5 - test/cookbooks/elktest/recipes/kibana.rb | 6 - test/cookbooks/elktest/recipes/logstash.rb | 9 +- .../elktest/recipes/logstash_forwarder.rb | 9 +- 18 files changed, 114 insertions(+), 643 deletions(-) create mode 100644 libraries/helpers.rb delete mode 100644 libraries/provider_elasticsearch_config.rb delete mode 100644 libraries/provider_kibana_config.rb delete mode 100755 templates/default/elasticsearch/elasticsearch.sysconfig.erb delete mode 100755 templates/default/elasticsearch/elasticsearch.yml.erb diff --git a/libraries/helpers.rb b/libraries/helpers.rb new file mode 100644 index 0000000..53cc90c --- /dev/null +++ b/libraries/helpers.rb @@ -0,0 +1,6 @@ +require 'chef' + +module ELK + module Helpers + end +end diff --git a/libraries/provider_elasticsearch.rb b/libraries/provider_elasticsearch.rb index bb1f4fb..fbc55f4 100644 --- a/libraries/provider_elasticsearch.rb +++ b/libraries/provider_elasticsearch.rb @@ -1,9 +1,12 @@ class Chef class Provider class Elasticsearch < Chef::Provider::LWRPBase + include ELK::Helpers + use_inline_resources if defined?(use_inline_resources) provides :elasticsearch + service_name = 'elasticsearch' action :install do @@ -15,7 +18,6 @@ class Elasticsearch < Chef::Provider::LWRPBase group new_resource.group has_binaries new_resource.has_binaries owner new_resource.user - prefix_bin new_resource.prefix_bin prefix_root new_resource.path url new_resource.url version new_resource.version @@ -26,6 +28,12 @@ class Elasticsearch < Chef::Provider::LWRPBase owner new_resource.user group new_resource.group cookbook new_resource.source + env new_resource.runit_env + options new_resource.runit_options.merge( + 'install_path' => "#{new_resource.path}/#{new_resource.name}-#{new_resource.version}", + 'user' => new_resource.user, + 'group' => new_resource.group + ) action [:create, :enable] end end diff --git a/libraries/provider_elasticsearch_config.rb b/libraries/provider_elasticsearch_config.rb deleted file mode 100644 index 5869e7b..0000000 --- a/libraries/provider_elasticsearch_config.rb +++ /dev/null @@ -1,46 +0,0 @@ -class Chef - class Provider - class ElasticsearchConfig < Chef::Provider::LWRPBase - use_inline_resources if defined?(use_inline_resources) - - provides :elasticsearch_config - - action :create do - directory '/etc/elasticsearch' do - mode '0755' - action :create - recursive true - end - - template '/etc/elasticsearch/elasticsearch.yml' do - source 'elasticsearch/elasticsearch.yml.erb' - owner 'elasticsearch' - group 'elasticsearch' - mode '0644' - cookbook new_resource.source - variables options: { - 'conf_dir' => new_resource.conf_dir, - 'conf_file' => new_resource.conf_file, - 'data_dir' => new_resource.data_dir, - 'es_direct_size' => new_resource.es_direct_size, - 'es_group' => new_resource.es_group, - 'es_heap_newsize' => new_resource.es_heap_newsize, - 'es_heap_size' => new_resource.es_heap_size, - 'es_home' => new_resource.es_home, - 'es_java_opts' => new_resource.es_java_opts, - 'es_user' => new_resource.es_user, - 'log_dir' => new_resource.log_dir, - 'max_locked_memory' => new_resource.max_locked_memory, - 'max_map_count' => new_resource.max_map_count, - 'max_open_files' => new_resource.max_open_files, - 'pid_dir' => new_resource.pid_dir, - 'restart_on_upgrade' => new_resource.restart_on_upgrade, - 'work_dir' => new_resource.work_dir - } - end - end - action :delete do - end - end - end -end diff --git a/libraries/provider_kibana.rb b/libraries/provider_kibana.rb index 8197d0a..ec22215 100644 --- a/libraries/provider_kibana.rb +++ b/libraries/provider_kibana.rb @@ -11,6 +11,7 @@ class Kibana < Chef::Provider::LWRPBase user new_resource.user group new_resource.group + # ARK ark service_name do checksum new_resource.checksum group new_resource.group @@ -21,13 +22,54 @@ class Kibana < Chef::Provider::LWRPBase version new_resource.version end + home_dir = "#{new_resource.path}/kibana-#{new_resource.version}" + + # RUNIT runit_service service_name do default_logger true owner new_resource.user group new_resource.group cookbook new_resource.source + env new_resource.runit_env + options new_resource.runit_options.merge( + 'install_path' => home_dir, + 'user' => new_resource.user, + 'group' => new_resource.group, + 'config_file' => "#{home_dir}/config/kibana.yml" + ) action [:create, :enable] end + + template "#{home_dir}/config/kibana.yml" do + source 'kibana/kibana.yml.erb' + owner new_resource.user + owner new_resource.group + mode '0644' + cookbook new_resource.source + variables options: { + 'default_app_id' => new_resource.default_app_id, + 'elasticsearch_preserve_host' => new_resource.elasticsearch_preserve_host, + 'elasticsearch_url' => new_resource.elasticsearch_url, + 'group' => new_resource.group, + 'host' => new_resource.host, + 'kibana_elasticsearch_client_crt' => new_resource.kibana_elasticsearch_client_crt, + 'kibana_elasticsearch_client_key' => new_resource.kibana_elasticsearch_client_key, + 'kibana_elasticsearch_password' => new_resource.kibana_elasticsearch_password, + 'kibana_elasticsearch_username' => new_resource.kibana_elasticsearch_username, + 'kibana_index' => new_resource.kibana_index, + 'log_file' => new_resource.log_file, + 'pid_file' => new_resource.pid_file, + 'ping_timeout' => new_resource.ping_timeout, + 'port' => new_resource.port, + 'request_timeout' => new_resource.request_timeout, + 'shard_timeout' => new_resource.shard_timeout, + 'ssl_cert_file' => new_resource.ssl_cert_file, + 'ssl_key_file' => new_resource.ssl_key_file, + 'startup_timeout' => new_resource.startup_timeout, + 'user' => new_resource.user, + 'verify_ssl' => new_resource.verify_ssl + } + end end action :remove do diff --git a/libraries/provider_kibana_config.rb b/libraries/provider_kibana_config.rb deleted file mode 100644 index d336a0f..0000000 --- a/libraries/provider_kibana_config.rb +++ /dev/null @@ -1,48 +0,0 @@ -class Chef - class Provider - class KibanaConfig < Chef::Provider::LWRPBase - use_inline_resources if defined?(use_inline_resources) - - provides :kibana_config - - action :create do - directory '/etc/kibana' do - mode '0755' - action :create - recursive true - end - - template '/etc/kibana/kibana.yml' do - source 'kibana/kibana.yml.erb' - owner new_resource.user - owner new_resource.group - mode '0644' - cookbook new_resource.source - variables options: { - 'default_app_id' => new_resource.default_app_id, - 'elasticsearch_preserve_host' => new_resource.elasticsearch_preserve_host, - 'elasticsearch_url' => new_resource.elasticsearch_url, - 'group' => new_resource.group, - 'host' => new_resource.host, - 'kibana_elasticsearch_client_crt' => new_resource.kibana_elasticsearch_client_crt, - 'kibana_elasticsearch_client_key' => new_resource.kibana_elasticsearch_client_key, - 'kibana_elasticsearch_password' => new_resource.kibana_elasticsearch_password, - 'kibana_elasticsearch_username' => new_resource.kibana_elasticsearch_username, - 'kibana_index' => new_resource.kibana_index, - 'log_file' => new_resource.log_file, - 'pid_file' => new_resource.pid_file, - 'ping_timeout' => new_resource.ping_timeout, - 'port' => new_resource.port, - 'request_timeout' => new_resource.request_timeout, - 'shard_timeout' => new_resource.shard_timeout, - 'ssl_cert_file' => new_resource.ssl_cert_file, - 'ssl_key_file' => new_resource.ssl_key_file, - 'startup_timeout' => new_resource.startup_timeout, - 'user' => new_resource.user, - 'verify_ssl' => new_resource.verify_ssl - } - end - end - end - end -end diff --git a/libraries/resource_elasticsearch.rb b/libraries/resource_elasticsearch.rb index fd85270..de21cae 100644 --- a/libraries/resource_elasticsearch.rb +++ b/libraries/resource_elasticsearch.rb @@ -12,47 +12,48 @@ class Elasticsearch < Chef::Resource::LWRPBase # used to target any files/templates; default to self attribute :source, kind_of: String, default: 'elk' + # ARK # url and sha256 of the archive to download and unpack attribute :url, kind_of: String, default: 'https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.0.tar.gz' attribute :checksum, kind_of: String, default: '6fabed2db09e1b88587df15269df328ecef33e155b3c675a2a6d2299bda09c95' - - # ARK tracks verioning by appending the :name with this for symlinking to a path attribute :version, kind_of: String, default: '1.7.0' attribute :has_binaries, kind_of: Array, default: ['bin/elasticsearch'] - attribute :append_env_path, kind_of: [TrueClass, FalseClass], default: false + # attribute :append_env_path, kind_of: [TrueClass, FalseClass], default: false - # USER/GROUP to install by, also creates users on the OS for them + attribute :name, kind_of: String, default: 'elasticsearch' attribute :user, kind_of: String, default: 'elasticsearch' attribute :group, kind_of: String, default: 'elasticsearch' attribute :owner, kind_of: String, default: 'elasticsearch' - attribute :path, kind_of: String, default: '/opt/elasticsearch' - attribute :prefix_bin, kind_of: String, default: '/opt/bin' - end - class ElasticsearchConfig < Chef::Resource::LWRPBase - resource_name :elasticsearch_config - default_action :create - actions [:create, :delete] - - attribute :conf_dir, kind_of: String, default: '/etc/elasticsearch' - attribute :conf_file, kind_of: String, default: '/etc/elasticsearch/elasticsearch.yml' - attribute :data_dir, kind_of: String, default: '/var/lib/elasticsearch' - attribute :es_direct_size, kind_of: String, default: nil - attribute :es_group, kind_of: String, default: 'elasticsearch' - attribute :es_heap_newsize, kind_of: String, default: nil - attribute :es_heap_size, kind_of: String, default: '1g' - attribute :es_home, kind_of: String, default: '/usr/share/elasticsearch' - attribute :es_java_opts, kind_of: String, default: nil - attribute :es_user, kind_of: String, default: 'elasticsearch' - attribute :log_dir, kind_of: String, default: '/var/log/elasticsearch' - attribute :max_locked_memory, kind_of: String, default: 'unlimited' - attribute :max_map_count, kind_of: Integer, default: 65_535 - attribute :max_open_files, kind_of: Integer, default: 65_535 - attribute :pid_dir, kind_of: String, default: '/var/run/elasticsearch' - attribute :restart_on_upgrade, kind_of: [TrueClass, FalseClass], default: false - attribute :source, kind_of: String, default: 'elk' - attribute :work_dir, kind_of: String, default: '/tmp/elasticsearch' + # RUNIT + attribute :runit_args, kind_of: Hash, default: { + + } + + attribute :runit_options, kind_of: Hash, default: { + + } + attribute :runit_env, kind_of: Hash, default: { + 'CONF_DIR' => '/etc/elasticsearch', + 'CONF_FILE' => '$CONF_DIR/elasticsearch.yml', + 'DATA_DIR' => '/var/lib/elasticsearch', + 'ES_DIRECT_SIZE' => '', + 'ES_GC_LOG_FILE' => '/var/log/elasticsearch/gc.log', + 'ES_GROUP' => 'elasticsearch', + 'ES_HEAP_NEWSIZE' => '', + 'ES_HEAP_SIZE' => '2g', + 'ES_HOME' => '/usr/share/elasticsearch', + 'ES_JAVA_OPTS' => '', + 'ES_RESTART_ON_UPGRADE' => 'true', + 'ES_USER' => 'elasticsearch', + 'LOG_DIR' => '/var/log/elasticsearch', + 'MAX_LOCKED_MEMORY' => 'unlimited', + 'MAX_MAP_COUNT' => '262144', + 'MAX_OPEN_FILES' => '65535', + 'PID_DIR' => '/var/run/elasticsearch', + 'WORK_DIR' => '/tmp/elasticsearch' + } end end end diff --git a/libraries/resource_kibana.rb b/libraries/resource_kibana.rb index dee3ede..73cb3f6 100644 --- a/libraries/resource_kibana.rb +++ b/libraries/resource_kibana.rb @@ -8,44 +8,38 @@ class Kibana < Chef::Resource::LWRPBase actions [:install, :remove, :enable, :disable, :restart, :start, :stop] attribute :checksum, kind_of: String, default: '6f42d25f337fd49f38e2af81b9ab6e0c987a199a8c0b2e1410d072f812cb4520' - attribute :group, kind_of: String, default: 'kibana' - attribute :host, kind_of: String, default: '127.0.0.1' - attribute :path, kind_of: String, default: '/opt/kibana' - attribute :port, kind_of: [String, Integer], default: 3000 - attribute :url, kind_of: String, default: 'https://download.elastic.co/kibana/kibana/kibana-4.1.1-linux-x64.tar.gz' - attribute :user, kind_of: String, default: 'kibana' - attribute :version, kind_of: String, default: '4.1.1' - - attribute :source, kind_of: String, default: 'elk' - end - - class KibanaConfig < Chef::Resource::LWRPBase - resource_name :kibana_config - default_action :create - actions [:create, :delete] - - attribute :group, kind_of: String, default: 'kibana' - attribute :kibana_elasticsearch_password, kind_of: String, default: nil - attribute :user, kind_of: String, default: 'kibana' attribute :default_app_id, kind_of: String, default: 'discover' + attribute :elasticsearch_host, kind_of: String, default: '127.0.0.1' + attribute :elasticsearch_port, kind_of: Integer, default: 5601 attribute :elasticsearch_preserve_host, kind_of: [TrueClass, FalseClass], default: true attribute :elasticsearch_url, kind_of: String, default: 'http://localhost:9200' + attribute :group, kind_of: String, default: 'kibana' attribute :host, kind_of: String, default: '0.0.0.0' attribute :kibana_elasticsearch_client_crt, kind_of: String, default: nil attribute :kibana_elasticsearch_client_key, kind_of: String, default: nil + attribute :kibana_elasticsearch_password, kind_of: String, default: nil attribute :kibana_elasticsearch_username, kind_of: String, default: nil attribute :kibana_index, kind_of: String, default: '.kibana' attribute :log_file, kind_of: Integer, default: './kibana.log' + attribute :path, kind_of: String, default: '/opt/kibana' attribute :pid_file, kind_of: String, default: '/var/run/kibana.pid' attribute :ping_timeout, kind_of: Integer, default: 1500 - attribute :port, kind_of: Integer, default: 5601 + attribute :port, kind_of: [String, Integer], default: 3000 attribute :request_timeout, kind_of: Integer, default: 30_000 attribute :shard_timeout, kind_of: Integer, default: 0 + attribute :source, kind_of: String, default: 'elk' attribute :ssl_cert_file, kind_of: String, default: nil attribute :ssl_key_file, kind_of: String, default: nil - attribute :source, kind_of: String, default: 'elk' attribute :startup_timeout, kind_of: Integer, default: 5000 + attribute :url, kind_of: String, default: 'https://download.elastic.co/kibana/kibana/kibana-4.1.1-linux-x64.tar.gz' + attribute :user, kind_of: String, default: 'kibana' attribute :verify_ssl, kind_of: [TrueClass, FalseClass], default: true + attribute :version, kind_of: String, default: '4.1.1' + + # RUNIT + attribute :runit_args, kind_of: Hash, default: {} + attribute :runit_options, kind_of: Hash, default: {} + attribute :runit_env, kind_of: Hash, default: {} end end end diff --git a/libraries/resource_logstash.rb b/libraries/resource_logstash.rb index fb223dc..c26d4fe 100644 --- a/libraries/resource_logstash.rb +++ b/libraries/resource_logstash.rb @@ -26,7 +26,7 @@ class Logstash < Chef::Resource::LWRPBase attribute :path, kind_of: String, default: '/opt/logstash' end - + class LogstashConfig < Chef::Resource::LWRPBase resource_name :logstash_config default_action :create diff --git a/libraries/resource_logstash_forwarder.rb b/libraries/resource_logstash_forwarder.rb index 09f1ab2..c2cc49c 100644 --- a/libraries/resource_logstash_forwarder.rb +++ b/libraries/resource_logstash_forwarder.rb @@ -14,7 +14,7 @@ class LogstashForwarder < Chef::Resource::LWRPBase attribute :user, kind_of: String, default: 'logstash' attribute :version, kind_of: String, default: '0.4.0' end - + class LogstashForwarderConfig < Chef::Resource::LWRPBase resource_name :logstash_forwarder_config default_action :create diff --git a/templates/default/elasticsearch/elasticsearch.sysconfig.erb b/templates/default/elasticsearch/elasticsearch.sysconfig.erb deleted file mode 100755 index 5694c36..0000000 --- a/templates/default/elasticsearch/elasticsearch.sysconfig.erb +++ /dev/null @@ -1,76 +0,0 @@ -# This file was generated by Chef -# Do NOT modify this file by hand. - -################################ -# Elasticsearch -################################ - -# Elasticsearch home directory -ES_HOME=<%= @options['es_home'] %> - -# Elasticsearch configuration directory -CONF_DIR=<%= @options['conf_dir'] %> - -# Elasticsearch configuration file -CONF_FILE=<%= @options['conf_file'] %> - -# Elasticsearch data directory -DATA_DIR=<%= @options['data_dir'] %> - -# Elasticsearch logs directory -LOG_DIR=<%= @options['log_dir'] %> - -# Elasticsearch work directory -WORK_DIR=<%= @options['work_dir'] %> - -# Elasticsearch PID directory -PID_DIR=<%= @options['pid_dir'] %> - -# 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=<%= @options['es_heap_size'] %> - -<%= "ES_DIRECT_SIZE=#{@options['es_direct_size']}" if @options['es_direct_size'] -%> -<%= "ES_HEAP_NEWSIZE=#{@options['es_heap_newsize']}" if @options['es_heap_newsize'] -%> -<%= "ES_JAVA_OPTS=#{@options['es_java_opts']}" if @options['es_java_opts'] -%> - -# Configure restart on package upgrade (true, every other setting will lead to not restarting) -ES_RESTART_ON_UPGRADE=<%= @options['restart_on_upgrade'] %> - -# Path to the GC log file -#ES_GC_LOG_FILE=/var/log/elasticsearch/gc.log - -################################ -# Elasticsearch service -################################ - -# SysV init.d -# -# When executing the init script, this user will be used to run the elasticsearch service. -# The default value is 'elasticsearch' and is declared in the init.d file. -# Note that this setting is only used by the init script. If changed, make sure that -# the configured user can read and write into the data, work, plugins and log directories. -# For systemd service, the user is usually configured in file /usr/lib/systemd/system/elasticsearch.service -ES_USER=<%= @options['es_user'] %> -ES_GROUP=<%= @options['es_group'] %> - -################################ -# System properties -################################ - -# Specifies the maximum file descriptor number that can be opened by this process -# When using Systemd, this setting is ignored and the LimitNOFILE defined in -# /usr/lib/systemd/system/elasticsearch.service takes precedence -MAX_OPEN_FILES=<%= @options['max_open_files'] %> - -# The maximum number of bytes of memory that may be locked into RAM -# Set to "unlimited" if you use the 'bootstrap.mlockall: true' option -# in elasticsearch.yml (ES_HEAP_SIZE must also be set). -# When using Systemd, the LimitMEMLOCK property must be set -# in /usr/lib/systemd/system/elasticsearch.service -MAX_LOCKED_MEMORY=<%= @options['max_locked_memory'] %> - -# Maximum number of VMA (Virtual Memory Areas) a process can own -# When using Systemd, this setting is ignored and the 'vm.max_map_count' -# property is set at boot time in /usr/lib/sysctl.d/elasticsearch.conf -MAX_MAP_COUNT=<%= @options['max_map_count'] %> diff --git a/templates/default/elasticsearch/elasticsearch.yml.erb b/templates/default/elasticsearch/elasticsearch.yml.erb deleted file mode 100755 index 8f15f14..0000000 --- a/templates/default/elasticsearch/elasticsearch.yml.erb +++ /dev/null @@ -1,387 +0,0 @@ -# This file was generated by Chef -# Do NOT modify this file by hand. -##################### Elasticsearch Configuration Example ##################### - -# This file contains an overview of various configuration settings, -# targeted at operations staff. Application developers should -# consult the guide at . -# -# The installation procedure is covered at -# . -# -# Elasticsearch comes with reasonable defaults for most settings, -# so you can try it out without bothering with configuration. -# -# Most of the time, these defaults are just fine for running a production -# cluster. If you're fine-tuning your cluster, or wondering about the -# effect of certain configuration option, please _do ask_ on the -# mailing list or IRC channel [http://elasticsearch.org/community]. - -# Any element in the configuration can be replaced with environment variables -# by placing them in ${...} notation. For example: -# -#node.rack: ${RACK_ENV_VAR} - -# For information on supported formats and syntax for the config file, see -# - - -################################### Cluster ################################### - -# Cluster name identifies your cluster for auto-discovery. If you're running -# multiple clusters on the same network, make sure you're using unique names. -# -#cluster.name: elasticsearch - - -#################################### Node ##################################### - -# Node names are generated dynamically on startup, so you're relieved -# from configuring them manually. You can tie this node to a specific name: -# -#node.name: "Franz Kafka" - -# Every node can be configured to allow or deny being eligible as the master, -# and to allow or deny to store the data. -# -# Allow this node to be eligible as a master node (enabled by default): -# -#node.master: true -# -# Allow this node to store data (enabled by default): -# -#node.data: true - -# You can exploit these settings to design advanced cluster topologies. -# -# 1. You want this node to never become a master node, only to hold data. -# This will be the "workhorse" of your cluster. -# -#node.master: false -#node.data: true -# -# 2. You want this node to only serve as a master: to not store any data and -# to have free resources. This will be the "coordinator" of your cluster. -# -#node.master: true -#node.data: false -# -# 3. You want this node to be neither master nor data node, but -# to act as a "search load balancer" (fetching data from nodes, -# aggregating results, etc.) -# -#node.master: false -#node.data: false - -# Use the Cluster Health API [http://localhost:9200/_cluster/health], the -# Node Info API [http://localhost:9200/_nodes] or GUI tools -# such as , -# , -# and -# to inspect the cluster state. - -# A node can have generic attributes associated with it, which can later be used -# for customized shard allocation filtering, or allocation awareness. An attribute -# is a simple key value pair, similar to node.key: value, here is an example: -# -#node.rack: rack314 - -# By default, multiple nodes are allowed to start from the same installation location -# to disable it, set the following: -#node.max_local_storage_nodes: 1 - - -#################################### Index #################################### - -# You can set a number of options (such as shard/replica options, mapping -# or analyzer definitions, translog settings, ...) for indices globally, -# in this file. -# -# Note, that it makes more sense to configure index settings specifically for -# a certain index, either when creating it or by using the index templates API. -# -# See and -# -# for more information. - -# Set the number of shards (splits) of an index (5 by default): -# -#index.number_of_shards: 5 - -# Set the number of replicas (additional copies) of an index (1 by default): -# -#index.number_of_replicas: 1 - -# Note, that for development on a local machine, with small indices, it usually -# makes sense to "disable" the distributed features: -# -#index.number_of_shards: 1 -#index.number_of_replicas: 0 - -# These settings directly affect the performance of index and search operations -# in your cluster. Assuming you have enough machines to hold shards and -# replicas, the rule of thumb is: -# -# 1. Having more *shards* enhances the _indexing_ performance and allows to -# _distribute_ a big index across machines. -# 2. Having more *replicas* enhances the _search_ performance and improves the -# cluster _availability_. -# -# The "number_of_shards" is a one-time setting for an index. -# -# The "number_of_replicas" can be increased or decreased anytime, -# by using the Index Update Settings API. -# -# Elasticsearch takes care about load balancing, relocating, gathering the -# results from nodes, etc. Experiment with different settings to fine-tune -# your setup. - -# Use the Index Status API () to inspect -# the index status. - - -#################################### Paths #################################### - -# Path to directory containing configuration (this file and logging.yml): -# -#path.conf: /path/to/conf - -# Path to directory where to store index data allocated for this node. -# -#path.data: /path/to/data -# -# Can optionally include more than one location, causing data to be striped across -# the locations (a la RAID 0) on a file level, favouring locations with most free -# space on creation. For example: -# -#path.data: /path/to/data1,/path/to/data2 - -# Path to temporary files: -# -#path.work: /path/to/work - -# Path to log files: -# -#path.logs: /path/to/logs - -# Path to where plugins are installed: -# -#path.plugins: /path/to/plugins - - -#################################### Plugin ################################### - -# If a plugin listed here is not installed for current node, the node will not start. -# -#plugin.mandatory: mapper-attachments,lang-groovy - - -################################### Memory #################################### - -# Elasticsearch performs poorly when JVM starts swapping: you should ensure that -# it _never_ swaps. -# -# Set this property to true to lock the memory: -# -#bootstrap.mlockall: true - -# Make sure that the ES_MIN_MEM and ES_MAX_MEM environment variables are set -# to the same value, and that the machine has enough memory to allocate -# for Elasticsearch, leaving enough memory for the operating system itself. -# -# You should also make sure that the Elasticsearch process is allowed to lock -# the memory, eg. by using `ulimit -l unlimited`. - - -############################## Network And HTTP ############################### - -# Elasticsearch, by default, binds itself to the 0.0.0.0 address, and listens -# on port [9200-9300] for HTTP traffic and on port [9300-9400] for node-to-node -# communication. (the range means that if the port is busy, it will automatically -# try the next port). - -# Set the bind address specifically (IPv4 or IPv6): -# -#network.bind_host: 192.168.0.1 - -# Set the address other nodes will use to communicate with this node. If not -# set, it is automatically derived. It must point to an actual IP address. -# -#network.publish_host: 192.168.0.1 - -# Set both 'bind_host' and 'publish_host': -# -#network.host: 192.168.0.1 - -# Set a custom port for the node to node communication (9300 by default): -# -#transport.tcp.port: 9300 - -# Enable compression for all communication between nodes (disabled by default): -# -#transport.tcp.compress: true - -# Set a custom port to listen for HTTP traffic: -# -#http.port: 9200 - -# Set a custom allowed content length: -# -#http.max_content_length: 100mb - -# Disable HTTP completely: -# -#http.enabled: false - - -################################### Gateway ################################### - -# The gateway allows for persisting the cluster state between full cluster -# restarts. Every change to the state (such as adding an index) will be stored -# in the gateway, and when the cluster starts up for the first time, -# it will read its state from the gateway. - -# There are several types of gateway implementations. For more information, see -# . - -# The default gateway type is the "local" gateway (recommended): -# -#gateway.type: local - -# Settings below control how and when to start the initial recovery process on -# a full cluster restart (to reuse as much local data as possible when using shared -# gateway). - -# Allow recovery process after N nodes in a cluster are up: -# -#gateway.recover_after_nodes: 1 - -# Set the timeout to initiate the recovery process, once the N nodes -# from previous setting are up (accepts time value): -# -#gateway.recover_after_time: 5m - -# Set how many nodes are expected in this cluster. Once these N nodes -# are up (and recover_after_nodes is met), begin recovery process immediately -# (without waiting for recover_after_time to expire): -# -#gateway.expected_nodes: 2 - - -############################# Recovery Throttling ############################# - -# These settings allow to control the process of shards allocation between -# nodes during initial recovery, replica allocation, rebalancing, -# or when adding and removing nodes. - -# Set the number of concurrent recoveries happening on a node: -# -# 1. During the initial recovery -# -#cluster.routing.allocation.node_initial_primaries_recoveries: 4 -# -# 2. During adding/removing nodes, rebalancing, etc -# -#cluster.routing.allocation.node_concurrent_recoveries: 2 - -# Set to throttle throughput when recovering (eg. 100mb, by default 20mb): -# -#indices.recovery.max_bytes_per_sec: 20mb - -# Set to limit the number of open concurrent streams when -# recovering a shard from a peer: -# -#indices.recovery.concurrent_streams: 5 - - -################################## Discovery ################################## - -# Discovery infrastructure ensures nodes can be found within a cluster -# and master node is elected. Multicast discovery is the default. - -# Set to ensure a node sees N other master eligible nodes to be considered -# operational within the cluster. This should be set to a quorum/majority of -# the master-eligible nodes in the cluster. -# -#discovery.zen.minimum_master_nodes: 1 - -# Set the time to wait for ping responses from other nodes when discovering. -# Set this option to a higher value on a slow or congested network -# to minimize discovery failures: -# -#discovery.zen.ping.timeout: 3s - -# For more information, see -# - -# Unicast discovery allows to explicitly control which nodes will be used -# to discover the cluster. It can be used when multicast is not present, -# or to restrict the cluster communication-wise. -# -# 1. Disable multicast discovery (enabled by default): -# -#discovery.zen.ping.multicast.enabled: false -# -# 2. Configure an initial list of master nodes in the cluster -# to perform discovery when new nodes (master or data) are started: -# -#discovery.zen.ping.unicast.hosts: ["host1", "host2:port"] - -# EC2 discovery allows to use AWS EC2 API in order to perform discovery. -# -# You have to install the cloud-aws plugin for enabling the EC2 discovery. -# -# For more information, see -# -# -# See -# for a step-by-step tutorial. - -# GCE discovery allows to use Google Compute Engine API in order to perform discovery. -# -# You have to install the cloud-gce plugin for enabling the GCE discovery. -# -# For more information, see . - -# Azure discovery allows to use Azure API in order to perform discovery. -# -# You have to install the cloud-azure plugin for enabling the Azure discovery. -# -# For more information, see . - -################################## Slow Log ################################## - -# Shard level query and fetch threshold logging. - -#index.search.slowlog.threshold.query.warn: 10s -#index.search.slowlog.threshold.query.info: 5s -#index.search.slowlog.threshold.query.debug: 2s -#index.search.slowlog.threshold.query.trace: 500ms - -#index.search.slowlog.threshold.fetch.warn: 1s -#index.search.slowlog.threshold.fetch.info: 800ms -#index.search.slowlog.threshold.fetch.debug: 500ms -#index.search.slowlog.threshold.fetch.trace: 200ms - -#index.indexing.slowlog.threshold.index.warn: 10s -#index.indexing.slowlog.threshold.index.info: 5s -#index.indexing.slowlog.threshold.index.debug: 2s -#index.indexing.slowlog.threshold.index.trace: 500ms - -################################## GC Logging ################################ - -#monitor.jvm.gc.young.warn: 1000ms -#monitor.jvm.gc.young.info: 700ms -#monitor.jvm.gc.young.debug: 400ms - -#monitor.jvm.gc.old.warn: 10s -#monitor.jvm.gc.old.info: 5s -#monitor.jvm.gc.old.debug: 2s - -################################## Security ################################ - -# Uncomment if you want to enable JSONP as a valid return transport on the -# http server. With this enabled, it may pose a security risk, so disabling -# it unless you need it is recommended (it is disabled by default). -# -#http.jsonp.enable: true diff --git a/templates/default/sv-elasticsearch-run.erb b/templates/default/sv-elasticsearch-run.erb index fb801ab..aa7042d 100644 --- a/templates/default/sv-elasticsearch-run.erb +++ b/templates/default/sv-elasticsearch-run.erb @@ -1,6 +1,7 @@ #!/bin/sh -cd /opt/elasticsearch +cd <%= @options['install_path'] %> exec 2>&1 +chpst -u :<%= @options['user'] %>:<%= @options['group'] %> exec ./bin/elasticsearch diff --git a/templates/default/sv-kibana-run.erb b/templates/default/sv-kibana-run.erb index 7436962..012447c 100644 --- a/templates/default/sv-kibana-run.erb +++ b/templates/default/sv-kibana-run.erb @@ -1,6 +1,7 @@ #!/bin/sh -cd /home/kibana +cd <%= @options['install_path'] %> exec 2>&1 -exec /usr/bin/env kibana -c /etc/kibana.yml +chpst -u :<%= @options['user'] %>:<%= @options['group'] %> +exec ./bin/kibana -c <%= @options['config_file'] %> diff --git a/test/cookbooks/elktest/recipes/default.rb b/test/cookbooks/elktest/recipes/default.rb index 2afbb10..4766019 100644 --- a/test/cookbooks/elktest/recipes/default.rb +++ b/test/cookbooks/elktest/recipes/default.rb @@ -7,6 +7,6 @@ include_recipe 'runit::default' include_recipe 'elktest::elasticsearch' -include_recipe 'elktest::logstash' -include_recipe 'elktest::logstash_forwarder' +# include_recipe 'elktest::logstash' +# include_recipe 'elktest::logstash_forwarder' include_recipe 'elktest::kibana' diff --git a/test/cookbooks/elktest/recipes/elasticsearch.rb b/test/cookbooks/elktest/recipes/elasticsearch.rb index 1599aee..5ca6074 100644 --- a/test/cookbooks/elktest/recipes/elasticsearch.rb +++ b/test/cookbooks/elktest/recipes/elasticsearch.rb @@ -1,6 +1 @@ elasticsearch 'default' - -elasticsearch_config 'default' do - action :create - notifies :start, 'elasticsearch[default]' -end diff --git a/test/cookbooks/elktest/recipes/kibana.rb b/test/cookbooks/elktest/recipes/kibana.rb index f2e4a0c..78dcc8a 100644 --- a/test/cookbooks/elktest/recipes/kibana.rb +++ b/test/cookbooks/elktest/recipes/kibana.rb @@ -1,7 +1 @@ kibana 'default' - -kibana_config 'default' do - port 8080 - action :create - notifies :restart, 'kibana[default]' -end diff --git a/test/cookbooks/elktest/recipes/logstash.rb b/test/cookbooks/elktest/recipes/logstash.rb index 6698214..f719738 100644 --- a/test/cookbooks/elktest/recipes/logstash.rb +++ b/test/cookbooks/elktest/recipes/logstash.rb @@ -1,5 +1,3 @@ -logstash 'default' - secrets = Chef::DataBagItem.load('secrets', 'logstash') logstash_key = Base64.decode64(secrets['key']) logstash_crt = Base64.decode64(secrets['certificate']) @@ -17,9 +15,4 @@ content logstash_crt end -logstash_config 'default' do - action :create - key logstash_key - crt logstash_crt - notifies :restart, 'logstash[default]' -end +logstash 'default' diff --git a/test/cookbooks/elktest/recipes/logstash_forwarder.rb b/test/cookbooks/elktest/recipes/logstash_forwarder.rb index 670f0c9..daa7ac9 100644 --- a/test/cookbooks/elktest/recipes/logstash_forwarder.rb +++ b/test/cookbooks/elktest/recipes/logstash_forwarder.rb @@ -1,5 +1,3 @@ -logstash_forwarder 'default' - secrets = Chef::DataBagItem.load('secrets', 'logstash') logstash_key = Base64.decode64(secrets['key']) logstash_crt = Base64.decode64(secrets['certificate']) @@ -11,9 +9,4 @@ content logstash_crt end -logstash_forwarder_config 'default' do - action :create - key logstash_key - crt logstash_crt - notifies :restart, 'logstash_forwarder[default]' -end +logstash_forwarder 'default' From dd58ff753d325f4da710a207750529a4e75cfc0e Mon Sep 17 00:00:00 2001 From: Jacob Dearing Date: Mon, 27 Jul 2015 16:22:04 -0500 Subject: [PATCH 06/10] even more runity --- libraries/provider_kibana.rb | 32 ++++++++-------- libraries/provider_logstash_forwarder.rb | 36 ++++++++++++++++-- .../provider_logstash_forwarder_config.rb | 38 ------------------- libraries/resource_logstash_forwarder.rb | 20 ++++------ .../default/sv-logstash-forwarder-run.erb | 7 ++++ .../default/sv-logstash_forwarder-run.erb | 6 --- test/cookbooks/elktest/recipes/default.rb | 2 +- test/cookbooks/elktest/recipes/logstash.rb | 10 +---- .../elktest/recipes/logstash_forwarder.rb | 9 +++-- 9 files changed, 73 insertions(+), 87 deletions(-) delete mode 100644 libraries/provider_logstash_forwarder_config.rb create mode 100644 templates/default/sv-logstash-forwarder-run.erb delete mode 100644 templates/default/sv-logstash_forwarder-run.erb diff --git a/libraries/provider_kibana.rb b/libraries/provider_kibana.rb index ec22215..36a1be6 100644 --- a/libraries/provider_kibana.rb +++ b/libraries/provider_kibana.rb @@ -24,22 +24,6 @@ class Kibana < Chef::Provider::LWRPBase home_dir = "#{new_resource.path}/kibana-#{new_resource.version}" - # RUNIT - runit_service service_name do - default_logger true - owner new_resource.user - group new_resource.group - cookbook new_resource.source - env new_resource.runit_env - options new_resource.runit_options.merge( - 'install_path' => home_dir, - 'user' => new_resource.user, - 'group' => new_resource.group, - 'config_file' => "#{home_dir}/config/kibana.yml" - ) - action [:create, :enable] - end - template "#{home_dir}/config/kibana.yml" do source 'kibana/kibana.yml.erb' owner new_resource.user @@ -70,6 +54,22 @@ class Kibana < Chef::Provider::LWRPBase 'verify_ssl' => new_resource.verify_ssl } end + + # RUNIT + runit_service service_name do + default_logger true + owner new_resource.user + group new_resource.group + cookbook new_resource.source + env new_resource.runit_env + options new_resource.runit_options.merge( + 'install_path' => home_dir, + 'user' => new_resource.user, + 'group' => new_resource.group, + 'config_file' => "#{home_dir}/config/kibana.yml" + ) + action [:create, :enable] + end end action :remove do diff --git a/libraries/provider_logstash_forwarder.rb b/libraries/provider_logstash_forwarder.rb index 52b5442..8630cfb 100644 --- a/libraries/provider_logstash_forwarder.rb +++ b/libraries/provider_logstash_forwarder.rb @@ -4,14 +4,26 @@ class LogstashForwarder < Chef::Provider::LWRPBase use_inline_resources if defined?(use_inline_resources) provides :logstash_forwarder - service_name = 'logstash_forwarder' + service_name = 'logstash-forwarder' action :install do + # TODO: make home folder working dir user new_resource.user group new_resource.group + home_dir = "/opt/logstash-forwarder/logstash-forwarder-#{new_resource.version}" + + # TODO: sloppy + directory home_dir do + owner new_resource.user + group new_resource.group + mode '0755' + recursive true + action :create + end + # TODO: react to os/arch - remote_file '/opt/bin/logstash-forwarder' do + remote_file "#{home_dir}/logstash-forwarder" do owner new_resource.user group new_resource.group mode '0755' @@ -19,11 +31,29 @@ class LogstashForwarder < Chef::Provider::LWRPBase checksum '5f49c5be671fff981b5ad1f8c5557a7e9973b24e8c73dbf0648326d400e6a4a1' end + template "#{home_dir}/logstash-forwarder.conf" do + source 'logstash-forwarder/logstash-forwarder.conf.erb' + owner 'logstash' + group 'logstash' + mode '0644' + cookbook new_resource.source + variables options: { + 'crt_location' => new_resource.crt_location, + 'key_location' => new_resource.key_location + } + end + runit_service service_name do default_logger true owner new_resource.user - group new_resource.user + group new_resource.group cookbook new_resource.source + options new_resource.runit_options.merge( + 'home_dir' => home_dir, + 'user' => new_resource.user, + 'group' => new_resource.group, + 'config_file' => 'logstash-forwarder.conf' + ) action [:create, :enable] end end diff --git a/libraries/provider_logstash_forwarder_config.rb b/libraries/provider_logstash_forwarder_config.rb deleted file mode 100644 index 3ba74b7..0000000 --- a/libraries/provider_logstash_forwarder_config.rb +++ /dev/null @@ -1,38 +0,0 @@ -class Chef - class Provider - class LogstashForwarderConfig < Chef::Provider::LWRPBase - use_inline_resources if defined?(use_inline_resources) - - provides :logstash_forwarder_config - - action :create do - directory '/etc/logstash-forwarder' do - mode '0755' - action :create - recursive true - end - - directory '/etc/logstash-forwarder/config.d' do - mode '0755' - action :create - recursive true - end - - template '/etc/logstash-forwarder/logstash-forwarder.conf' do - source 'logstash-forwarder/logstash-forwarder.conf.erb' - owner 'logstash' - group 'logstash' - mode '0644' - cookbook new_resource.source - variables options: { - 'crt_location' => new_resource.crt_location, - 'key_location' => new_resource.key_location - } - end - end - - action :delete do - end - end - end -end diff --git a/libraries/resource_logstash_forwarder.rb b/libraries/resource_logstash_forwarder.rb index c2cc49c..fce1fe5 100644 --- a/libraries/resource_logstash_forwarder.rb +++ b/libraries/resource_logstash_forwarder.rb @@ -9,28 +9,24 @@ class LogstashForwarder < Chef::Resource::LWRPBase # used to target any files/templates; default to self attribute :source, kind_of: String, default: 'elk' - attribute :group, kind_of: String, default: 'logstash' attribute :user, kind_of: String, default: 'logstash' attribute :version, kind_of: String, default: '0.4.0' - end - - class LogstashForwarderConfig < Chef::Resource::LWRPBase - resource_name :logstash_forwarder_config - default_action :create - actions [:create, :delete] - attribute :chdir, kind_of: String, default: '/var/lib/logstash-forwarder' - attribute :chroot, kind_of: String, default: '/' + # CONFIGURATION; HASH IT UP attribute :crt, kind_of: String, default: '' attribute :crt_location, kind_of: String, default: '/etc/logstash-forwarder/logstash.crt' - attribute :group, kind_of: String, default: 'root' attribute :key, kind_of: String, default: '' attribute :key_location, kind_of: String, default: '/etc/logstash-forwarder/logstash.key' + attribute :chdir, kind_of: String, default: '/var/lib/logstash-forwarder' + attribute :chroot, kind_of: String, default: '/' attribute :nice, kind_of: String, default: '' attribute :port, kind_of: Integer, default: 5043 - attribute :source, kind_of: String, default: 'elk' - attribute :user, kind_of: String, default: 'root' + + # RUNIT + attribute :runit_args, kind_of: Hash, default: {} + attribute :runit_options, kind_of: Hash, default: {} + attribute :runit_env, kind_of: Hash, default: {} end end end diff --git a/templates/default/sv-logstash-forwarder-run.erb b/templates/default/sv-logstash-forwarder-run.erb new file mode 100644 index 0000000..9d8e6ef --- /dev/null +++ b/templates/default/sv-logstash-forwarder-run.erb @@ -0,0 +1,7 @@ +#!/bin/sh + +cd <%= @options['home_dir'] %> +exec 2>&1 + +chpst -u :<%= @options['user'] %>:<%= @options['group'] %> +exec ./logstash-forwarder -config <%= @options['config_file'] %> diff --git a/templates/default/sv-logstash_forwarder-run.erb b/templates/default/sv-logstash_forwarder-run.erb deleted file mode 100644 index f680fae..0000000 --- a/templates/default/sv-logstash_forwarder-run.erb +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -cd /home/logstash -exec 2>&1 - -exec /usr/bin/env logstash-forwarder -c /etc/logstash-forwarder/logstash-forwarder.yml diff --git a/test/cookbooks/elktest/recipes/default.rb b/test/cookbooks/elktest/recipes/default.rb index 4766019..02d56d9 100644 --- a/test/cookbooks/elktest/recipes/default.rb +++ b/test/cookbooks/elktest/recipes/default.rb @@ -8,5 +8,5 @@ include_recipe 'runit::default' include_recipe 'elktest::elasticsearch' # include_recipe 'elktest::logstash' -# include_recipe 'elktest::logstash_forwarder' +include_recipe 'elktest::logstash_forwarder' include_recipe 'elktest::kibana' diff --git a/test/cookbooks/elktest/recipes/logstash.rb b/test/cookbooks/elktest/recipes/logstash.rb index f719738..f0ff888 100644 --- a/test/cookbooks/elktest/recipes/logstash.rb +++ b/test/cookbooks/elktest/recipes/logstash.rb @@ -2,16 +2,10 @@ logstash_key = Base64.decode64(secrets['key']) logstash_crt = Base64.decode64(secrets['certificate']) -directory '/etc/logstash-forwarder' do - mode '0755' - action :create - recursive true -end - -file '/etc/logstash/logstash.key' do +file '/tmp/logstash.key' do content logstash_key end -file '/etc/logstash/logstash.crt' do +file '/tmp/logstash.crt' do content logstash_crt end diff --git a/test/cookbooks/elktest/recipes/logstash_forwarder.rb b/test/cookbooks/elktest/recipes/logstash_forwarder.rb index daa7ac9..620846e 100644 --- a/test/cookbooks/elktest/recipes/logstash_forwarder.rb +++ b/test/cookbooks/elktest/recipes/logstash_forwarder.rb @@ -2,11 +2,14 @@ logstash_key = Base64.decode64(secrets['key']) logstash_crt = Base64.decode64(secrets['certificate']) -file '/etc/logstash-forwarder/logstash.key' do +file '/tmp/logstash.key' do content logstash_key end -file '/etc/logstash-forwarder/logstash.crt' do +file '/tmp/logstash.crt' do content logstash_crt end -logstash_forwarder 'default' +logstash_forwarder 'default' do + crt_location '/tmp/logstash.crt' + key_location '/tmp/logstash.key' +end From a0dbc6cf56876e6268c2778540b16eb080827f91 Mon Sep 17 00:00:00 2001 From: Jacob Dearing Date: Mon, 27 Jul 2015 16:42:23 -0500 Subject: [PATCH 07/10] simplify testing cookbook --- test/cookbooks/elktest/recipes/default.rb | 31 +++++++++++++++---- .../elktest/recipes/elasticsearch.rb | 1 - test/cookbooks/elktest/recipes/kibana.rb | 1 - test/cookbooks/elktest/recipes/logstash.rb | 12 ------- .../elktest/recipes/logstash_forwarder.rb | 15 --------- 5 files changed, 25 insertions(+), 35 deletions(-) delete mode 100644 test/cookbooks/elktest/recipes/elasticsearch.rb delete mode 100644 test/cookbooks/elktest/recipes/kibana.rb delete mode 100644 test/cookbooks/elktest/recipes/logstash.rb delete mode 100644 test/cookbooks/elktest/recipes/logstash_forwarder.rb diff --git a/test/cookbooks/elktest/recipes/default.rb b/test/cookbooks/elktest/recipes/default.rb index 02d56d9..a5540cc 100644 --- a/test/cookbooks/elktest/recipes/default.rb +++ b/test/cookbooks/elktest/recipes/default.rb @@ -1,12 +1,31 @@ - # test a single node with all four projects - %w( tar nano htop java-1.8.0-openjdk-headless).each do |pkg| package pkg end include_recipe 'runit::default' -include_recipe 'elktest::elasticsearch' -# include_recipe 'elktest::logstash' -include_recipe 'elktest::logstash_forwarder' -include_recipe 'elktest::kibana' + +# create certs (subject = localhost) +secrets = Chef::DataBagItem.load('secrets', 'logstash') +logstash_key = Base64.decode64(secrets['key']) +file '/tmp/logstash.key' do + content logstash_key +end +logstash_crt = Base64.decode64(secrets['certificate']) +file '/tmp/logstash.crt' do + content logstash_crt +end + +elasticsearch 'default' + +logstash 'default' do + crt_location '/tmp/logstash.crt' + key_location '/tmp/logstash.key' +end + +logstash_forwarder 'default' do + crt_location '/tmp/logstash.crt' + key_location '/tmp/logstash.key' +end + +kibana 'default' diff --git a/test/cookbooks/elktest/recipes/elasticsearch.rb b/test/cookbooks/elktest/recipes/elasticsearch.rb deleted file mode 100644 index 5ca6074..0000000 --- a/test/cookbooks/elktest/recipes/elasticsearch.rb +++ /dev/null @@ -1 +0,0 @@ -elasticsearch 'default' diff --git a/test/cookbooks/elktest/recipes/kibana.rb b/test/cookbooks/elktest/recipes/kibana.rb deleted file mode 100644 index 78dcc8a..0000000 --- a/test/cookbooks/elktest/recipes/kibana.rb +++ /dev/null @@ -1 +0,0 @@ -kibana 'default' diff --git a/test/cookbooks/elktest/recipes/logstash.rb b/test/cookbooks/elktest/recipes/logstash.rb deleted file mode 100644 index f0ff888..0000000 --- a/test/cookbooks/elktest/recipes/logstash.rb +++ /dev/null @@ -1,12 +0,0 @@ -secrets = Chef::DataBagItem.load('secrets', 'logstash') -logstash_key = Base64.decode64(secrets['key']) -logstash_crt = Base64.decode64(secrets['certificate']) - -file '/tmp/logstash.key' do - content logstash_key -end -file '/tmp/logstash.crt' do - content logstash_crt -end - -logstash 'default' diff --git a/test/cookbooks/elktest/recipes/logstash_forwarder.rb b/test/cookbooks/elktest/recipes/logstash_forwarder.rb deleted file mode 100644 index 620846e..0000000 --- a/test/cookbooks/elktest/recipes/logstash_forwarder.rb +++ /dev/null @@ -1,15 +0,0 @@ -secrets = Chef::DataBagItem.load('secrets', 'logstash') -logstash_key = Base64.decode64(secrets['key']) -logstash_crt = Base64.decode64(secrets['certificate']) - -file '/tmp/logstash.key' do - content logstash_key -end -file '/tmp/logstash.crt' do - content logstash_crt -end - -logstash_forwarder 'default' do - crt_location '/tmp/logstash.crt' - key_location '/tmp/logstash.key' -end From ccf120d91010c3aa0962333e20153ae8a0e5b292 Mon Sep 17 00:00:00 2001 From: Jacob Dearing Date: Mon, 27 Jul 2015 17:06:11 -0500 Subject: [PATCH 08/10] rework logstash --- libraries/provider_logstash.rb | 39 ++++++++- libraries/provider_logstash_config.rb | 79 ------------------- libraries/resource_logstash.rb | 12 ++- .../default/logstash/conf.d/00-input.conf.erb | 8 -- .../logstash/conf.d/99-output.conf.erb | 4 - .../10-syslog.conf.erb => logstash.conf.erb} | 16 +++- templates/default/sv-logstash-run.erb | 5 +- 7 files changed, 61 insertions(+), 102 deletions(-) delete mode 100644 libraries/provider_logstash_config.rb delete mode 100755 templates/default/logstash/conf.d/00-input.conf.erb delete mode 100755 templates/default/logstash/conf.d/99-output.conf.erb rename templates/default/logstash/{conf.d/10-syslog.conf.erb => logstash.conf.erb} (59%) mode change 100755 => 100644 diff --git a/libraries/provider_logstash.rb b/libraries/provider_logstash.rb index 9c8a1a5..4d35e7d 100644 --- a/libraries/provider_logstash.rb +++ b/libraries/provider_logstash.rb @@ -6,11 +6,19 @@ class Logstash < Chef::Provider::LWRPBase provides :logstash service_name = 'logstash' - action :install do + home_dir = "/opt/logstash/logstash-#{new_resource.version}" + user new_resource.user group new_resource.group + directory "#{home_dir}/config" do + owner new_resource.user + group new_resource.group + mode '0755' + action :create + end + ark service_name do checksum new_resource.checksum group new_resource.group @@ -21,11 +29,40 @@ class Logstash < Chef::Provider::LWRPBase version new_resource.version end + template "#{home_dir}/config/logging.yml" do + source 'logstash/logging.yml.erb' + owner 'root' + group 'root' + mode '0644' + cookbook new_resource.source + end + + template "#{home_dir}/config/logstash.conf" do + source 'logstash/logstash.conf.erb' + owner 'root' + group 'root' + mode '0644' + cookbook new_resource.source + variables options: { + 'port' => new_resource.port, + 'key' => new_resource.key, + 'crt' => new_resource.crt, + 'key_location' => new_resource.key_location, + 'crt_location' => new_resource.crt_location + } + end + runit_service service_name do default_logger true owner new_resource.user group new_resource.user cookbook new_resource.source + options new_resource.runit_options.merge( + 'home_dir' => home_dir, + 'user' => new_resource.user, + 'group' => new_resource.group, + 'config_file' => 'config/logstash.conf' + ) action [:create, :enable] end end diff --git a/libraries/provider_logstash_config.rb b/libraries/provider_logstash_config.rb deleted file mode 100644 index da280b0..0000000 --- a/libraries/provider_logstash_config.rb +++ /dev/null @@ -1,79 +0,0 @@ -class Chef - class Provider - class LogstashConfig < Chef::Provider::LWRPBase - use_inline_resources if defined?(use_inline_resources) - - provides :logstash_config - - action :create do - [new_resource.ls_conf_dir, - new_resource.ls_home, - '/var/log/logstash/', - '/etc/logstash' - ].each do |dir| - directory dir do - mode '0755' - action :create - recursive true - end - end - - template '/etc/logstash/config' do - source 'logstash/logstash.sysconfig.erb' - owner 'root' - group 'root' - mode '0644' - cookbook new_resource.source - variables options: { - 'javacmd' => new_resource.javacmd, - 'ls_home' => new_resource.ls_home, - 'ls_opts' => new_resource.ls_opts, - 'ls_heap_size' => new_resource.ls_heap_size, - 'ls_java_opts' => new_resource.ls_java_opts, - 'ls_pidfile' => new_resource.ls_pidfile, - 'ls_user' => new_resource.ls_user, - 'ls_group' => new_resource.ls_group, - 'ls_log_file' => new_resource.ls_log_file, - 'ls_use_gc_logging' => new_resource.ls_use_gc_logging, - 'ls_conf_dir' => new_resource.ls_conf_dir, - 'ls_open_files' => new_resource.ls_open_files, - 'ls_nice' => new_resource.ls_nice - } - end - - template "#{new_resource.ls_conf_dir}/00-input.conf" do - source 'logstash/conf.d/00-input.conf.erb' - owner 'root' - group 'root' - mode '0644' - cookbook new_resource.source - variables options: { - 'port' => new_resource.port, - 'key' => new_resource.key, - 'crt' => new_resource.crt, - 'key_location' => new_resource.key_location, - 'crt_location' => new_resource.crt_location - } - end - - template "#{new_resource.ls_conf_dir}/99-input.conf" do - source 'logstash/conf.d/99-output.conf.erb' - owner 'root' - group 'root' - mode '0644' - cookbook new_resource.source - end - - template "#{new_resource.ls_conf_dir}/10-syslog.conf" do - source 'logstash/conf.d/10-syslog.conf.erb' - owner 'root' - group 'root' - mode '0644' - cookbook new_resource.source - end - end - action :delete do - end - end - end -end diff --git a/libraries/resource_logstash.rb b/libraries/resource_logstash.rb index c26d4fe..43e556c 100644 --- a/libraries/resource_logstash.rb +++ b/libraries/resource_logstash.rb @@ -25,12 +25,6 @@ class Logstash < Chef::Resource::LWRPBase attribute :owner, kind_of: String, default: 'logstash' attribute :path, kind_of: String, default: '/opt/logstash' - end - - class LogstashConfig < Chef::Resource::LWRPBase - resource_name :logstash_config - default_action :create - actions [:create, :delete] attribute :crt, kind_of: String, default: '' attribute :crt_location, kind_of: String, default: '/etc/logstash/logstash.crt' @@ -50,7 +44,11 @@ class LogstashConfig < Chef::Resource::LWRPBase attribute :ls_use_gc_logging, kind_of: [TrueClass, FalseClass], default: true attribute :ls_user, kind_of: String, default: 'logstash' attribute :port, kind_of: Integer, default: 5043 - attribute :source, kind_of: String, default: 'elk' + + # RUNIT + attribute :runit_args, kind_of: Hash, default: {} + attribute :runit_options, kind_of: Hash, default: {} + attribute :runit_env, kind_of: Hash, default: {} end end end diff --git a/templates/default/logstash/conf.d/00-input.conf.erb b/templates/default/logstash/conf.d/00-input.conf.erb deleted file mode 100755 index d0d6962..0000000 --- a/templates/default/logstash/conf.d/00-input.conf.erb +++ /dev/null @@ -1,8 +0,0 @@ -input { - lumberjack { - port => "<%= @options['port'] %>" - type => "logs" - ssl_certificate => "<%= @options['crt_location'] %>" - ssl_key => "<%= @options['key_location'] %>" - } -} diff --git a/templates/default/logstash/conf.d/99-output.conf.erb b/templates/default/logstash/conf.d/99-output.conf.erb deleted file mode 100755 index 58c3ef4..0000000 --- a/templates/default/logstash/conf.d/99-output.conf.erb +++ /dev/null @@ -1,4 +0,0 @@ -output { - elasticsearch { host => localhost } - stdout { codec => rubydebug } -} diff --git a/templates/default/logstash/conf.d/10-syslog.conf.erb b/templates/default/logstash/logstash.conf.erb old mode 100755 new mode 100644 similarity index 59% rename from templates/default/logstash/conf.d/10-syslog.conf.erb rename to templates/default/logstash/logstash.conf.erb index 3344a78..ee381ce --- a/templates/default/logstash/conf.d/10-syslog.conf.erb +++ b/templates/default/logstash/logstash.conf.erb @@ -1,3 +1,12 @@ +input { + lumberjack { + port => "<%= @options['port'] %>" + type => "logs" + ssl_certificate => "<%= @options['crt_location'] %>" + ssl_key => "<%= @options['key_location'] %>" + } +} + filter { if [type] == "syslog" { grok { @@ -10,4 +19,9 @@ filter { match => [ "syslog_timestamp", "MMM d HH:mm:ss", "MMM dd HH:mm:ss" ] } } -} \ No newline at end of file +} + +output { + elasticsearch { host => localhost } + stdout { codec => rubydebug } +} diff --git a/templates/default/sv-logstash-run.erb b/templates/default/sv-logstash-run.erb index 4790176..fb42860 100644 --- a/templates/default/sv-logstash-run.erb +++ b/templates/default/sv-logstash-run.erb @@ -1,6 +1,7 @@ #!/bin/sh -cd /home/logstash +cd <%= @options['home_dir'] %> exec 2>&1 -exec /usr/bin/env logstash -c /etc/logstash/config +chpst -u :<%= @options['user'] %>:<%= @options['group'] %> +exec ./bin/logstash -f <%= @options['config_file'] %> From 9ad564ca5494ab3c4f6da903b52bdf8ae3526bb0 Mon Sep 17 00:00:00 2001 From: Jacob Dearing Date: Mon, 27 Jul 2015 17:35:46 -0500 Subject: [PATCH 09/10] correct elasticsearch bin location --- libraries/provider_elasticsearch.rb | 5 ++++- libraries/provider_kibana.rb | 2 +- libraries/provider_logstash.rb | 1 + templates/default/sv-elasticsearch-run.erb | 2 +- templates/default/sv-kibana-run.erb | 2 +- test/integration/helpers/serverspec/elasticsearch.rb | 10 ++++------ 6 files changed, 12 insertions(+), 10 deletions(-) mode change 100755 => 100644 test/integration/helpers/serverspec/elasticsearch.rb diff --git a/libraries/provider_elasticsearch.rb b/libraries/provider_elasticsearch.rb index fbc55f4..bf4d50b 100644 --- a/libraries/provider_elasticsearch.rb +++ b/libraries/provider_elasticsearch.rb @@ -10,6 +10,9 @@ class Elasticsearch < Chef::Provider::LWRPBase service_name = 'elasticsearch' action :install do + + home_dir = "#{new_resource.path}/elasticsearch-#{new_resource.version}" + user new_resource.user group new_resource.group @@ -30,7 +33,7 @@ class Elasticsearch < Chef::Provider::LWRPBase cookbook new_resource.source env new_resource.runit_env options new_resource.runit_options.merge( - 'install_path' => "#{new_resource.path}/#{new_resource.name}-#{new_resource.version}", + 'home_dir' => home_dir, 'user' => new_resource.user, 'group' => new_resource.group ) diff --git a/libraries/provider_kibana.rb b/libraries/provider_kibana.rb index 36a1be6..8b6c7b8 100644 --- a/libraries/provider_kibana.rb +++ b/libraries/provider_kibana.rb @@ -63,7 +63,7 @@ class Kibana < Chef::Provider::LWRPBase cookbook new_resource.source env new_resource.runit_env options new_resource.runit_options.merge( - 'install_path' => home_dir, + 'home_dir' => home_dir, 'user' => new_resource.user, 'group' => new_resource.group, 'config_file' => "#{home_dir}/config/kibana.yml" diff --git a/libraries/provider_logstash.rb b/libraries/provider_logstash.rb index 4d35e7d..8b14a77 100644 --- a/libraries/provider_logstash.rb +++ b/libraries/provider_logstash.rb @@ -16,6 +16,7 @@ class Logstash < Chef::Provider::LWRPBase owner new_resource.user group new_resource.group mode '0755' + recursive true action :create end diff --git a/templates/default/sv-elasticsearch-run.erb b/templates/default/sv-elasticsearch-run.erb index aa7042d..5c77a09 100644 --- a/templates/default/sv-elasticsearch-run.erb +++ b/templates/default/sv-elasticsearch-run.erb @@ -1,6 +1,6 @@ #!/bin/sh -cd <%= @options['install_path'] %> +cd <%= @options['home_dir'] %> exec 2>&1 chpst -u :<%= @options['user'] %>:<%= @options['group'] %> diff --git a/templates/default/sv-kibana-run.erb b/templates/default/sv-kibana-run.erb index 012447c..e95885a 100644 --- a/templates/default/sv-kibana-run.erb +++ b/templates/default/sv-kibana-run.erb @@ -1,6 +1,6 @@ #!/bin/sh -cd <%= @options['install_path'] %> +cd <%= @options['home_dir'] %> exec 2>&1 chpst -u :<%= @options['user'] %>:<%= @options['group'] %> diff --git a/test/integration/helpers/serverspec/elasticsearch.rb b/test/integration/helpers/serverspec/elasticsearch.rb old mode 100755 new mode 100644 index e6a2845..f14854b --- a/test/integration/helpers/serverspec/elasticsearch.rb +++ b/test/integration/helpers/serverspec/elasticsearch.rb @@ -1,12 +1,10 @@ # sshd_service = os[:family] == 'redhat' ? 'sshd' : 'ssh' shared_examples 'elasticsearch' do - describe service('elasticsearch') do - it 'is enabled and running' do - expect(subject).to be_enabled - expect(subject).to be_running - end - end + describe command('sv status elasticsearch') do + its(:stdout) { should match /run: elasticsearch/ } + end end # curl -X GET http://localhost:9200/ +# curl 'localhost:9200/_cat/health?v' From ba1b2294b0f055ec3a94411cba86f06aae0ed881 Mon Sep 17 00:00:00 2001 From: Jacob Dearing Date: Mon, 27 Jul 2015 17:39:55 -0500 Subject: [PATCH 10/10] update tests --- libraries/provider_elasticsearch.rb | 1 - test/integration/helpers/serverspec/elasticsearch.rb | 6 +++--- test/integration/helpers/serverspec/kibana.rb | 7 ++----- test/integration/helpers/serverspec/logstash.rb | 7 ++----- test/integration/helpers/serverspec/logstash_forwarder.rb | 7 ++----- 5 files changed, 9 insertions(+), 19 deletions(-) mode change 100755 => 100644 test/integration/helpers/serverspec/kibana.rb mode change 100755 => 100644 test/integration/helpers/serverspec/logstash.rb mode change 100755 => 100644 test/integration/helpers/serverspec/logstash_forwarder.rb diff --git a/libraries/provider_elasticsearch.rb b/libraries/provider_elasticsearch.rb index bf4d50b..b825776 100644 --- a/libraries/provider_elasticsearch.rb +++ b/libraries/provider_elasticsearch.rb @@ -10,7 +10,6 @@ class Elasticsearch < Chef::Provider::LWRPBase service_name = 'elasticsearch' action :install do - home_dir = "#{new_resource.path}/elasticsearch-#{new_resource.version}" user new_resource.user diff --git a/test/integration/helpers/serverspec/elasticsearch.rb b/test/integration/helpers/serverspec/elasticsearch.rb index f14854b..6f8af97 100644 --- a/test/integration/helpers/serverspec/elasticsearch.rb +++ b/test/integration/helpers/serverspec/elasticsearch.rb @@ -1,9 +1,9 @@ # sshd_service = os[:family] == 'redhat' ? 'sshd' : 'ssh' shared_examples 'elasticsearch' do - describe command('sv status elasticsearch') do - its(:stdout) { should match /run: elasticsearch/ } - end + describe command('sv status elasticsearch') do + its(:stdout) { should match 'run: elasticsearch' } + end end # curl -X GET http://localhost:9200/ diff --git a/test/integration/helpers/serverspec/kibana.rb b/test/integration/helpers/serverspec/kibana.rb old mode 100755 new mode 100644 index 5e8d28a..27f0f55 --- a/test/integration/helpers/serverspec/kibana.rb +++ b/test/integration/helpers/serverspec/kibana.rb @@ -1,10 +1,7 @@ # sshd_service = os[:family] == 'redhat' ? 'sshd' : 'ssh' shared_examples 'kibana' do - describe service('kibana') do - it 'is enabled and running' do - expect(subject).to be_enabled - expect(subject).to be_running - end + describe command('sv status kibana') do + its(:stdout) { should match 'run: kibana' } end end diff --git a/test/integration/helpers/serverspec/logstash.rb b/test/integration/helpers/serverspec/logstash.rb old mode 100755 new mode 100644 index 25f2591..5a84fff --- a/test/integration/helpers/serverspec/logstash.rb +++ b/test/integration/helpers/serverspec/logstash.rb @@ -1,10 +1,7 @@ # sshd_service = os[:family] == 'redhat' ? 'sshd' : 'ssh' shared_examples 'logstash' do - describe service('logstash') do - it 'is enabled and running' do - expect(subject).to be_enabled - expect(subject).to be_running - end + describe command('sv status logstash') do + its(:stdout) { should match 'run: logstash' } end end diff --git a/test/integration/helpers/serverspec/logstash_forwarder.rb b/test/integration/helpers/serverspec/logstash_forwarder.rb old mode 100755 new mode 100644 index 40e6e93..849001c --- a/test/integration/helpers/serverspec/logstash_forwarder.rb +++ b/test/integration/helpers/serverspec/logstash_forwarder.rb @@ -1,10 +1,7 @@ # sshd_service = os[:family] == 'redhat' ? 'sshd' : 'ssh' shared_examples 'logstash_forwarder' do - describe service('logstash-forwarder') do - it 'is enabled and running' do - expect(subject).to be_enabled - expect(subject).to be_running - end + describe command('sv status logstash-forwarder') do + its(:stdout) { should match 'run: logstash-forwarder' } end end