Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for Fedora, fix Foodcritic errors #3

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.kitchen
.vagrant
Berksfile.lock
Gemfile.lock
*~
*#
.#*
\#*#
.*.sw[a-z]
*.un~
/cookbooks
4 changes: 4 additions & 0 deletions Berksfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
site :opscode

metadata
cookbook 'redis', '>= 0.3.2', chef_api: :config
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source :rubygems

gem 'berkshelf'
gem 'vagrant', '~> 1.0.5'
66 changes: 66 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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/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

# 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 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
# 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 = {
:base => '/opt/graphiti',
:tmp_dir => '/opt/graphiti/tmp'
}

chef.binary_path = '/usr/local/bin'

chef.run_list = [
"recipe[redis::server]",
"recipe[graphiti::default]"
]
end
end
34 changes: 20 additions & 14 deletions attributes/graphiti.rb
Original file line number Diff line number Diff line change
@@ -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'] = "#{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_base_url'] = "http://localhost/"
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",
Expand All @@ -25,4 +25,10 @@
"areaMode" => "stacked"
}

default.graphiti.graph_types = []
default['graphiti']['auto_refresh'] = {
"enabled" => true,
"interval" => 60
}

default['graphiti']['graph_types'] = []
default['graphiti']['user'] = 'graphiti'
52 changes: 52 additions & 0 deletions chefignore
Original file line number Diff line number Diff line change
@@ -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
10 changes: 7 additions & 3 deletions metadata.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
name "graphiti"
maintainer "Heavy Water Software Inc."
maintainer_email "[email protected]"
license "Apache 2.0"
description "Installs/Configures graphiti"
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 amazon}.each do |os|
supports os
end
152 changes: 96 additions & 56 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,95 +18,135 @@
#
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"
system true
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-linecache19 rubygem-rack rubygem-rake rubygem-sinatra rubygem-haml 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"
directory File.join(node['graphiti']['base'], "log") do
owner node['graphiti']['user']
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

user "www-data"
group "www-data"
environment "PATH" => "/var/lib/gems/1.9.1/bin"
cwd node.graphiti.base
execute "bundle-rake-generate" do
command "bundle exec rake graphiti:metrics"
cwd node['graphiti']['base']
user node['graphiti']['user']
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"
notifies :run, resources(:execute => "bundle"), :immediately
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, "execute[bundle-install]", :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"
template File.join(node['graphiti']['base'], "config", "settings.yml") do
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_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,
"default_metrics" => node.graphiti.default_metrics.to_a,
"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
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"

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
end
Loading