Skip to content
Browse files

Merge pull request #5 from bbg-cookbooks/bluebox

Bluebox: Add RHEL support
  • Loading branch information...
2 parents 9bd7895 + c7cf2d0 commit 2c4de017b32ef057fd883cdd678455a6f99e811b @hectcastro committed Dec 27, 2012
Showing with 140 additions and 9 deletions.
  1. +2 −1 metadata.rb
  2. +26 −8 recipes/default.rb
  3. +112 −0 templates/default/statsd.erb
View
3 metadata.rb
@@ -4,12 +4,13 @@
description "Installs and configures StatsD."
version "0.0.7"
recipe "statsd", "Installs and configures StatsD"
+name "statsd"
%w{ git logrotate nodejs }.each do |d|
depends d
end
-%w{ ubuntu }.each do |os|
+%w{ ubuntu rhel scientific redhat centos amazon}.each do |os|
supports os
end
View
34 recipes/default.rb
@@ -25,13 +25,26 @@
notifies :restart, "service[statsd]"
end
-template "/etc/init/statsd.conf" do
- mode "0644"
- source "statsd.conf.erb"
- variables(
- :log_file => node["statsd"]["log_file"],
- :platform_version => node["platform_version"].to_f
- )
+
+case node["platform_family"]
+when "debian"
+ template "/etc/init/statsd.conf" do
+ mode "0644"
+ source "statsd.conf.erb"
+ variables(
+ :log_file => node["statsd"]["log_file"],
+ :platform_version => node["platform_version"].to_f
+ )
+ end
+when "rhel","fedora"
+ template "/etc/init.d/statsd" do
+ mode "0755"
+ source "statsd.erb"
+ variables(
+ :log_file => node["statsd"]["log_file"],
+ )
+ supports :start => true, :stop => true, :restart => true, :status => true
+ end
end
user "statsd" do
@@ -53,6 +66,11 @@
end
service "statsd" do
- provider Chef::Provider::Service::Upstart
+ case node["platform"]
+ when "ubuntu"
+ if node["platform_version"].to_f >= 9.10
+ provider Chef::Provider::Service::Upstart
+ end
+ end
action [ :enable, :start ]
end
View
112 templates/default/statsd.erb
@@ -0,0 +1,112 @@
+#!/bin/bash
+#
+# /etc/rc.d/init.d/statsd
+#
+# Starts the statsd daemon
+#
+# chkconfig: 2345 20 80
+# description: Frontend aggregatation of messages destined for graphite daemon
+# processname: statsd
+
+### BEGIN INIT INFO
+# Provides: statsd
+# Defalt-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Description: Frontend aggregatation of messages destined for graphite daemon
+### END INIT INFO
+
+
+
+# Source function library.
+. /etc/rc.d/init.d/functions
+
+NAME=statsd
+INSTALL_DIR=/usr/share/$NAME
+NODE_EXE=/usr/local/bin/node
+
+[ -x $NODE_EXE ] || exit 0
+[ -f $INSTALL_DIR/stats.js ] || exit 0
+
+RETVAL=0
+
+#
+# See how we were called.
+#
+
+start() {
+ # Check if it is already running
+ if [ ! -f /var/lock/subsys/$NAME ]; then
+ echo -n $"Starting $NAME daemon: "
+ # daemon
+ sudo -u statsd -- $NODE_EXE $INSTALL_DIR/stats.js /etc/$NAME/config.js > <%= @log_file %> 2>&1 < <%= @log_file %> &
+ RETVAL=$?
+ if [ $RETVAL -eq 0 ]; then
+ touch /var/lock/subsys/$NAME
+ echo_success
+ else
+ echo_failure
+ fi
+ echo
+ fi
+ return $RETVAL
+}
+
+stop() {
+ echo -n $"Stopping $NAME daemon: "
+ pid=$(ps aux | grep stats.js | grep nodejs | awk '{print $2}')
+ kill $pid
+ RETVAL=$?
+ if [ $RETVAL -eq 0 ]; then
+ rm -f /var/lock/subsys/$NAME
+ echo_success
+ else
+ echo_failure
+ fi
+ echo
+ return $RETVAL
+}
+
+
+restart() {
+ stop
+ start
+}
+
+reload() {
+ trap "" SIGHUP
+ killall -HUP stats.js
+}
+
+case "$1" in
+start)
+ start
+ ;;
+stop)
+ stop
+ ;;
+reload)
+ reload
+ ;;
+restart)
+ restart
+ ;;
+condrestart)
+ if [ -f /var/lock/subsys/$NAME ]; then
+ restart
+ fi
+ ;;
+status)
+ if [ -f /var/lock/subsys/$NAME ]; then
+ echo "$NAME is running"
+ exit 0
+ else
+ echo "$NAME is stopped"
+ exit 3
+ fi
+ ;;
+*)
+ echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
+ exit 1
+esac
+
+exit $RETVAL

0 comments on commit 2c4de01

Please sign in to comment.
Something went wrong with that request. Please try again.