From 2e8dbfeea1e97f7c459f087144f41e5f13e2ec83 Mon Sep 17 00:00:00 2001 From: Jacob Dearing Date: Wed, 22 Jul 2015 07:49:26 -0500 Subject: [PATCH] use runit for kibana; future plans to use it for all --- Berksfile | 1 + Gemfile | 0 libraries/provider_kibana_config.rb | 6 -- libraries/provider_kibana_service.rb | 31 +++--- .../provider_logstash_forwarder_service.rb | 8 +- libraries/provider_logstash_service.rb | 10 +- metadata.rb | 3 +- .../elasticsearch/elasticsearch.initd.erb | 0 templates/centos/kibana/kibana.initd.erb | 97 ++++++++++++++++++- templates/centos/sv-kibana-run.erb | 6 ++ test/cookbooks/elktest/metadata.rb | 1 + test/cookbooks/elktest/recipes/default.rb | 2 + test/cookbooks/elktest/recipes/kibana.rb | 3 +- 13 files changed, 134 insertions(+), 34 deletions(-) mode change 100755 => 100644 Berksfile mode change 100755 => 100644 Gemfile mode change 100755 => 100644 libraries/provider_kibana_config.rb mode change 100755 => 100644 libraries/provider_kibana_service.rb mode change 100755 => 100644 metadata.rb mode change 100755 => 100644 templates/centos/elasticsearch/elasticsearch.initd.erb mode change 100755 => 100644 templates/centos/kibana/kibana.initd.erb create mode 100644 templates/centos/sv-kibana-run.erb mode change 100755 => 100644 test/cookbooks/elktest/metadata.rb mode change 100755 => 100644 test/cookbooks/elktest/recipes/default.rb mode change 100755 => 100644 test/cookbooks/elktest/recipes/kibana.rb diff --git a/Berksfile b/Berksfile old mode 100755 new mode 100644 index 39e2f2f..68e0d62 --- a/Berksfile +++ b/Berksfile @@ -5,4 +5,5 @@ metadata group :integration do cookbook 'yum' cookbook 'elktest', path: './test/cookbooks/elktest' + cookbook 'runit', '~> 1.7.2' end diff --git a/Gemfile b/Gemfile old mode 100755 new mode 100644 diff --git a/libraries/provider_kibana_config.rb b/libraries/provider_kibana_config.rb old mode 100755 new mode 100644 index b711853..faed7b0 --- a/libraries/provider_kibana_config.rb +++ b/libraries/provider_kibana_config.rb @@ -37,12 +37,6 @@ class KibanaConfig < Chef::Provider::LWRPBase } end end - - action :delete do - file '/etc/kibana.yml' do - action :remove - end - end end end end diff --git a/libraries/provider_kibana_service.rb b/libraries/provider_kibana_service.rb old mode 100755 new mode 100644 index 18cab33..8eee5b6 --- a/libraries/provider_kibana_service.rb +++ b/libraries/provider_kibana_service.rb @@ -19,48 +19,47 @@ class KibanaService < Chef::Provider::LWRPBase version new_resource.version end - template '/etc/init.d/kibana' do + runit_service 'kibana' do + default_logger true + owner "kibana" + group "kibana" cookbook new_resource.source - source 'kibana/kibana.initd.erb' - owner 'root' - group 'root' - mode '0755' + action [:create, :enable] end - end action :delete do - service 'kibana' do + runit_service 'kibana' do action :stop end end action :enable do - service 'kibana' do - action :enable + runit_service 'kibana' do + action :enable end end action :disable do - service 'kibana' do - action :disable + runit_service 'kibana' do + action :disable end end action :restart do - service 'kibana' do - action :restart + runit_service 'kibana' do + action [:stop, :start] end end action :start do - service 'kibana' do - action :start + runit_service 'kibana' do + action :start end end action :stop do - service 'kibana' do + runit_service 'kibana' do action :stop end end diff --git a/libraries/provider_logstash_forwarder_service.rb b/libraries/provider_logstash_forwarder_service.rb index 1e61c7b..8a083cd 100755 --- a/libraries/provider_logstash_forwarder_service.rb +++ b/libraries/provider_logstash_forwarder_service.rb @@ -32,25 +32,25 @@ class LogstashForwarderService < Chef::Provider::LWRPBase action :disable do service service_name do - action :disable + action :disable end end action :restart do service service_name do - action :restart + action :restart end end action :start do service service_name do - action :start + action :start end end action :stop do service service_name do - action :stop + action :stop end end diff --git a/libraries/provider_logstash_service.rb b/libraries/provider_logstash_service.rb index 0ea707f..e918fdd 100755 --- a/libraries/provider_logstash_service.rb +++ b/libraries/provider_logstash_service.rb @@ -19,32 +19,32 @@ class LogstashService < Chef::Provider::LWRPBase action :stop end package service_name do - action :remove + action :remove end remove_repository end action :enable do service service_name do - action :enable + action :enable end end action :restart do service service_name do - action :restart + action :restart end end action :start do service service_name do - action :start + action :start end end action :stop do service service_name do - action :stop + action :stop end end diff --git a/metadata.rb b/metadata.rb old mode 100755 new mode 100644 index a25f33f..6290e17 --- a/metadata.rb +++ b/metadata.rb @@ -4,9 +4,10 @@ license 'MIT' description 'Installs/Configures ELK' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '0.1.0' +version '0.2.0' supports 'centos' depends 'yum' depends 'ark' +depends 'runit' diff --git a/templates/centos/elasticsearch/elasticsearch.initd.erb b/templates/centos/elasticsearch/elasticsearch.initd.erb old mode 100755 new mode 100644 diff --git a/templates/centos/kibana/kibana.initd.erb b/templates/centos/kibana/kibana.initd.erb old mode 100755 new mode 100644 index c73f9b2..800dc84 --- a/templates/centos/kibana/kibana.initd.erb +++ b/templates/centos/kibana/kibana.initd.erb @@ -1,3 +1,98 @@ +#!/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 -# this left blank \ No newline at end of file +# 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/centos/sv-kibana-run.erb b/templates/centos/sv-kibana-run.erb new file mode 100644 index 0000000..7436962 --- /dev/null +++ b/templates/centos/sv-kibana-run.erb @@ -0,0 +1,6 @@ +#!/bin/sh + +cd /home/kibana +exec 2>&1 + +exec /usr/bin/env kibana -c /etc/kibana.yml diff --git a/test/cookbooks/elktest/metadata.rb b/test/cookbooks/elktest/metadata.rb old mode 100755 new mode 100644 index c68bff3..c91096d --- a/test/cookbooks/elktest/metadata.rb +++ b/test/cookbooks/elktest/metadata.rb @@ -7,3 +7,4 @@ version '0.1.0' depends 'elk' +depends 'runit' \ No newline at end of file diff --git a/test/cookbooks/elktest/recipes/default.rb b/test/cookbooks/elktest/recipes/default.rb old mode 100755 new mode 100644 index cbab186..a22f48c --- a/test/cookbooks/elktest/recipes/default.rb +++ b/test/cookbooks/elktest/recipes/default.rb @@ -5,6 +5,8 @@ package 'java-1.8.0-openjdk-headless' package 'nginx' +include_recipe 'runit::default' + include_recipe 'elktest::elasticsearch' include_recipe 'elktest::logstash' include_recipe 'elktest::logstash_forwarder' diff --git a/test/cookbooks/elktest/recipes/kibana.rb b/test/cookbooks/elktest/recipes/kibana.rb old mode 100755 new mode 100644 index f66bb62..6d37c11 --- a/test/cookbooks/elktest/recipes/kibana.rb +++ b/test/cookbooks/elktest/recipes/kibana.rb @@ -1,8 +1,9 @@ kibana_service 'default' do - action [:create, :enable] + action [:create] end kibana_config 'default' do + port 8080 action :create notifies :restart, 'kibana_service[default]' end