Created
May 25, 2011 18:41
-
-
Save fearoffish/991604 to your computer and use it in GitHub Desktop.
Scout recipe and databag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Recipe | |
# Grab our key details and user/group from the databag | |
scout_details = data_bag_item("scout", "main") | |
group scout_details["group"] do | |
action [ :create, :manage ] | |
end | |
user scout_details["user"] do | |
comment "Scout Agent" | |
gid scout_details["group"] | |
home "/home/#{scout_details["user"]}" | |
supports :manage_home => true | |
action [ :create, :manage ] | |
end | |
# install scout agent gem | |
gem_package "scout" do | |
version scout_details["version"] | |
action :install | |
end | |
if scout_details["keys"] | |
# Find the correct key for this server role (webserver, database or workers) | |
# This means we can get plugins per server role thanks to Scout's cloud instance templates | |
key = scout_details["keys"].keys.detect {|k| node.roles.include? k } | |
if key | |
key = scout_details["keys"][key] | |
# initialize scout gem | |
bash "initialize scout" do | |
code "#{scout_details["scout_bin"]} --name='#{node.name}' #{key}" | |
not_if do File.exist?("/var/spool/cron/crontabs/scout") end | |
end | |
# schedule scout agent to run via cron | |
cron "scout_run" do | |
user scout_details["user"] | |
# Use the new name property on the scout agent, to give it a specific name | |
command "#{scout_details["scout_bin"]} --name='#{node.name}' #{key}" | |
minute "*/5" | |
only_if do File.exist?("/usr/bin/scout") end | |
end | |
else | |
Chef::Log.info "No role has been set that matches the scout roles" | |
end | |
else | |
Chef::Log.info "Add a [:keys] data bag attribute to configure this node's Scout Agent" | |
end | |
## Databag | |
{ | |
"id": "main", | |
"user": "scout", | |
"group": "scout", | |
"version": "5.3.2", | |
"keys": { | |
"webserver": "WEBSERVER_SCOUT_KEY", | |
"database": "DATABASE_SCOUT_KEY", | |
"workers": "WORKERS_SCOUT_KEY" | |
}, | |
"scout_bin": "/usr/bin/scout" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment