diff --git a/.kitchen.yml b/.kitchen.yml index ab284cc..6955a7c 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -14,7 +14,7 @@ suites: - name: default run_list: - recipe[apt::default] - - recipe[kibana::install] + - recipe[kibana_lwrp::install] attributes: java: install_flavor: "oracle" diff --git a/.tailor b/.tailor deleted file mode 100644 index f54fac6..0000000 --- a/.tailor +++ /dev/null @@ -1,25 +0,0 @@ -Tailor.config do |config| - config.formatters "text" - config.file_set '**/*.rb' do |style| - style.max_line_length 80, level: :off - style.allow_camel_case_methods false, level: :error - style.allow_hard_tabs false, level: :error - style.allow_screaming_snake_case_classes false, level: :error - style.allow_trailing_line_spaces false, level: :error - style.allow_invalid_ruby false, level: :warn - style.indentation_spaces 2, level: :error - style.max_code_lines_in_class 300, level: :error - style.max_code_lines_in_method 30, level: :error - style.spaces_after_comma 1, level: :error - style.spaces_after_lbrace 1, level: :error - style.spaces_after_lbracket 0, level: :error - style.spaces_after_lparen 0, level: :error - style.spaces_before_comma 0, level: :error - style.spaces_before_lbrace 1, level: :error - style.spaces_before_rbrace 1, level: :error - style.spaces_before_rbracket 0, level: :error - style.spaces_before_rparen 0, level: :error - style.spaces_in_empty_braces 0, level: :error - style.trailing_newlines 1, level: :error - end -end \ No newline at end of file diff --git a/README.md b/README.md index c9ecbcf..442798f 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -kibana Cookbook +Kibana Library Cookbook =============== A library cookbook for installing kibana 4. If you wish to install Kibana3 try using the '1.3.x' releases of the cookbook. -This is a library cookbook, you can use you included `kibana::install` recipe to install kibana, but it is more likely to be really useful for you to call the LWRPs directly from your own cookbook. You can use the `kibana::install` recipe as a guide and customize to your needs. +This is a library cookbook, you can use you included `kibana_lwrp::install` recipe to install kibana, but it is more likely to be really useful for you to call the LWRPs directly from your own cookbook. You can use the `kibana_lwrp::install` recipe as a guide and customize to your needs. This cookbook is tested and works well with the `logstash` and the `elasticsearch` cookbooks found on the chef community site. @@ -17,11 +17,11 @@ See `attributes/*.rb` for attributes ( documented inline ) Usage ----- -#### kibana::default +#### kibana_lwrp::default The default recipe does nothing except for allow access to the LWRPs. -#### kibana::install +#### kibana_lwrp::install This is designed to be an example recipe to show you how you might write a wrapper cookbook. However it should be usable for a simple install of kibana. diff --git a/Strainerfile b/Strainerfile deleted file mode 100644 index ebe285a..0000000 --- a/Strainerfile +++ /dev/null @@ -1,5 +0,0 @@ -# Strainerfile -tailor: bundle exec tailor -knife test: bundle exec knife cookbook test $COOKBOOK -foodcritic: bundle exec foodcritic . -chefspec: bundle exec rspec . --color \ No newline at end of file diff --git a/Vagabondfile b/Vagabondfile deleted file mode 100644 index 1652709..0000000 --- a/Vagabondfile +++ /dev/null @@ -1,28 +0,0 @@ -{ - :nodes => { - :ubuntu1204 => { - :template => "ubuntu_1204", - :ipaddress => "33.33.33.87", - :run_list => [ - "recipe[apt::default]", - "recipe[kibana::default]" - ] - }, - :ubuntu1304 => { - :template => "ubuntu_1304", - :ipaddress => "33.33.33.87", - :run_list => [ - "recipe[apt::default]", - "recipe[kibana::default]" - ] - } - } - :local_chef_server => { - :zero => false, - :berkshelf => true, - :librarian => false, - :enabled => true, - :auto_upload => true - }, - :sudo => true -} \ No newline at end of file diff --git a/attributes/default.rb b/attributes/default.rb index 6309d39..65088ef 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -9,7 +9,7 @@ default['kibana']['git']['type'] = 'sync' # checkout | sync default['kibana']['git']['config'] = 'kibana/config.js' # relative path of config file default['kibana']['git']['config_template'] = 'config.js.erb' # template to use for config -default['kibana']['git']['config_template_cookbook'] = 'kibana' # cookbook containing config template +default['kibana']['git']['config_template_cookbook'] = 'kibana_lwrp' # cookbook containing config template # Values to use for file method of installation default['kibana']['file']['type'] = 'tgz' # zip | tgz @@ -18,7 +18,7 @@ default['kibana']['file']['checksum'] = nil # sha256 ( shasum -a 256 FILENAME ) default['kibana']['file']['config'] = 'config/kibana.yml' # relative path of config file default['kibana']['file']['config_template'] = 'kibana.yml.erb' # template to use for config -default['kibana']['file']['config_template_cookbook'] = 'kibana' # cookbook containing config template +default['kibana']['file']['config_template_cookbook'] = 'kibana_lwrp' # cookbook containing config template # Kibana Java Web Server default['kibana']['java_webserver_port'] = 5601 @@ -61,11 +61,11 @@ # nginx variables default['kibana']['nginx']['install_method'] = 'package' default['kibana']['nginx']['template'] = 'kibana-nginx.conf.erb' -default['kibana']['nginx']['template_cookbook'] = 'kibana' +default['kibana']['nginx']['template_cookbook'] = 'kibana_lwrp' default['kibana']['nginx']['enable_default_site'] = false default['kibana']['nginx']['install_method'] = 'package' # Apache variables. default['kibana']['apache']['template'] = 'kibana-apache.conf.erb' -default['kibana']['apache']['template_cookbook'] = 'kibana' +default['kibana']['apache']['template_cookbook'] = 'kibana_lwrp' default['kibana']['apache']['enable_default_site'] = false diff --git a/metadata.rb b/metadata.rb index 571a9e9..06117cb 100644 --- a/metadata.rb +++ b/metadata.rb @@ -1,13 +1,13 @@ -name 'kibana' +name 'kibana_lwrp' maintainer 'John E. Vincent' maintainer_email 'lusis.org+github.com@gmail.com' license 'Apache 2.0' description 'Installs/Configures kibana' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '1.4.1' +version '2.0.0' -%w(git nginx apache2 ark libarchive java runit logstash poise).each do |cb| +%w(git nginx apache2 ark libarchive java runit poise).each do |cb| depends cb end diff --git a/providers/service.rb b/providers/service.rb new file mode 100644 index 0000000..9fed8ac --- /dev/null +++ b/providers/service.rb @@ -0,0 +1,131 @@ +# Encoding: utf-8 +# Cookbook Name:: logstash +# Provider:: service +# 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.instance + @basedir = Logstash.get_attribute_or_default(node, @instance, 'basedir') + @templates_cookbook = new_resource.templates_cookbook || Logstash.get_attribute_or_default(node, @instance, 'service_templates_cookbook') + @service_name = new_resource.service_name || "logstash_#{@instance}" + @home = "#{@basedir}/#{@instance}" + @method = new_resource.method || Logstash.get_attribute_or_default(node, @instance, 'init_method') + @command = new_resource.command || "#{@home}/bin/logstash" + @user = new_resource.user || Logstash.get_attribute_or_default(node, @instance, 'user') + @group = new_resource.group || Logstash.get_attribute_or_default(node, @instance, 'group') + @log_file = Logstash.get_attribute_or_default(node, @instance, 'log_file') + @max_heap = Logstash.get_attribute_or_default(node, @instance, 'xmx') + @min_heap = Logstash.get_attribute_or_default(node, @instance, 'xms') + @gc_opts = Logstash.get_attribute_or_default(node, @instance, 'gc_opts') + @ipv4_only = Logstash.get_attribute_or_default(node, @instance, 'ipv4_only') + @java_opts = Logstash.get_attribute_or_default(node, @instance, 'java_opts') + @description = new_resource.description || @service_name + @chdir = @home + @workers = Logstash.get_attribute_or_default(node, @instance, 'workers') + @debug = Logstash.get_attribute_or_default(node, @instance, 'debug') + @install_type = Logstash.get_attribute_or_default(node, @instance, 'install_type') + @supervisor_gid = Logstash.get_attribute_or_default(node, @instance, 'supervisor_gid') + @runit_run_template_name = Logstash.get_attribute_or_default(node, @instance, 'runit_run_template_name') + @runit_log_template_name = Logstash.get_attribute_or_default(node, @instance, 'runit_log_template_name') + @nofile_soft = Logstash.get_attribute_or_default(node, @instance, 'limit_nofile_soft') + @nofile_hard = Logstash.get_attribute_or_default(node, @instance, 'limit_nofile_hard') +end + +action :restart do + new_resource.updated_by_last_action(service_action(:restart)) +end + +action :start do + new_resource.updated_by_last_action(service_action(:start)) +end + +action :stop do + new_resource.updated_by_last_action(service_action(:stop)) +end + +action :reload do + new_resource.updated_by_last_action(service_action(:reload)) +end + +action :enable do + svc = svc_vars + Chef::Log.info("Using init method #{svc[:method]} for #{svc[:service_name]}") + @run_context.include_recipe 'runit::default' + ri = runit_service svc[:service_name] do + options( + name: svc[:name], + home: svc[:home], + max_heap: svc[:max_heap], + min_heap: svc[:min_heap], + gc_opts: svc[:gc_opts], + java_opts: svc[:java_opts], + ipv4_only: svc[:ipv4_only], + debug: svc[:debug], + log_file: svc[:log_file], + workers: svc[:workers], + install_type: svc[:install_type], + supervisor_gid: svc[:supervisor_gid], + user: svc[:user], + web_address: svc[:web_address], + web_port: svc[:web_port] + ) + cookbook svc[:templates_cookbook] + run_template_name svc[:runit_run_template_name] + log_template_name svc[:runit_log_template_name] + end + new_resource.updated_by_last_action(ri.updated_by_last_action?) +end + +private + +def default_args + svc = svc_vars + args = ['agent', '-f', "#{svc[:home]}/etc/conf.d/"] + args.concat ['-vv'] if svc[:debug] + args.concat ['-l', "#{svc[:home]}/log/#{svc[:log_file]}"] if svc[:log_file] + args.concat ['-w', svc[:workers].to_s] if svc[:workers] + args +end + +def service_action(action) + svc = svc_vars + @run_context.include_recipe 'runit::default' + sv = runit_service svc[:service_name] + sv.run_action(action) + sv.updated_by_last_action? +end + +def svc_vars + svc = { + name: @instance, + service_name: @service_name, + home: @home, + method: @method, + command: @command, + description: @description, + chdir: @chdir, + user: @user, + group: @group, + log_file: @log_file, + max_heap: @max_heap, + min_heap: @min_heap, + java_opts: @java_opts, + ipv4_only: @ipv4_only, + workers: @workers, + debug: @debug, + supervisor_gid: @supervisor_gid, + templates_cookbook: @templates_cookbook, + runit_run_template_name: @runit_run_template_name, + runit_log_template_name: @runit_log_template_name, + nofile_soft: @nofile_soft, + nofile_hard: @nofile_hard + } + svc +end diff --git a/recipes/apache.rb b/recipes/apache.rb deleted file mode 100644 index 18ee098..0000000 --- a/recipes/apache.rb +++ /dev/null @@ -1,39 +0,0 @@ -# -# Cookbook Name:: kibana -# Recipe:: apache -# -# Copyright 2013, John E. Vincent -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -node.set['apache2']['default_site_enabled'] = node['kibana']['apache']['enable_default_site'] - -include_recipe 'apache2' -include_recipe 'apache2::mod_dir' -include_recipe 'apache2::mod_proxy' -include_recipe 'apache2::mod_proxy_http' - -web_app "#{node['kibana']['webserver_hostname']}-#{node['kibana']['webserver_port']}" do - cookbook node['kibana']['apache']['template_cookbook'] - docroot node['kibana']['web_dir'] - template node['kibana']['apache']['template'] - es_server node['kibana']['es_server'] - es_port node['kibana']['es_port'] - server_name node['kibana']['webserver_hostname'] - server_aliases node['kibana']['webserver_aliases'] - kibana_dir node['kibana']['web_dir'] - listen_address node['kibana']['webserver_listen'] - listen_port node['kibana']['webserver_port'] - es_scheme node['kibana']['es_scheme'] -end diff --git a/recipes/install.rb b/recipes/install.rb index be81679..410fecf 100644 --- a/recipes/install.rb +++ b/recipes/install.rb @@ -80,7 +80,7 @@ user: kibana_user, home: "#{node['kibana']['install_dir']}/current" ) - cookbook 'kibana' + cookbook 'kibana_lwrp' subscribes :restart, "template[#{kibana_config}]", :delayed end diff --git a/recipes/nginx.rb b/recipes/nginx.rb deleted file mode 100644 index c492df5..0000000 --- a/recipes/nginx.rb +++ /dev/null @@ -1,41 +0,0 @@ -# -# Cookbook Name:: kibana -# Recipe:: nginx -# -# Copyright 2013, John E. Vincent -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -node.set['nginx']['default_site_enabled'] = node['kibana']['nginx']['enable_default_site'] -node.set['nginx']['install_method'] = node['kibana']['nginx']['install_method'] - -include_recipe 'nginx' - -template "#{node['nginx']['dir']}/sites-available/kibana" do - source node['kibana']['nginx']['template'] - cookbook node['kibana']['nginx']['template_cookbook'] - notifies :reload, 'service[nginx]' - variables( - es_server: node['kibana']['es_server'], - es_port: node['kibana']['es_port'], - server_name: node['kibana']['webserver_hostname'], - server_aliases: node['kibana']['webserver_aliases'], - kibana_dir: node['kibana']['web_dir'], - listen_address: node['kibana']['webserver_listen'], - listen_port: node['kibana']['webserver_port'], - es_scheme: node['kibana']['es_scheme'] - ) -end - -nginx_site 'kibana' diff --git a/resources/service.rb b/resources/service.rb new file mode 100644 index 0000000..882af3f --- /dev/null +++ b/resources/service.rb @@ -0,0 +1,24 @@ +# Encoding: utf-8 +# Cookbook Name:: kibana +# Resource:: install +# Author:: John E. Vincent +# Author:: Paul Czarkowski +# Copyright 2014, John E. Vincent +# License:: Apache 2.0 + + +actions :enable, :start, :restart, :reload, :stop + +default_action :enable if defined?(default_action) + +attribute :name, kind_of: String, name_attribute: true +attribute :user, kind_of: String +attribute :group, kind_of: String + +attribute :service_name, kind_of: String +attribute :command, kind_of: String +attribute :args, kind_of: Array +attribute :description, kind_of: String +attribute :template_cookbook, kind_of: String +attribute :run_template_name, kind_of: String +attribute :log_template_name, kind_of: String