Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Changed cookbook name to kibana_lwrp
Browse files Browse the repository at this point in the history
LWRPs are ironically now HWRPs using poise.
  • Loading branch information
paulczar committed Dec 26, 2014
1 parent d1f8d09 commit d0d68ba
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 151 deletions.
2 changes: 1 addition & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ suites:
- name: default
run_list:
- recipe[apt::default]
- recipe[kibana::install]
- recipe[kibana_lwrp::install]
attributes:
java:
install_flavor: "oracle"
Expand Down
25 changes: 0 additions & 25 deletions .tailor

This file was deleted.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions Strainerfile

This file was deleted.

28 changes: 0 additions & 28 deletions Vagabondfile

This file was deleted.

8 changes: 4 additions & 4 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions metadata.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name 'kibana'
name 'kibana_lwrp'
maintainer 'John E. Vincent'
maintainer_email '[email protected]'
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

Expand Down
131 changes: 131 additions & 0 deletions providers/service.rb
Original file line number Diff line number Diff line change
@@ -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
39 changes: 0 additions & 39 deletions recipes/apache.rb

This file was deleted.

2 changes: 1 addition & 1 deletion recipes/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
41 changes: 0 additions & 41 deletions recipes/nginx.rb

This file was deleted.

24 changes: 24 additions & 0 deletions resources/service.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d0d68ba

Please sign in to comment.