define :notify_newrelic, :deploy_path=>nil, :environment=>nil do script "notifying new relic of deploy" do interpreter "ruby" user "deployer" cwd params[:name] code <<-EOS require 'rubygems' unless File.exist?("#{params[:name]}/config/newrelic.yml") puts "!!! newrelic.yml not found. Not notifying New Relic of the deploy !!!" exit 0 end ## When new relic is loaded it automagically loads up its configuration file ## And sets the config[:environment]. We are injecting the path to the configuration ## file and the environment via ENV variables. ENV['APP_ROOT'] = "#{params[:name]}" ENV['RAILS_ENV'] = "#{params[:environment]}" require 'newrelic_rpm' require 'new_relic/command' config = NewRelic::Control.instance revision = `git rev-parse HEAD`.chomp deployment = NewRelic::Command::Deployments.new({:revision => revision, :user => 'chef'}) print "New Relic : " deployment.run EOS end end