From f43c39f6eae5002d0a0db19273398068b9eb5d83 Mon Sep 17 00:00:00 2001 From: "Julian C. Dunn" Date: Sun, 2 Dec 2012 23:31:04 -0500 Subject: [PATCH 01/11] Initial port of graphiti recipe to Fedora {17,18} --- .gitignore | 10 ++++ Berksfile | 3 + Gemfile | 4 ++ Vagrantfile | 68 ++++++++++++++++++++++ attributes/graphiti.rb | 29 +++++----- chefignore | 52 +++++++++++++++++ metadata.rb | 9 ++- recipes/default.rb | 125 ++++++++++++++++++++++++----------------- 8 files changed, 232 insertions(+), 68 deletions(-) create mode 100644 .gitignore create mode 100644 Berksfile create mode 100644 Gemfile create mode 100644 Vagrantfile create mode 100644 chefignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..77cbe8b --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +.vagrant +Berksfile.lock +Gemfile.lock +*~ +*# +.#* +\#*# +.*.sw[a-z] +*.un~ +/cookbooks diff --git a/Berksfile b/Berksfile new file mode 100644 index 0000000..c4bb297 --- /dev/null +++ b/Berksfile @@ -0,0 +1,3 @@ +site :opscode + +metadata diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..878eb92 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source :rubygems + +gem 'berkshelf' +gem 'vagrant', '~> 1.0.5' diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..a0d361b --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,68 @@ +require 'berkshelf/vagrant' + +Vagrant::Config.run do |config| + # All Vagrant configuration is done here. The most common configuration + # options are documented and commented below. For a complete reference, + # please see the online documentation at vagrantup.com. + + # The path to the Berksfile to use with Vagrant Berkshelf + # config.berkshelf.berksfile_path = "./Berksfile" + + # An array of symbols representing groups of cookbook described in the Vagrantfile + # to skip installing and copying to Vagrant's shelf. + # config.berkshelf.only = [] + + # An array of symbols representing groups of cookbook described in the Vagrantfile + # to skip installing and copying to Vagrant's shelf. + # config.berkshelf.except = [] + + config.vm.host_name = "graphiti-berkshelf" + + # config.vm.box = "Berkshelf-CentOS-6.3-x86_64-minimal" + config.vm.box = "Fedora-18-x86_64" + + #config.vm.box_url = "https://dl.dropbox.com/u/31081437/Berkshelf-CentOS-6.3-x86_64-minimal.box" + + # Boot with a GUI so you can see the screen. (Default is headless) + # config.vm.boot_mode = :gui + + # Assign this VM to a host-only network IP, allowing you to access it + # via the IP. Host-only networks can talk to the host machine as well as + # any other machines on the same network, but cannot be accessed (through this + # network interface) by any external networks. + # config.vm.network :hostonly, "192.168.66.1" + + # Assign this VM to a bridged network, allowing you to connect directly to a + # network using the host's network device. This makes the VM appear as another + # physical device on your network. + + # config.vm.network :bridged + + # Forward a port from the guest to the host, which allows for outside + # computers to access the VM, whereas host only networking does not. + # config.vm.forward_port 80, 8080 + + # Share an additional folder to the guest VM. The first argument is + # an identifier, the second is the path on the guest to mount the + # folder, and the third is the path on the host to the actual folder. + # config.vm.share_folder "v-data", "/vagrant_data", "../data" + + config.ssh.max_tries = 40 + config.ssh.timeout = 120 + + config.vm.provision :chef_solo do |chef| + chef.json = { + :mysql => { + :server_root_password => 'rootpass', + :server_debian_password => 'debpass', + :server_repl_password => 'replpass' + } + } + + chef.binary_path = '/usr/local/bin' + + chef.run_list = [ + "recipe[graphiti::default]" + ] + end +end diff --git a/attributes/graphiti.rb b/attributes/graphiti.rb index 58e36b1..6adfc7c 100644 --- a/attributes/graphiti.rb +++ b/attributes/graphiti.rb @@ -1,17 +1,17 @@ -default.graphiti.tarfile = "/usr/src/graphiti.tgz" -default.graphiti.url = "https://github.com/paperlesspost/graphiti/tarball/master" -default.graphiti.base = "/srv/graphiti" -default.graphiti.graphite_host = "127.0.0.1" -default.graphiti.redis_url = "localhost:6379:1/graphiti" -default.graphiti.tmp_dir = "/srv/graphiti/tmp" -default.graphiti.metric_prefix = "collectd" -default.graphiti.default_metrics = %w[carbon.agents.*.metricsReceived] -default.graphiti.unicorn.timeout = 60 -default.graphiti.unicorn.cow_friendly = true -default.graphiti.s3_bucket = "graphiti" -default.graphiti.port = 8081 +default['graphiti']['tarfile'] = "/usr/src/graphiti.tgz" +default['graphiti']['url'] = "https://github.com/paperlesspost/graphiti/tarball/master" +default['graphiti']['base'] = "/srv/graphiti" +default['graphiti']['graphite_host'] = "127.0.0.1" +default['graphiti']['redis_url'] = "localhost:6379:1/graphiti" +default['graphiti']['tmp_dir'] = "/srv/graphiti/tmp" +default['graphiti']['metric_prefix'] = "collectd" +default['graphiti']['default_metrics'] = %w[carbon.agents.*.metricsReceived] +default['graphiti']['unicorn']['timeout'] = 60 +default['graphiti']['unicorn']['cow_friendly'] = true +default['graphiti']['s3_bucket'] = "graphiti" +default['graphiti']['port'] = 8081 -default.graphiti.default_options = { +default['graphiti']['default_options'] = { "title" => "New Graph", "from" => "-6h", "font" => "DroidSans", @@ -25,4 +25,5 @@ "areaMode" => "stacked" } -default.graphiti.graph_types = [] +default['graphiti']['graph_types'] = [] +default['graphiti']['user'] = 'graphiti' diff --git a/chefignore b/chefignore new file mode 100644 index 0000000..856929d --- /dev/null +++ b/chefignore @@ -0,0 +1,52 @@ +# Put files/directories that should be ignored in this file. +# Lines that start with '# ' are comments. + +## OS +.DS_Store +Icon? +nohup.out + +## EDITORS +\#* +.#* +*~ +*.sw[a-z] +*.bak +REVISION +TAGS* +tmtags +*_flymake.* +*_flymake +*.tmproj +.project +.settings +mkmf.log + +## COMPILED +a.out +*.o +*.pyc +*.so + +## OTHER SCM +*/.bzr/* +*/.hg/* +*/.svn/* + +## Don't send rspecs up in cookbook +.watchr +.rspec +spec/* +spec/fixtures/* +features/* + +## SCM +.gitignore + +# Berkshelf +Berksfile +Berksfile.lock +cookbooks/* + +# Vagrant +.vagrant diff --git a/metadata.rb b/metadata.rb index e871cbf..fb647e6 100644 --- a/metadata.rb +++ b/metadata.rb @@ -5,7 +5,10 @@ long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) version "0.0.1" -depends "build-essential" -depends "runit" +%w{build-essential iptables runit}.each do |d| + depends d +end -suggests "iptables" +%w{ubuntu debian fedora suse amazon}.each do |os| + supports os +end diff --git a/recipes/default.rb b/recipes/default.rb index 1a7dc37..3e0ff7c 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -18,95 +18,118 @@ # include_recipe "build-essential" -%w[libcurl4-gnutls-dev ruby1.9.1-full].each do |pkg| - apt_package pkg +user node['graphiti']['user'] do + comment "Graphiti Graphite Dashboard" + action :create end -gem_package "bundler" +case node['platform_family'] +when "debian" + %w[libcurl4-gnutls-dev ruby1.9.1-full].each do |pkg| + package pkg do + action :install + end + end + gem_package "bundler" -remote_file node.graphiti.tarfile do +when "fedora" + %w{ruby ruby-devel rubygem-bundler rubygem-daemons rubygem-rack rubygem-rake rubygem-sinatra rubygem-haml redis libcurl-devel}.each do |pkg| + package pkg do + action :install + end + end + +end + +remote_file node['graphiti']['tarfile'] do mode "00666" - owner "www-data" - group "www-data" - source node.graphiti.url + owner node['graphiti']['user'] + group node['graphiti']['user'] + source node['graphiti']['url'] action :create_if_missing end -directory node.graphiti.base do - owner "www-data" - group "www-data" +directory node['graphiti']['base'] do + owner node['graphiti']['user'] + group node['graphiti']['user'] end directory File.join(node.graphiti.base, "log") do - owner "www-data" - group "www-data" + owner node['graphiti']['user'] + group node['graphiti']['user'] end execute "bundle" do command "bundle install --deployment --binstubs; " + "bundle exec rake graphiti:metrics" - user "www-data" - group "www-data" - environment "PATH" => "/var/lib/gems/1.9.1/bin" - cwd node.graphiti.base + cwd node['graphiti']['base'] action :nothing end cron "graphiti:metrics" do minute "*/15" - command "cd #{node.graphiti.base} && /var/lib/gems/1.9.1/bin/bundle exec rake graphiti:metrics" - user "www-data" + command "cd #{node['graphiti']['base']} && bundle exec rake graphiti:metrics" + user node['graphiti']['user'] end execute "graphiti: untar" do - command "tar zxf #{node.graphiti.tarfile} -C #{node.graphiti.base} --strip-components=1" - creates File.join(node.graphiti.base, "Rakefile") - user "www-data" - group "www-data" + command "tar zxf #{node['graphiti']['tarfile']} -C #{node['graphiti']['base']} --strip-components=1" + creates File.join(node['graphiti']['base'], "Rakefile") + user node['graphiti']['user'] + group node['graphiti']['user'] notifies :run, resources(:execute => "bundle"), :immediately end -aws = data_bag_item "aws", node.chef_environment -template File.join(node.graphiti.base, "config", "amazon_s3.yml") do - variables :hash => { node.chef_environment => { - "bucket" => node.graphiti.s3_bucket, - "access_key_id" => aws["aws_access_key_id"], - "secret_access_key" => aws["aws_secret_access_key"] - } } - owner "www-data" - group "www-data" - notifies :restart, "service[graphiti]" -end +# XXX domain-specific stuff. Not everyone has their databags set up like this +# (nor does everyone want graph storage in S3 as a feature) +#aws = data_bag_item "aws", node.chef_environment +#template File.join(node.graphiti.base, "config", "amazon_s3.yml") do +# variables :hash => { node.chef_environment => { +# "bucket" => node.graphiti.s3_bucket, +# "access_key_id" => aws["aws_access_key_id"], +# "secret_access_key" => aws["aws_secret_access_key"] +# } } +# owner node['graphiti']['user'] +# group node['graphiti']['user'] +# notifies :restart, "service[graphiti]" +#end template File.join(node.graphiti.base, "config", "settings.yml") do - owner "www-data" - group "www-data" + owner node['graphiti']['user'] + group node['graphiti']['user'] variables :hash => { - "graphite_host" => node.graphiti.graphite_host, - "redis_url" => node.graphiti.redis_url, - "tmp_dir" => node.graphiti.tmp_dir, + "graphite_host" => node['graphiti']['graphite_host'], + "redis_url" => node['graphiti']['redis_url'], + "tmp_dir" => node['graphiti']['tmp_dir'], "fonts" => %w[DroidSans DejaVuSans], - "metric_prefix" => node.graphiti.metric_prefix, - "default_options" => node.graphiti.default_options.to_hash, - "default_metrics" => node.graphiti.default_metrics.to_a, + "metric_prefix" => node['graphiti']['metric_prefix'], + "default_options" => node['graphiti']['default_options'].to_hash, + "default_metrics" => node['graphiti']['default_metrics'].to_a, } notifies :restart, "service[graphiti]" end directory "/var/run/unicorn" do - owner "www-data" - group "www-data" + owner node['graphiti']['user'] + group node['graphiti']['user'] end -template File.join(node.graphiti.base, "config", "unicorn.rb") do - owner "www-data" - group "www-data" - variables( :worker_processes => node.cpu.total, - :timeout => node.graphiti.unicorn.timeout, - :cow_friendly => node.graphiti.unicorn.cow_friendly ) +template File.join(node['graphiti']['base'], "config", "unicorn.rb") do + owner node['graphiti']['user'] + group node['graphiti']['user'] + variables( :worker_processes => node['cpu']['total'], + :timeout => node['graphiti']['unicorn']['timeout'], + :cow_friendly => node['graphiti']['unicorn']['cow_friendly'] ) notifies :restart, "service[graphiti]" end -runit_service "graphiti" - +case node['platform_family'] +when "debian" + runit_service "graphiti" +when "fedora" + # XXX still need to write init script + service "graphiti" do + action [ :enable, :start ] + end +end From 175255da8fcdbe0ccb9a971f5feec6a50470fd3e Mon Sep 17 00:00:00 2001 From: "Julian C. Dunn" Date: Sun, 2 Dec 2012 23:42:59 -0500 Subject: [PATCH 02/11] No need to install redis package, as we're not necessarily installing Redis on the same box as the Graphiti installation --- recipes/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/default.rb b/recipes/default.rb index 3e0ff7c..871c136 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -33,7 +33,7 @@ gem_package "bundler" when "fedora" - %w{ruby ruby-devel rubygem-bundler rubygem-daemons rubygem-rack rubygem-rake rubygem-sinatra rubygem-haml redis libcurl-devel}.each do |pkg| + %w{ruby ruby-devel rubygem-bundler rubygem-daemons rubygem-rack rubygem-rake rubygem-sinatra rubygem-haml libcurl-devel}.each do |pkg| package pkg do action :install end From 3a633e60326dab747f267fa80a856a886dbc40a2 Mon Sep 17 00:00:00 2001 From: "Julian C. Dunn" Date: Fri, 21 Dec 2012 11:15:52 -0500 Subject: [PATCH 03/11] Foodcritic fixes; more Fedora support. Stub out init script while testing --- Vagrantfile | 2 +- metadata.rb | 3 +- recipes/default.rb | 14 +++- recipes/graph_generator.rb | 8 +- templates/default/graphiti-init.erb | 113 ++++++++++++++++++++++++++++ test/kitchen/Kitchenfile | 3 + 6 files changed, 136 insertions(+), 7 deletions(-) create mode 100644 templates/default/graphiti-init.erb create mode 100644 test/kitchen/Kitchenfile diff --git a/Vagrantfile b/Vagrantfile index a0d361b..396adee 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -21,7 +21,7 @@ Vagrant::Config.run do |config| # config.vm.box = "Berkshelf-CentOS-6.3-x86_64-minimal" config.vm.box = "Fedora-18-x86_64" - #config.vm.box_url = "https://dl.dropbox.com/u/31081437/Berkshelf-CentOS-6.3-x86_64-minimal.box" + config.vm.box_url = "https://dl.dropbox.com/u/47541301/vagrantboxes/Fedora-18-x86_64.box" # Boot with a GUI so you can see the screen. (Default is headless) # config.vm.boot_mode = :gui diff --git a/metadata.rb b/metadata.rb index fb647e6..5567428 100644 --- a/metadata.rb +++ b/metadata.rb @@ -1,3 +1,4 @@ +name "graphiti" maintainer "Heavy Water Software Inc." maintainer_email "ops@hw-ops.com" license "Apache 2.0" @@ -9,6 +10,6 @@ depends d end -%w{ubuntu debian fedora suse amazon}.each do |os| +%w{ubuntu debian fedora amazon}.each do |os| supports os end diff --git a/recipes/default.rb b/recipes/default.rb index 871c136..05b6ab3 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -54,7 +54,7 @@ group node['graphiti']['user'] end -directory File.join(node.graphiti.base, "log") do +directory File.join(node['graphiti']['base'], "log") do owner node['graphiti']['user'] group node['graphiti']['user'] end @@ -95,7 +95,7 @@ # notifies :restart, "service[graphiti]" #end -template File.join(node.graphiti.base, "config", "settings.yml") do +template File.join(node['graphiti']['base'], "config", "settings.yml") do owner node['graphiti']['user'] group node['graphiti']['user'] variables :hash => { @@ -128,7 +128,15 @@ when "debian" runit_service "graphiti" when "fedora" - # XXX still need to write init script + + template "/etc/init.d/graphiti" do + source "graphiti-init.erb" + owner "root" + group "root" + mode 00755 + action :create + end + service "graphiti" do action [ :enable, :start ] end diff --git a/recipes/graph_generator.rb b/recipes/graph_generator.rb index 008fc0b..da8569a 100644 --- a/recipes/graph_generator.rb +++ b/recipes/graph_generator.rb @@ -17,6 +17,10 @@ # limitations under the License. # +if Chef::Config[:solo] + Chef::Log.warn("This recipe does not work properly in Solo mode; it depends on search.") + return +end nodes = search(:node, "graphiti_graph_types:*") nodes.map do |remote_node| @@ -46,7 +50,7 @@ "title" => "#{remote_node.fqdn} #{graph_type}" } - options = node.graphiti.default_options.to_hash.deep_merge(options) + options = node['graphiti']['default_options'].to_hash.deep_merge(options) graphiti_graph options["title"] do type graph_type @@ -84,7 +88,7 @@ end } - options = node.graphiti.default_options.to_hash.deep_merge(options) + options = node['graphiti']['default_options'].to_hash.deep_merge(options) graphiti_graph "#{title}_#{from}" do type title diff --git a/templates/default/graphiti-init.erb b/templates/default/graphiti-init.erb new file mode 100644 index 0000000..ca960b8 --- /dev/null +++ b/templates/default/graphiti-init.erb @@ -0,0 +1,113 @@ +#!/bin/bash +# +# graphiti - Startup script for the Graphiti dashboard +# +# chkconfig: - 98 02 +# description: Graphiti dashboard (frontend) for Graphite + +### BEGIN INIT INFO +# Provides: graphiti +# Required-Start: $local_fs $network $remote_fs +# Required-Stop: $local_fs $network $remote_fs +# Should-Start: $named $time +# Should-Stop: $named $time +# Short-Description: Startup script for the Graphiti dashboard +# Description: Graphiti dashboard (frontend) for Graphite +### END INIT INFO + +# Source function library +. /etc/init.d/functions + +#exec="<%= @client_bin %>" +prog="graphiti" + +[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog + +#config=${CONFIG-/etc/chef/client.rb} +#pidfile=${PIDFILE-/var/run/chef/client.pid} +#lockfile=${LOCKFILE-/var/lock/subsys/$prog} +#logfile=${LOGFILE-/var/log/chef/client.log} +#interval=${INTERVAL-1800} +#splay=${SPLAY-20} +#options=${OPTIONS-} + +start() { +# [ -x $exec ] || exit 5 +# [ -f $config ] || exit 6 + echo -n $"Starting $prog: " +# daemon $exec -d -c "$config" -L "$logfile" -P "$pidfile" -i "$interval" -s "$splay" "$options" +# retval=$? +# echo +# [ $retval -eq 0 ] && touch $lockfile +# return $retval + return 0 +} + +stop() { + echo -n $"Stopping $prog: " +# killproc -p $pidfile $exec +# retval=$? +# echo +# [ $retval -eq 0 ] && rm -f $lockfile +# return $retval + return 0 +} + +restart () { + stop + start +} + +reload() { + echo -n $"Reloading $prog: " +# killproc -p $pidfile $exec -HUP +# retval=$? +# echo +# return $retval + return 0 +} + +force_reload() { + restart +} + +rh_status() { + # run checks to determine if the service is running or use generic status + status -p $pidfile $prog +} + +rh_status_q() { + rh_status >/dev/null 2>&1 +} + +case "$1" in + start) + rh_status_q && exit 0 + $1 + ;; + stop) + rh_status_q || exit 0 + $1 + ;; + restart) + $1 + ;; + reload) + rh_status_q || exit 7 + $1 + ;; + force-reload) + force_reload + ;; + status) + rh_status + ;; + condrestart|try-restart) + rh_status_q || exit 0 + restart + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" + exit 2 +esac +exit $? diff --git a/test/kitchen/Kitchenfile b/test/kitchen/Kitchenfile new file mode 100644 index 0000000..6a314d8 --- /dev/null +++ b/test/kitchen/Kitchenfile @@ -0,0 +1,3 @@ +cookbook "graphiti" do + +end From 74ef41a8ba7a2499d1c231d63799831facec65b9 Mon Sep 17 00:00:00 2001 From: "Julian C. Dunn" Date: Fri, 21 Dec 2012 11:18:32 -0500 Subject: [PATCH 04/11] Ignore test kitchen files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 77cbe8b..4b77218 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.kitchen .vagrant Berksfile.lock Gemfile.lock From 662c0a7a77ba3790712ad13d389f6475972889c6 Mon Sep 17 00:00:00 2001 From: "Julian C. Dunn" Date: Fri, 21 Dec 2012 12:01:05 -0500 Subject: [PATCH 05/11] Add port forwarding of 8081 to the localhost in Vagrantfile Remove debian-specific values in unicorn config --- Vagrantfile | 2 +- templates/default/unicorn.rb.erb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 396adee..c7b615f 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -40,7 +40,7 @@ Vagrant::Config.run do |config| # Forward a port from the guest to the host, which allows for outside # computers to access the VM, whereas host only networking does not. - # config.vm.forward_port 80, 8080 + config.vm.forward_port 8081, 8081 # Share an additional folder to the guest VM. The first argument is # an identifier, the second is the path on the guest to mount the diff --git a/templates/default/unicorn.rb.erb b/templates/default/unicorn.rb.erb index 901e745..3e30503 100644 --- a/templates/default/unicorn.rb.erb +++ b/templates/default/unicorn.rb.erb @@ -1,5 +1,5 @@ worker_processes <%= @worker_processes %> -working_directory "/srv/graphiti" +working_directory "<%= node['graphiti']['base'] %>" listen "/var/run/unicorn/unicorn.socket", :backlog => 64 pid "/var/run/unicorn/unicorn.pid" @@ -17,7 +17,7 @@ before_fork do |server, worker| begin uid, gid = Process.euid, Process.egid - user, group = "www-data", "www-data" + user, group = "<%= node['graphiti']['user'] %>", "<%= node['graphiti']['user'] %>" target_uid = Etc.getpwnam(user).uid target_gid = Etc.getgrnam(group).gid worker.tmp.chown(target_uid, target_gid) From 6d36b41c4080cc6d22d53e2ef56411027177561b Mon Sep 17 00:00:00 2001 From: "Julian C. Dunn" Date: Fri, 21 Dec 2012 16:36:57 -0500 Subject: [PATCH 06/11] Fixes after testing --- Berksfile | 1 + Vagrantfile | 9 +++++---- attributes/graphiti.rb | 9 +++++++-- recipes/default.rb | 20 ++++++++++++++------ 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Berksfile b/Berksfile index c4bb297..76b777f 100644 --- a/Berksfile +++ b/Berksfile @@ -1,3 +1,4 @@ site :opscode metadata +cookbook 'redis', '>= 0.3.2', chef_api: :config diff --git a/Vagrantfile b/Vagrantfile index c7b615f..698b476 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -52,16 +52,17 @@ Vagrant::Config.run do |config| config.vm.provision :chef_solo do |chef| chef.json = { - :mysql => { - :server_root_password => 'rootpass', - :server_debian_password => 'debpass', - :server_repl_password => 'replpass' + :graphiti => { + :base => '/opt/graphiti', + :graphite_base_url => 'http://graphite.2mlabs.com', + :tmp_dir => '/opt/graphiti/tmp' } } chef.binary_path = '/usr/local/bin' chef.run_list = [ + "recipe[redis::server]", "recipe[graphiti::default]" ] end diff --git a/attributes/graphiti.rb b/attributes/graphiti.rb index 6adfc7c..f8921ec 100644 --- a/attributes/graphiti.rb +++ b/attributes/graphiti.rb @@ -1,7 +1,7 @@ -default['graphiti']['tarfile'] = "/usr/src/graphiti.tgz" +default['graphiti']['tarfile'] = "#{Chef::Config[:file_cache_path]}/graphiti.tgz" default['graphiti']['url'] = "https://github.com/paperlesspost/graphiti/tarball/master" default['graphiti']['base'] = "/srv/graphiti" -default['graphiti']['graphite_host'] = "127.0.0.1" +default['graphiti']['graphite_base_url'] = "http://localhost/" default['graphiti']['redis_url'] = "localhost:6379:1/graphiti" default['graphiti']['tmp_dir'] = "/srv/graphiti/tmp" default['graphiti']['metric_prefix'] = "collectd" @@ -25,5 +25,10 @@ "areaMode" => "stacked" } +default['graphiti']['auto_refresh'] = { + "enabled" => true, + "interval" => 60 +} + default['graphiti']['graph_types'] = [] default['graphiti']['user'] = 'graphiti' diff --git a/recipes/default.rb b/recipes/default.rb index 05b6ab3..596468d 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -33,7 +33,7 @@ gem_package "bundler" when "fedora" - %w{ruby ruby-devel rubygem-bundler rubygem-daemons rubygem-rack rubygem-rake rubygem-sinatra rubygem-haml libcurl-devel}.each do |pkg| + %w{ruby ruby-devel rubygem-bundler rubygem-daemons rubygem-linecache19 rubygem-rack rubygem-rake rubygem-sinatra rubygem-haml libcurl-devel}.each do |pkg| package pkg do action :install end @@ -59,11 +59,17 @@ group node['graphiti']['user'] end -execute "bundle" do - command "bundle install --deployment --binstubs; " + - "bundle exec rake graphiti:metrics" +execute "bundle-install" do + command "bundle install --deployment --binstubs" + cwd node['graphiti']['base'] +# user node['graphiti']['user'] + action :nothing +end +execute "bundle-rake-generate" do + command "bundle exec rake graphiti:metrics" cwd node['graphiti']['base'] + user node['graphiti']['user'] action :nothing end @@ -78,7 +84,7 @@ creates File.join(node['graphiti']['base'], "Rakefile") user node['graphiti']['user'] group node['graphiti']['user'] - notifies :run, resources(:execute => "bundle"), :immediately + notifies :run, "execute[bundle-install]", :immediately end # XXX domain-specific stuff. Not everyone has their databags set up like this @@ -99,15 +105,17 @@ owner node['graphiti']['user'] group node['graphiti']['user'] variables :hash => { - "graphite_host" => node['graphiti']['graphite_host'], + "graphite_base_url" => node['graphiti']['graphite_base_url'], "redis_url" => node['graphiti']['redis_url'], "tmp_dir" => node['graphiti']['tmp_dir'], "fonts" => %w[DroidSans DejaVuSans], "metric_prefix" => node['graphiti']['metric_prefix'], "default_options" => node['graphiti']['default_options'].to_hash, + "auto_refresh" => node['graphiti']['auto_refresh'].to_hash, "default_metrics" => node['graphiti']['default_metrics'].to_a, } notifies :restart, "service[graphiti]" + notifies :run, "execute[bundle-rake-generate]", :immediately end directory "/var/run/unicorn" do From ce7102a99965a304c6efc20a169d9baa2b3b1d6f Mon Sep 17 00:00:00 2001 From: "Julian C. Dunn" Date: Tue, 25 Dec 2012 22:31:57 -0500 Subject: [PATCH 07/11] First working init script for Fedora --- templates/default/graphiti-init.erb | 42 +++++++++++++++-------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/templates/default/graphiti-init.erb b/templates/default/graphiti-init.erb index ca960b8..0a9e8d1 100644 --- a/templates/default/graphiti-init.erb +++ b/templates/default/graphiti-init.erb @@ -18,38 +18,40 @@ # Source function library . /etc/init.d/functions -#exec="<%= @client_bin %>" +exec="<%= node['graphiti']['base'] %>/bin/unicorn_rails" prog="graphiti" [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog -#config=${CONFIG-/etc/chef/client.rb} -#pidfile=${PIDFILE-/var/run/chef/client.pid} -#lockfile=${LOCKFILE-/var/lock/subsys/$prog} +config=${CONFIG-<%= node['graphiti']['base'] %>/config/unicorn.rb} +pidfile=${PIDFILE-/var/run/unicorn/unicorn.pid} +railsroot=${RAILS_ROOT-<%= node['graphiti']['base'] %>} +railsenv=${RAILS_ENV-production} +lockfile=${LOCKFILE-/var/lock/subsys/$prog} #logfile=${LOGFILE-/var/log/chef/client.log} #interval=${INTERVAL-1800} #splay=${SPLAY-20} #options=${OPTIONS-} start() { -# [ -x $exec ] || exit 5 -# [ -f $config ] || exit 6 + [ -x $exec ] || exit 5 + [ -f $config ] || exit 6 echo -n $"Starting $prog: " -# daemon $exec -d -c "$config" -L "$logfile" -P "$pidfile" -i "$interval" -s "$splay" "$options" -# retval=$? -# echo -# [ $retval -eq 0 ] && touch $lockfile -# return $retval + daemon --user graphiti $exec -c $config -E $railsenv -D + retval=$? + echo + [ $retval -eq 0 ] && touch $lockfile + return $retval return 0 } stop() { echo -n $"Stopping $prog: " -# killproc -p $pidfile $exec -# retval=$? -# echo -# [ $retval -eq 0 ] && rm -f $lockfile -# return $retval + killproc -p $pidfile $exec + retval=$? + echo + [ $retval -eq 0 ] && rm -f $lockfile + return $retval return 0 } @@ -60,10 +62,10 @@ restart () { reload() { echo -n $"Reloading $prog: " -# killproc -p $pidfile $exec -HUP -# retval=$? -# echo -# return $retval + killproc -p $pidfile $exec -HUP + retval=$? + echo + return $retval return 0 } From cac2ec13f22627dc01074dddc7009d7d53c9d003 Mon Sep 17 00:00:00 2001 From: "Julian C. Dunn" Date: Wed, 26 Dec 2012 20:23:16 -0500 Subject: [PATCH 08/11] Remove unnecessary comments --- templates/default/graphiti-init.erb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/templates/default/graphiti-init.erb b/templates/default/graphiti-init.erb index 0a9e8d1..e47655a 100644 --- a/templates/default/graphiti-init.erb +++ b/templates/default/graphiti-init.erb @@ -28,10 +28,6 @@ pidfile=${PIDFILE-/var/run/unicorn/unicorn.pid} railsroot=${RAILS_ROOT-<%= node['graphiti']['base'] %>} railsenv=${RAILS_ENV-production} lockfile=${LOCKFILE-/var/lock/subsys/$prog} -#logfile=${LOGFILE-/var/log/chef/client.log} -#interval=${INTERVAL-1800} -#splay=${SPLAY-20} -#options=${OPTIONS-} start() { [ -x $exec ] || exit 5 From 9a7f57237154f1c8ba25cbe46fd4e318b8769aa2 Mon Sep 17 00:00:00 2001 From: "Julian C. Dunn" Date: Wed, 26 Dec 2012 20:35:31 -0500 Subject: [PATCH 09/11] Remove SecondMarket-specific attribute --- Vagrantfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 698b476..2a03bb4 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -52,9 +52,7 @@ Vagrant::Config.run do |config| config.vm.provision :chef_solo do |chef| chef.json = { - :graphiti => { :base => '/opt/graphiti', - :graphite_base_url => 'http://graphite.2mlabs.com', :tmp_dir => '/opt/graphiti/tmp' } } From ffb379dae982e72eb6f3a0c6d6bb22f7f4501eeb Mon Sep 17 00:00:00 2001 From: "Julian C. Dunn" Date: Wed, 26 Dec 2012 22:54:02 -0500 Subject: [PATCH 10/11] Fix broken JSON. --- Vagrantfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Vagrantfile b/Vagrantfile index 2a03bb4..29b6c70 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -54,7 +54,6 @@ Vagrant::Config.run do |config| chef.json = { :base => '/opt/graphiti', :tmp_dir => '/opt/graphiti/tmp' - } } chef.binary_path = '/usr/local/bin' From bb5fc23f681c3a1a01415a5c0695dd465d4a6160 Mon Sep 17 00:00:00 2001 From: "Julian C. Dunn" Date: Mon, 7 Jan 2013 16:48:19 -0500 Subject: [PATCH 11/11] "port" setting got lost in the runit->init conversion. Create the 'graphiti' user as a system user so it can run cron jobs. --- recipes/default.rb | 1 + templates/default/graphiti-init.erb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/recipes/default.rb b/recipes/default.rb index 596468d..08badaa 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -20,6 +20,7 @@ user node['graphiti']['user'] do comment "Graphiti Graphite Dashboard" + system true action :create end diff --git a/templates/default/graphiti-init.erb b/templates/default/graphiti-init.erb index e47655a..459faa6 100644 --- a/templates/default/graphiti-init.erb +++ b/templates/default/graphiti-init.erb @@ -28,12 +28,13 @@ pidfile=${PIDFILE-/var/run/unicorn/unicorn.pid} railsroot=${RAILS_ROOT-<%= node['graphiti']['base'] %>} railsenv=${RAILS_ENV-production} lockfile=${LOCKFILE-/var/lock/subsys/$prog} +unicornport=${UNICORN_PORT-<%= node['graphiti']['port'] %>} start() { [ -x $exec ] || exit 5 [ -f $config ] || exit 6 echo -n $"Starting $prog: " - daemon --user graphiti $exec -c $config -E $railsenv -D + daemon --user graphiti $exec -c $config -E $railsenv -p $unicornport -D retval=$? echo [ $retval -eq 0 ] && touch $lockfile