Skip to content

Instantly share code, notes, and snippets.

@thoward
Created September 25, 2013 09:12
Show Gist options
  • Save thoward/6697048 to your computer and use it in GitHub Desktop.
Save thoward/6697048 to your computer and use it in GitHub Desktop.
Cloud Foundry Service Shims for Rabbit/Redis configs
#!/usr/bin/env ruby
#
# Shims Rabbit configuration for CloudFoundry
#
require 'json'
if ENV['VCAP_SERVICES']
$vcap_services ||= JSON.parse(ENV['VCAP_SERVICES'])
rabbit_service_name = $vcap_services.keys.find { |svc| svc =~ /rabbit/i }
rabbit_service = $vcap_services[rabbit_service_name].first
$rabbit_url = rabbit_service['credentials']['url']
else
$rabbit_url = "amqp://localhost"
end
ENV['RABBITMQ_URL']=$rabbit_url
#!/usr/bin/env ruby
#
# Shims Redis configuration for CloudFoundry
#
require 'json'
if ENV['VCAP_SERVICES']
$vcap_services ||= JSON.parse(ENV['VCAP_SERVICES'])
redis_service_name = $vcap_services.keys.find { |svc| svc =~ /redis/i }
redis_service = $vcap_services[redis_service_name].first
$redis_config = {
:host => redis_service['credentials']['host'],
:port => redis_service['credentials']['port'],
:password => redis_service['credentials']['password']
}
else
$redis_config = {
:host => '127.0.0.1',
:port => 6379
}
end
if $redis_config[:password]
redis_url = "redis://:#{$redis_config[:password]}@#{$redis_config[:host]}:#{$redis_config[:port]}/0"
else
redis_url = "redis://#{$redis_config[:host]}:#{$redis_config[:port]}/0"
end
ENV['REDIS_URL']=redis_url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment