From 91d80d77410118f149cc96aa3beb35f6b9602773 Mon Sep 17 00:00:00 2001 From: Jacob Dearing Date: Mon, 27 Jul 2015 11:38:10 -0500 Subject: [PATCH] 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