Skip to content

Commit

Permalink
use runit for kibana; future plans to use it for all
Browse files Browse the repository at this point in the history
  • Loading branch information
dearing committed Jul 22, 2015
1 parent e5383ab commit 2e8dbfe
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 34 deletions.
1 change: 1 addition & 0 deletions Berksfile
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ metadata
group :integration do
cookbook 'yum'
cookbook 'elktest', path: './test/cookbooks/elktest'
cookbook 'runit', '~> 1.7.2'
end
Empty file modified Gemfile
100755 → 100644
Empty file.
6 changes: 0 additions & 6 deletions libraries/provider_kibana_config.rb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 15 additions & 16 deletions libraries/provider_kibana_service.rb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions libraries/provider_logstash_forwarder_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions libraries/provider_logstash_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion metadata.rb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Empty file modified templates/centos/elasticsearch/elasticsearch.initd.erb
100755 → 100644
Empty file.
97 changes: 96 additions & 1 deletion templates/centos/kibana/kibana.initd.erb
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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
# 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
6 changes: 6 additions & 0 deletions templates/centos/sv-kibana-run.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

cd /home/kibana
exec 2>&1

exec /usr/bin/env kibana -c /etc/kibana.yml
1 change: 1 addition & 0 deletions test/cookbooks/elktest/metadata.rb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
version '0.1.0'

depends 'elk'
depends 'runit'
2 changes: 2 additions & 0 deletions test/cookbooks/elktest/recipes/default.rb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion test/cookbooks/elktest/recipes/kibana.rb
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2e8dbfe

Please sign in to comment.