From 35d27845c32f82e453f6832112502a4bdb059c1b Mon Sep 17 00:00:00 2001 From: paulczar Date: Thu, 17 Jul 2014 08:34:18 -0500 Subject: [PATCH 1/2] version bump --- CHANGELOG.md | 3 + metadata.rb | 2 +- providers/install.rb | 238 +++++++++++++++++++++++++++++++++++++++++++ recipes/install.rb | 13 +++ 4 files changed, 255 insertions(+), 1 deletion(-) create mode 100644 providers/install.rb create mode 100644 recipes/install.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 686801e..9c564c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ This file is used to list changes made in each version of chef-logstash. +## 0.9.2: +* update to fix PAX header issue on community site + ## 0.9.1: * curator LWRP diff --git a/metadata.rb b/metadata.rb index 4b327f6..a6d6a7f 100644 --- a/metadata.rb +++ b/metadata.rb @@ -5,7 +5,7 @@ license 'Apache 2.0' description 'Installs/Configures logstash' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '0.9.1' +version '0.9.2' %w(ubuntu debian redhat centos scientific amazon fedora).each do |os| supports os diff --git a/providers/install.rb b/providers/install.rb new file mode 100644 index 0000000..18108ef --- /dev/null +++ b/providers/install.rb @@ -0,0 +1,238 @@ +# Encoding: utf-8 +# Cookbook Name:: logstash +# Provider:: instance +# Author:: John E. Vincent +# License:: Apache 2.0 +# +# Copyright 2014, John E. Vincent + +require 'chef/mixin/shell_out' +require 'chef/mixin/language' +include Chef::Mixin::ShellOut + +def load_current_resource + @name = new_resource.name || 'default' + if node['logstash']['instance'].key?(@name) + attributes = node['logstash']['instance'][@name] + defaults = node['logstash']['instance']['default'] + else + attributes = node['logstash']['instance']['default'] + end + @base_directory = new_resource.base_directory || attributes['basedir'] || defaults['basedir'] + @install_type = new_resource.install_type || attributes['install_type'] || defaults['install_type'] + @version = new_resource.version || attributes['version'] || defaults['version'] + @checksum = new_resource.checksum || attributes['checksum'] || defaults['checksum'] + @source_url = new_resource.source_url || attributes['source_url'] || defaults['source_url'] + @repo = new_resource.repo + @sha = new_resource.sha + @java_home = new_resource.java_home + @user = new_resource.user || attributes['user'] || defaults['user'] + @group = new_resource.group || attributes['group'] || defaults['group'] + @useropts = new_resource.user_opts || attributes['user_opts'] || defaults['user_opts'] + @install_dir = "#{@base_directory}/application/logstash-#{@version}".clone +end + +action :delete do + ls = ls_vars + + idr = directory ls[:install_dir] do + recursive true + action :delete + end + new_resource.updated_by_last_action(idr.updated_by_last_action?) +end + +action :create do + ls = ls_vars + + ur = user ls[:user] do + home ls[:homedir] + system true + action :create + manage_home true + uid ls[:uid] + end + new_resource.updated_by_last_action(ur.updated_by_last_action?) + + gr = group ls[:group] do + gid ls[:gid] + members ls[:user] + append true + system true + end + new_resource.updated_by_last_action(gr.updated_by_last_action?) + + case @install_type + when 'tarball' + @run_context.include_recipe 'ark::default' + arkit = ark ls[:name] do + url ls[:source_url] + checksum ls[:checksum] + owner ls[:user] + group ls[:group] + mode 0755 + version ls[:version] + path ls[:basedir] + action :put + end + new_resource.updated_by_last_action(arkit.updated_by_last_action?) + + %w(bin etc lib log tmp etc/conf.d patterns).each do |ldir| + r = directory "#{ls[:instance_dir]}/#{ldir}" do + action :create + mode '0755' + owner ls[:user] + group ls[:group] + end + new_resource.updated_by_last_action(r.updated_by_last_action?) + end + + when 'jar' + bdr = directory @base_directory do + action :create + mode '0755' + owner ls[:user] + group ls[:group] + end + new_resource.updated_by_last_action(bdr.updated_by_last_action?) + + idr = directory ls[:instance_dir] do + action :create + mode '0755' + owner ls[:user] + group ls[:group] + end + new_resource.updated_by_last_action(idr.updated_by_last_action?) + + %w(bin etc lib log tmp etc/conf.d patterns).each do |ldir| + r = directory "#{ls[:instance_dir]}/#{ldir}" do + action :create + mode '0755' + owner ls[:user] + group ls[:group] + end + new_resource.updated_by_last_action(r.updated_by_last_action?) + end + + rfr = remote_file "#{ls[:instance_dir]}/lib/logstash-#{ls[:version]}.jar" do + owner ls[:user] + group ls[:group] + mode '0755' + source ls[:source_url] + checksum ls[:checksum] + end + new_resource.updated_by_last_action(rfr.updated_by_last_action?) + + lr = link "#{ls[:instance_dir]}/lib/logstash.jar" do + to "#{ls[:instance_dir]}/lib/logstash-#{ls[:version]}.jar" + only_if { new_resource.auto_symlink } + end + new_resource.updated_by_last_action(lr.updated_by_last_action?) + + when 'source' + bdr = directory @base_directory do + action :create + mode '0755' + owner ls[:user] + group ls[:group] + end + new_resource.updated_by_last_action(bdr.updated_by_last_action?) + + idr = directory ls[:instance_dir] do + action :create + mode '0755' + owner ls[:user] + group ls[:group] + end + new_resource.updated_by_last_action(idr.updated_by_last_action?) + + %w(bin etc lib log tmp etc/conf.d patterns).each do |ldir| + r = directory "#{ls[:instance_dir]}/#{ldir}" do + action :create + mode '0755' + owner ls[:user] + group ls[:group] + end + new_resource.updated_by_last_action(r.updated_by_last_action?) + end + + sd = directory "#{ls[:instance_dir]}/source" do + action :create + owner ls[:user] + group ls[:group] + mode '0755' + end + new_resource.updated_by_last_action(sd.updated_by_last_action?) + + gr = git "#{ls[:instance_dir]}/source" do + repository @repo + reference @sha + action :sync + user ls[:user] + group ls[:group] + end + new_resource.updated_by_last_action(gr.updated_by_last_action?) + + source_version = @sha || "v#{@version}" + er = execute 'build-logstash' do + cwd "#{ls[:instance_dir]}/source" + environment(JAVA_HOME: @java_home) + user ls_user # Changed from root cause building as root...WHA? + command "make clean && make VERSION=#{source_version} jar" + action :run + creates "#{ls[:instance_dir]}/source/build/logstash-#{source_version}--monolithic.jar" + not_if "test -f #{ls[:instance_dir]}/source/build/logstash-#{source_version}--monolithic.jar" + end + new_resource.updated_by_last_action(er.updated_by_last_action?) + lr = link "#{ls[:instance_dir]}/lib/logstash.jar" do + to "#{ls[:instance_dir]}/source/build/logstash-#{source_version}--monolithic.jar" + only_if { new_resource.auto_symlink } + end + new_resource.updated_by_last_action(lr.updated_by_last_action?) + else + Chef::Application.fatal!("Unknown install type: #{@install_type}") + end + logrotate(ls) if ls[:logrotate_enable] + +end + +private + +def logrotate(ls) + name = ls[:name] + + @run_context.include_recipe 'logrotate::default' + + logrotate_app "logstash_#{name}" do + path "#{ls[:homedir]}/log/*.log" + size ls[:logrotate_size] if ls[:logrotate_use_filesize] + frequency ls[:logrotate_frequency] + rotate ls[:logrotate_max_backup] + options ls[:logrotate_options] + create "664 #{ls[:user]} #{ls[:group]}" + end +end + +def ls_vars + ls = { + homedir: @useropts[:homedir], + uid: @useropts[:uid], + gid: @useropts[:gid], + source_url: @source_url, + version: @version, + checksum: @checksum, + basedir: @base_directory, + user: @user, + group: @group, + name: @name, + instance_dir: @instance_dir, + enable_logrotate: @enable_logrotate, + logrotate_size: @logrotate_size, + logrotate_use_filesize: @logrotate_use_filesize, + logrotate_frequency: @logrotate_frequency, + logrotate_max_backup: @logrotate_max_backup, + logrotate_options: @logrotate_options, + logrotate_enable: @logrotate_enable + } + ls +end diff --git a/recipes/install.rb b/recipes/install.rb new file mode 100644 index 0000000..ce6d750 --- /dev/null +++ b/recipes/install.rb @@ -0,0 +1,13 @@ +# Encoding: utf-8 +# +# Author:: John E. Vincent +# Author:: Bryan W. Berry () +# Copyright 2012, John E. Vincent +# Copyright 2012, Bryan W. Berry +# License: Apache 2.0 +# Cookbook Name:: logstash +# Recipe:: install +# +# + +# install logstash binaries From 1c83271b7bf069c971050fdd1d166dae809fe115 Mon Sep 17 00:00:00 2001 From: paulczar Date: Sun, 31 Aug 2014 13:45:30 -0500 Subject: [PATCH 2/2] fixes for service_restart for issue https://github.com/lusis/chef-logstash/issues/330 --- .gitignore | 3 +- Gemfile.lock | 248 ------------------ providers/config.rb | 3 +- providers/service.rb | 78 +++--- recipes/agent.rb | 1 + recipes/server.rb | 5 +- .../server/serverspec/server_spec.rb | 2 +- test/unit/spec/agent_spec.rb | 1 - test/unit/spec/server_spec.rb | 1 - 9 files changed, 49 insertions(+), 293 deletions(-) delete mode 100644 Gemfile.lock diff --git a/.gitignore b/.gitignore index aa73350..a5d5527 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ vendor/ .kitchen/ .kitchen.local.yml .bundle/ -bin/ \ No newline at end of file +bin/ +Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index f6c303a..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,248 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - addressable (2.3.6) - ast (2.0.0) - berkshelf (3.1.3) - addressable (~> 2.3.4) - berkshelf-api-client (~> 1.2) - buff-config (~> 1.0) - buff-extensions (~> 1.0) - buff-shell_out (~> 0.1) - celluloid (~> 0.16.0.pre) - celluloid-io (~> 0.16.0.pre) - faraday (~> 0.9.0) - minitar (~> 0.5.4) - octokit (~> 3.0) - retryable (~> 1.3.3) - ridley (~> 4.0) - solve (~> 1.1) - thor (~> 0.18) - berkshelf-api-client (1.2.0) - faraday (~> 0.9.0) - buff-config (1.0.0) - buff-extensions (~> 1.0) - varia_model (~> 0.4) - buff-extensions (1.0.0) - buff-ignore (1.1.1) - buff-ruby_engine (0.1.0) - buff-shell_out (0.1.1) - buff-ruby_engine (~> 0.1.0) - celluloid (0.16.0.pre2) - timers (~> 3.0.0) - celluloid-io (0.16.0.pre2) - celluloid (>= 0.16.0.pre) - nio4r (>= 1.0.0) - chef (11.12.8) - chef-zero (>= 2.0.2, < 2.1) - diff-lcs (~> 1.2, >= 1.2.4) - erubis (~> 2.7) - highline (~> 1.6, >= 1.6.9) - json (>= 1.4.4, <= 1.8.1) - mime-types (~> 1.16) - mixlib-authentication (~> 1.3) - mixlib-cli (~> 1.4) - mixlib-config (~> 2.0) - mixlib-log (~> 1.3) - mixlib-shellout (~> 1.4) - net-ssh (~> 2.6) - net-ssh-multi (~> 1.1) - ohai (~> 7.0.4) - pry (~> 0.9) - rest-client (>= 1.0.4, < 1.7.0) - yajl-ruby (~> 1.1) - chef-zero (2.0.2) - hashie (~> 2.0) - json - mixlib-log (~> 1.3) - rack - chefspec (3.4.0) - chef (~> 11.0) - fauxhai (~> 2.0) - rspec (~> 2.14) - coderay (1.1.0) - dep-selector-libgecode (1.0.2) - dep_selector (1.0.3) - dep-selector-libgecode (~> 1.0) - ffi (~> 1.9) - diff-lcs (1.2.5) - erubis (2.7.0) - faraday (0.9.0) - multipart-post (>= 1.2, < 3) - fauxhai (2.1.2) - net-ssh - ohai - ffi (1.9.3) - foodcritic (3.0.3) - erubis - gherkin (~> 2.11.7) - nokogiri (~> 1.5.4) - rake - treetop (~> 1.4.10) - yajl-ruby (~> 1.1.0) - formatador (0.2.5) - gherkin (2.11.8) - multi_json (~> 1.3) - guard (2.6.1) - formatador (>= 0.2.4) - listen (~> 2.7) - lumberjack (~> 1.0) - pry (>= 0.9.12) - thor (>= 0.18.1) - guard-foodcritic (1.0.2) - foodcritic (>= 1.3, < 4.0) - guard (>= 1.0, < 3.0) - guard-rubocop (1.1.0) - guard (~> 2.0) - rubocop (~> 0.20) - hashie (2.1.2) - highline (1.6.21) - hitimes (1.2.1) - ipaddress (0.8.0) - json (1.8.1) - kitchen-vagrant (0.15.0) - test-kitchen (~> 1.0) - listen (2.7.9) - celluloid (>= 0.15.2) - rb-fsevent (>= 0.9.3) - rb-inotify (>= 0.9) - lumberjack (1.0.9) - method_source (0.8.2) - mime-types (1.25.1) - minitar (0.5.4) - mixlib-authentication (1.3.0) - mixlib-log - mixlib-cli (1.5.0) - mixlib-config (2.1.0) - mixlib-log (1.6.0) - mixlib-shellout (1.4.0) - multi_json (1.10.1) - multipart-post (2.0.0) - net-http-persistent (2.9.4) - net-scp (1.2.1) - net-ssh (>= 2.6.5) - net-ssh (2.9.1) - net-ssh-gateway (1.2.0) - net-ssh (>= 2.6.5) - net-ssh-multi (1.2.0) - net-ssh (>= 2.6.5) - net-ssh-gateway (>= 1.2.0) - nio4r (1.0.0) - nokogiri (1.5.11) - octokit (3.2.0) - sawyer (~> 0.5.3) - ohai (7.0.4) - ipaddress - mime-types (~> 1.16) - mixlib-cli - mixlib-config (~> 2.0) - mixlib-log - mixlib-shellout (~> 1.2) - systemu (~> 2.5.2) - yajl-ruby - parser (2.1.9) - ast (>= 1.1, < 3.0) - slop (~> 3.4, >= 3.4.5) - polyglot (0.3.5) - powerpack (0.0.9) - pry (0.10.0) - coderay (~> 1.1.0) - method_source (~> 0.8.1) - slop (~> 3.4) - rack (1.5.2) - rainbow (2.0.0) - rake (10.3.2) - rb-fsevent (0.9.4) - rb-inotify (0.9.5) - ffi (>= 0.5.0) - rdoc (4.1.1) - json (~> 1.4) - rest-client (1.6.8) - mime-types (~> 1.16) - rdoc (>= 2.4.2) - retryable (1.3.5) - ridley (4.0.0) - addressable - buff-config (~> 1.0) - buff-extensions (~> 1.0) - buff-ignore (~> 1.1) - buff-shell_out (~> 0.1) - celluloid (~> 0.16.0.pre) - celluloid-io (~> 0.16.0.pre) - erubis - faraday (~> 0.9.0) - hashie (>= 2.0.2, < 3.0.0) - json (>= 1.7.7) - mixlib-authentication (>= 1.3.0) - net-http-persistent (>= 2.8) - retryable - semverse (~> 1.1) - varia_model (~> 0.4) - rspec (2.99.0) - rspec-core (~> 2.99.0) - rspec-expectations (~> 2.99.0) - rspec-mocks (~> 2.99.0) - rspec-core (2.99.1) - rspec-expectations (2.99.1) - diff-lcs (>= 1.1.3, < 2.0) - rspec-its (1.0.1) - rspec-core (>= 2.99.0.beta1) - rspec-expectations (>= 2.99.0.beta1) - rspec-mocks (2.99.1) - rubocop (0.23.0) - json (>= 1.7.7, < 2) - parser (~> 2.1.9) - powerpack (~> 0.0.6) - rainbow (>= 1.99.1, < 3.0) - ruby-progressbar (~> 1.4) - ruby-progressbar (1.5.1) - safe_yaml (1.0.3) - sawyer (0.5.4) - addressable (~> 2.3.5) - faraday (~> 0.8, < 0.10) - semverse (1.1.0) - serverspec (1.9.1) - highline - net-ssh - rspec (~> 2.13) - rspec-its - specinfra (~> 1.18) - slop (3.5.0) - solve (1.2.0) - dep_selector (~> 1.0) - semverse (~> 1.1) - specinfra (1.19.0) - systemu (2.5.2) - test-kitchen (1.2.1) - mixlib-shellout (~> 1.2) - net-scp (~> 1.1) - net-ssh (~> 2.7) - safe_yaml (~> 1.0) - thor (~> 0.18) - thor (0.19.1) - timers (3.0.1) - hitimes - treetop (1.4.15) - polyglot - polyglot (>= 0.3.1) - varia_model (0.4.0) - buff-extensions (~> 1.0) - hashie (>= 2.0.2, < 3.0.0) - yajl-ruby (1.1.0) - -PLATFORMS - ruby - -DEPENDENCIES - berkshelf (> 3) - chef (>= 11.8) - chefspec (>= 3.4) - foodcritic (< 4.0) - guard (>= 2.6) - guard-foodcritic (>= 1.0.2) - guard-rubocop (>= 1.1) - kitchen-vagrant - rake (>= 10.2) - rubocop (= 0.23) - serverspec (>= 1.6) - test-kitchen diff --git a/providers/config.rb b/providers/config.rb index 9f81d31..6cf7ffb 100644 --- a/providers/config.rb +++ b/providers/config.rb @@ -29,6 +29,8 @@ def load_current_resource @service_name = new_resource.service_name || @instance end +use_inline_resources + action :create do conf = conf_vars # Chef::Log.info("config vars: #{conf.inspect}") @@ -40,7 +42,6 @@ def load_current_resource group conf[:group] mode conf[:mode] variables conf[:variables] - notifies :restart, "logstash_service[#{conf[:service_name]}]" action :create end new_resource.updated_by_last_action(tp.updated_by_last_action?) diff --git a/providers/service.rb b/providers/service.rb index d133583..08c087b 100644 --- a/providers/service.rb +++ b/providers/service.rb @@ -41,52 +41,22 @@ def load_current_resource @supervisor_gid = attributes['supervisor_gid'] || defaults['supervisor_gid'] end +use_inline_resources + action :restart do - svc = svc_vars - case svc[:method] - when 'native' - sv = service svc[:service_name] do - # provider Chef::Provider::Service::Upstart - action [:restart] - end - new_resource.updated_by_last_action(sv.updated_by_last_action?) - end + service_action(:restart) end action :start do - svc = svc_vars - case svc[:method] - when 'native' - sv = service svc[:service_name] do - # provider Chef::Provider::Service::Upstart - action [:start] - end - new_resource.updated_by_last_action(sv.updated_by_last_action?) - end + service_action(:start) end action :stop do - svc = svc_vars - case svc[:method] - when 'native' - sv = service svc[:service_name] do - # provider Chef::Provider::Service::Upstart - action [:stop] - end - new_resource.updated_by_last_action(sv.updated_by_last_action?) - end + service_action(:stop) end action :reload do - svc = svc_vars - case svc[:method] - when 'native' - sv = service svc[:service_name] do - # provider Chef::Provider::Service::Upstart - action [:reload] - end - new_resource.updated_by_last_action(sv.updated_by_last_action?) - end + service_action(:reload) end action :enable do @@ -243,6 +213,42 @@ def default_args args end +def service_action(action) + svc = svc_vars + case svc[:method] + when 'native' + sv = service svc[:service_name] + case pick_provider + when 'systemd' + sv.provider(Chef::Provider::Service::Systemd) + when 'upstart' + sv.provider(Chef::Provider::Service::Upstart) + else + sv.provider(Chef::Provider::Service::Init) + end + sv.run_action(action) + new_resource.updated_by_last_action(sv.updated_by_last_action?) + end +end + +def pick_provider + if platform_family? 'fedora' + if node['platform_version'] >= '15' + return 'systemd' + else + return 'default' + end + elsif platform_family? 'debian' + if node['platform_version'] >= '12.04' + return 'upstart' + else + return 'default' + end + else + return 'default' + end +end + def svc_vars svc = { name: @instance, diff --git a/recipes/agent.rb b/recipes/agent.rb index 0157648..dfa8e4d 100644 --- a/recipes/agent.rb +++ b/recipes/agent.rb @@ -24,6 +24,7 @@ input_file_name: '/var/log/syslog', input_file_type: 'syslog' ) + notifies :restart, "logstash_service[#{name}]" action [:create] end diff --git a/recipes/server.rb b/recipes/server.rb index cc59e94..53d29ec 100644 --- a/recipes/server.rb +++ b/recipes/server.rb @@ -42,6 +42,7 @@ variables( elasticsearch_embedded: true ) + notifies :restart, "logstash_service[#{name}]" end # ^ see `.kitchen.yml` for example attributes to configure templates. @@ -54,10 +55,6 @@ action [:create] end -logstash_service name do - action [:start] -end - logstash_curator 'server' do action [:create] end diff --git a/test/integration/server/serverspec/server_spec.rb b/test/integration/server/serverspec/server_spec.rb index 4168d4c..dd7610e 100644 --- a/test/integration/server/serverspec/server_spec.rb +++ b/test/integration/server/serverspec/server_spec.rb @@ -39,5 +39,5 @@ # Logstash Curator describe cron do - it { should have_entry('0 * * * * curator --host 127.0.0.1 -d 31 &> /dev/null').with_user('logstash') } + it { should have_entry('0 * * * * curator --host 127.0.0.1 delete --older-than 31 &> /dev/null').with_user('logstash') } end diff --git a/test/unit/spec/agent_spec.rb b/test/unit/spec/agent_spec.rb index 4648138..4ebd5a8 100644 --- a/test/unit/spec/agent_spec.rb +++ b/test/unit/spec/agent_spec.rb @@ -32,7 +32,6 @@ it 'calls the logstash_instance LWRP' do expect(chef_run).to enable_logstash_service('agent') - expect(chef_run).to start_logstash_service('agent') end end diff --git a/test/unit/spec/server_spec.rb b/test/unit/spec/server_spec.rb index 75ca8bf..491d7a2 100644 --- a/test/unit/spec/server_spec.rb +++ b/test/unit/spec/server_spec.rb @@ -32,7 +32,6 @@ it 'calls the logstash_service LWRP' do expect(chef_run).to enable_logstash_service('server') - expect(chef_run).to start_logstash_service('server') end it 'calls the logstash_plugins LWRP' do