Permalink
Browse files

Merge pull request #19 from gansbrest/use_runit

Use runit to start / stop statsd process. Much more reliable than previous init scripts.
  • Loading branch information...
hectcastro committed Jun 15, 2013
2 parents f9aa871 + 3e3b0b1 commit 2c99a41dd633923455ce35d6b0e035852699e314
View
@@ -33,6 +33,8 @@ Installs and configures StatsD.
inactive timers (default: `false`).
* `node["statsd"]["delete_gauges"]` - Don't send values to graphite for
inactive gauges (default: `false`).
+* `node["statsd"]["username"]` - Will be used for process supervision (default: `stasd` )
+
* `node["statsd"]["graphite"]["legacy_namespace"]` - Flag to use legacy
namespace (default: `true`).
* `node["statsd"]["graphite"]["global_prefix"]` - Global prefix to use for
View
@@ -1,14 +1,14 @@
default["statsd"]["dir"] = "/usr/share/statsd"
default["statsd"]["conf_dir"] = "/etc/statsd"
default["statsd"]["repository"] = "git://github.com/etsy/statsd.git"
-default["statsd"]["log_file"] = "/var/log/statsd.log"
default["statsd"]["flush_interval"] = 10000
default["statsd"]["address"] = "0.0.0.0"
default["statsd"]["port"] = 8125
default["statsd"]["graphite_host"] = "localhost"
default["statsd"]["graphite_port"] = 2003
default["statsd"]["delete_timers"] = false
default["statsd"]["delete_gauges"] = false
+default["statsd"]["username"] = "statsd"
# Graphite storage config
default["statsd"]["graphite"]["legacy_namespace"] = true
View
@@ -6,11 +6,10 @@
recipe "statsd", "Installs and configures StatsD"
name "statsd"
-%w{ git logrotate nodejs }.each do |d|
+%w{ git nodejs runit }.each do |d|
depends d
end
%w{ ubuntu rhel scientific redhat centos amazon}.each do |os|
supports os
end
-
View
@@ -1,11 +1,11 @@
include_recipe "git"
include_recipe "nodejs"
-include_recipe "logrotate"
+include_recipe "runit"
git node["statsd"]["dir"] do
repository node["statsd"]["repository"]
action :sync
- notifies :restart, "service[statsd]"
+ notifies :restart, "runit_service[statsd]"
end
directory node["statsd"]["conf_dir"] do
@@ -30,57 +30,20 @@
:prefix_gauge => node["statsd"]["graphite"]["prefix_gauge"],
:prefix_set => node["statsd"]["graphite"]["prefix_set"]
)
- notifies :restart, "service[statsd]"
+ notifies :restart, "runit_service[statsd]"
end
-
-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"],
- :node_dir => node["statsd"]["dir"]
- )
- end
-end
-
-user "statsd" do
+user "#{node['statsd']['username']}" do
system true
shell "/bin/false"
end
-file node["statsd"]["log_file"] do
- owner "statsd"
- action :create
-end
-
-logrotate_app "statsd" do
- cookbook "logrotate"
- path node["statsd"]["log_file"]
- frequency "daily"
- rotate 7
- create "644 root root"
-end
-
-service "statsd" do
- case node["platform"]
- when "ubuntu"
- if node["platform_version"].to_f >= 9.10
- provider Chef::Provider::Service::Upstart
- end
- #restart_command "sudo service statsd stop && sudo service statsd start"
- end
- action [ :enable, :start ]
- supports :start => true, :stop => true, :restart => true, :status => true
+runit_service "statsd" do
+ action [:enable, :start]
+ default_logger true
+ options ({
+ :user => node['statsd']['username'],
+ :statsd_dir => node['statsd']['dir'],
+ :conf_dir => node['statsd']['conf_dir']
+ })
end
@@ -1,23 +0,0 @@
-description "StatsD"
-author "Chef"
-
-start on (filesystem and net-device-up)
-stop on runlevel [!2345]
-
-respawn
-respawn limit 5 30
-
-chdir <%= @node['statsd']['dir'] %>
-<% unless @platform_version < 11.10 -%>
-setuid statsd
-<% end %>
-
-script
-<% if @platform_version < 11.10 -%>
- exec start-stop-daemon --start --chuid statsd --exec node <%= @node['statsd']['dir'] %>/stats.js <%= @node['statsd']['conf_dir'] %>/config.js >> <%= @log_file %> 2>&1
-<% else -%>
- exec node <%= @node['statsd']['dir'] %>/stats.js <%= @node['statsd']['conf_dir'] %>/config.js >> <%= @log_file %> 2>&1
-<% end -%>
-end script
-
-emits statsd-running
@@ -1,111 +0,0 @@
-#!/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=<%= @node_dir %>
-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: "
- kill $(ps aux | grep stats.js | grep statsd | awk '{print $2}')
- 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,0 +1,2 @@
+#!/bin/sh
+exec svlogd -tt ./main
@@ -0,0 +1,4 @@
+#!/bin/sh
+exec 2>&1
+exec chpst -u <%= @options[:user] %> /usr/local/bin/node <%= @options[:statsd_dir] %>/stats.js <%= @options[:conf_dir] %>/config.js
+

0 comments on commit 2c99a41

Please sign in to comment.