Skip to content

Commit

Permalink
Foodcritic, port and path attributes to customize
Browse files Browse the repository at this point in the history
* FC001 - use strings in preference to symbols
* FC019 - consistent attribute access
* Add listen_port attribute to customize the web port
  This attribute is used in the HW gdash cookbook.
* Add base_dir attribute for customizing the base location of graphite
* Add doc_root attribute for customizing the DocumentRoot for vhost
  • Loading branch information
jtimberman committed Sep 26, 2012
1 parent efe53aa commit d494d0e
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 60 deletions.
29 changes: 16 additions & 13 deletions attributes/graphite.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
default[:graphite][:version] = "0.9.9"
default[:graphite][:python_version] = "2.6"
default['graphite']['version'] = "0.9.9"
default['graphite']['python_version'] = "2.6"

default[:graphite][:carbon][:uri] = "http://launchpadlibrarian.net/82112362/carbon-#{node[:graphite][:version]}.tar.gz"
default[:graphite][:carbon][:checksum] = "b3d42e3b93c09"
default['graphite']['carbon']['uri'] = "http://launchpadlibrarian.net/82112362/carbon-#{node['graphite']['version']}.tar.gz"
default['graphite']['carbon']['checksum'] = "b3d42e3b93c09"

default[:graphite][:whisper][:uri] = "http://launchpadlibrarian.net/82112367/whisper-#{node[:graphite][:version]}.tar.gz"
default[:graphite][:whisper][:checksum] = "66c05eafe8d86"
default['graphite']['whisper']['uri'] = "http://launchpadlibrarian.net/82112367/whisper-#{node['graphite']['version']}.tar.gz"
default['graphite']['whisper']['checksum'] = "66c05eafe8d86"

default[:graphite][:graphite_web][:uri] = "http://launchpadlibrarian.net/82112308/graphite-web-#{node[:graphite][:version]}.tar.gz"
default[:graphite][:graphite_web][:checksum] = "cc78bab7fb26b"
default['graphite']['graphite_web']['uri'] = "http://launchpadlibrarian.net/82112308/graphite-web-#{node['graphite']['version']}.tar.gz"
default['graphite']['graphite_web']['checksum'] = "cc78bab7fb26b"

default[:graphite][:carbon][:line_receiver_interface] = "127.0.0.1"
default[:graphite][:carbon][:pickle_receiver_interface] = "127.0.0.1"
default[:graphite][:carbon][:cache_query_interface] = "127.0.0.1"
default['graphite']['carbon']['line_receiver_interface'] = "127.0.0.1"
default['graphite']['carbon']['pickle_receiver_interface'] = "127.0.0.1"
default['graphite']['carbon']['cache_query_interface'] = "127.0.0.1"

default[:graphite][:password] = "change_me"
default[:graphite][:url] = "graphite"
default['graphite']['password'] = "change_me"
default['graphite']['url'] = "graphite"
default['graphite']['listen_port'] = "80"
default['graphite']['base_dir'] = "/opt/graphite"
default['graphite']['doc_root'] = "/opt/graphite/webapp"
26 changes: 13 additions & 13 deletions recipes/carbon.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package "python-twisted"
package "python-simplejson"

version = node[:graphite][:version]
pyver = node[:graphite][:python_version]
version = node['graphite']['version']
pyver = node['graphite']['python_version']

remote_file "/usr/src/carbon-#{version}.tar.gz" do
source node[:graphite][:carbon][:uri]
checksum node[:graphite][:carbon][:checksum]
source node['graphite']['carbon']['uri']
checksum node['graphite']['carbon']['checksum']
end

execute "untar carbon" do
Expand All @@ -17,33 +17,33 @@

execute "install carbon" do
command "python setup.py install"
creates "/opt/graphite/lib/carbon-#{version}-py#{pyver}.egg-info"
creates "#{node['graphite']['base_dir']}/lib/carbon-#{version}-py#{pyver}.egg-info"
cwd "/usr/src/carbon-#{version}"
end

template "/opt/graphite/conf/carbon.conf" do
template "#{node['graphite']['base_dir']}/conf/carbon.conf" do
owner node['apache']['user']
group node['apache']['group']
variables( :line_receiver_interface => node[:graphite][:carbon][:line_receiver_interface],
:pickle_receiver_interface => node[:graphite][:carbon][:pickle_receiver_interface],
:cache_query_interface => node[:graphite][:carbon][:cache_query_interface] )
variables( :line_receiver_interface => node['graphite']['carbon']['line_receiver_interface'],
:pickle_receiver_interface => node['graphite']['carbon']['pickle_receiver_interface'],
:cache_query_interface => node['graphite']['carbon']['cache_query_interface'] )
notifies :restart, "service[carbon-cache]"
end

template "/opt/graphite/conf/storage-schemas.conf" do
template "#{node['graphite']['base_dir']}/conf/storage-schemas.conf" do
owner node['apache']['user']
group node['apache']['group']
end

execute "carbon: change graphite storage permissions to apache user" do
command "chown -R #{node['apache']['user']}:#{node['apache']['group']} /opt/graphite/storage"
command "chown -R www-data:www-data #{node['graphite']['base_dir']}/storage"
only_if do
f = File.stat("/opt/graphite/storage")
f = File.stat("#{node['graphite']['base_dir']}/storage")
f.uid == 0 and f.gid == 0
end
end

directory "/opt/graphite/lib/twisted/plugins/" do
directory "#{node['graphite']['base_dir']}/lib/twisted/plugins/" do
owner node['apache']['user']
group node['apache']['group']
end
Expand Down
30 changes: 16 additions & 14 deletions recipes/web.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
include_recipe "apache2::mod_python"

version = node[:graphite][:version]
pyver = node[:graphite][:python_version]
basedir = node['graphite']['base_dir']
version = node['graphite']['version']
pyver = node['graphite']['python_version']

package "python-cairo-dev"
package "python-django"
Expand All @@ -10,8 +11,8 @@
package "python-rrdtool"

remote_file "/usr/src/graphite-web-#{version}.tar.gz" do
source node[:graphite][:graphite_web][:uri]
checksum node[:graphite][:graphite_web][:checksum]
source node['graphite']['graphite_web']['uri']
checksum node['graphite']['graphite_web']['checksum']
end

execute "untar graphite-web" do
Expand All @@ -22,7 +23,7 @@

execute "install graphite-web" do
command "python setup.py install"
creates "/opt/graphite/webapp/graphite_web-#{version}-py#{pyver}.egg-info"
creates "#{node['graphite']['doc_root']}/graphite_web-#{version}-py#{pyver}.egg-info"
cwd "/usr/src/graphite-web-#{version}"
end

Expand All @@ -32,39 +33,40 @@

apache_site "graphite"

directory "/opt/graphite/storage" do
directory "#{basedir}/storage" do
owner node['apache']['user']
group node['apache']['group']
end

directory '/opt/graphite/storage/log' do
directory "#{basedir}/storage/log" do
owner node['apache']['user']
group node['apache']['group']
end

%w{ webapp whisper }.each do |dir|
directory "/opt/graphite/storage/log/#{dir}" do
directory "#{basedir}/storage/log/#{dir}" do
owner node['apache']['user']
group node['apache']['group']
end
end

cookbook_file "/opt/graphite/bin/set_admin_passwd.py" do
mode "755"
template "#{basedir}/bin/set_admin_passwd.py" do
source "set_admin_passwd.py.erb"
mode 00755
end

cookbook_file "/opt/graphite/storage/graphite.db" do
cookbook_file "#{basedir}/storage/graphite.db" do
action :create_if_missing
notifies :run, "execute[set admin password]"
end

execute "set admin password" do
command "/opt/graphite/bin/set_admin_passwd.py root #{node[:graphite][:password]}"
command "#{basedir}/bin/set_admin_passwd.py root #{node['graphite']['password']}"
action :nothing
end

file "/opt/graphite/storage/graphite.db" do
file "#{basedir}/storage/graphite.db" do
owner node['apache']['user']
group node['apache']['group']
mode "644"
mode 00644
end
8 changes: 4 additions & 4 deletions recipes/whisper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
version = node[:graphite][:version]
pyver = node[:graphite][:python_version]
version = node['graphite']['version']
pyver = node['graphite']['python_version']

remote_file "/usr/src/whisper-#{version}.tar.gz" do
source node[:graphite][:whisper][:uri]
checksum node[:graphite][:whisper][:checksum]
source node['graphite']['whisper']['uri']
checksum node['graphite']['whisper']['checksum']
end

execute "untar whisper" do
Expand Down
2 changes: 1 addition & 1 deletion templates/default/carbon.conf.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[cache]
LOCAL_DATA_DIR = /opt/graphite/storage/whisper/
LOCAL_DATA_DIR = <%= node['graphite']['base_dir'] %>/storage/whisper/

# Specify the user to drop privileges to
# If this is blank carbon runs as the user that invokes it
Expand Down
20 changes: 8 additions & 12 deletions templates/default/graphite-vhost.conf.erb
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
# Graphite Apache Virtual Host
#
# Generated by Chef
NameVirtualHost *:<%= node['graphite']['listen_port'] %>

# You may need to manually edit this file to fit your needs.
# This configuration assumes the default installation prefix
# of /opt/graphite/, if you installed graphite somewhere else
# you will need to change all the occurances of /opt/graphite/
# in this file to your chosen install location.

<VirtualHost *:80>
ServerName <%= node[:graphite][:url] %>
DocumentRoot "/opt/graphite/webapp"
ErrorLog /opt/graphite/storage/log/webapp/error.log
CustomLog /opt/graphite/storage/log/webapp/access.log common
<VirtualHost *:<%= node['graphite']['listen_port']%>>
ServerName <%= node['graphite']['url'] %>
DocumentRoot "<%= node['graphite']['doc_root'] %>"
ErrorLog <%= node['graphite']['base_dir'] %>/storage/log/webapp/error.log
CustomLog <%= node['graphite']['base_dir'] %>/storage/log/webapp/access.log common

<Location "/">
SetHandler python-program
PythonPath "['/opt/graphite/webapp'] + sys.path"
PythonPath "['<%= node['graphite']['base_dir'] %>'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE graphite.settings
PythonDebug Off
Expand All @@ -31,7 +27,7 @@
SetHandler None
</Location>

<% if node[:recipes].include? "ganglia::web" -%>
<% if node['recipes'].include? "ganglia::web" -%>
<Location "/ganglia/">
SetHandler None
</Location>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# cribbed from https://gist.github.com/97863dc8171c7b473c94#file_set_admin_password.py

import os,sys
sys.path.append("/opt/graphite/webapp/graphite")
sys.path.append("<%= node['graphite']['doc_root']%>/graphite")
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from django.contrib.auth.models import User

Expand Down
2 changes: 1 addition & 1 deletion templates/default/sv-carbon-cache-finish.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
PIDFILE="/opt/graphite/storage/carbon-cache-a.pid"
PIDFILE="<%= node['graphite']['base_dir'] %>/storage/carbon-cache-a.pid"

if [ -e $PIDFILE ]; then
rm -v $PIDFILE
Expand Down
2 changes: 1 addition & 1 deletion templates/default/sv-carbon-cache-run.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
exec 2>&1
exec chpst -u <%= node['apache']['user'] %>:<%= node['apache']['group'] %> -l /opt/graphite/storage/carbon-cache.lock -- /opt/graphite/bin/carbon-cache.py --debug start
exec chpst -u <%= node['apache']['user'] %>:<%= node['apache']['group'] %> -l <%= node['graphite']['base_dir'] %>/storage/carbon-cache.lock -- <%= node['graphite']['base_dir']%>/bin/carbon-cache.py --debug start

0 comments on commit d494d0e

Please sign in to comment.