Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added runit support

  • Loading branch information...
commit 4921f7f56f65e4fff792b2c8b2b5b3bb5de2f573 1 parent f9aa871
@gansbrest gansbrest authored
View
1  attributes/default.rb
@@ -9,6 +9,7 @@
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
2  metadata.rb
@@ -6,7 +6,7 @@
recipe "statsd", "Installs and configures StatsD"
name "statsd"
-%w{ git logrotate nodejs }.each do |d|
+%w{ git logrotate nodejs runit }.each do |d|
depends d
end
View
52 recipes/default.rb
@@ -1,11 +1,12 @@
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,41 +31,14 @@
: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"]
@@ -73,14 +47,12 @@
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
View
23 templates/default/statsd.conf.erb
@@ -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
View
111 templates/default/statsd.erb
@@ -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
View
2  templates/default/sv-statsd-log-run.erb
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec svlogd -tt ./main
View
4 templates/default/sv-statsd-run.erb
@@ -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
+
Please sign in to comment.
Something went wrong with that request. Please try again.