summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgebele <gebele@in-silico.ch>2017-03-16 12:57:38 +0000
committergebele <gebele@in-silico.ch>2017-03-16 12:57:38 +0000
commit554f822b7c8ada1f33bbfcc1edbd7150ea5cd4a1 (patch)
treef7a23d9f8944562bb5ab4c8fd6dfeba2155fe44a
parent9cd2431197c4bc1cbaa3c21d5341079f567b9265 (diff)
parent91ad959bdc1d0ebea295e7dc13f2ec80dec04d19 (diff)
Merge branch 'master' into development
-rw-r--r--lib/lazar.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/lazar.rb b/lib/lazar.rb
index f251379..a756742 100644
--- a/lib/lazar.rb
+++ b/lib/lazar.rb
@@ -16,16 +16,19 @@ raise "Incorrect lazar environment variable LAZAR_ENV '#{ENV["LAZAR_ENV"]}', ple
ENV["MONGOID_ENV"] = ENV["LAZAR_ENV"]
ENV["RACK_ENV"] = ENV["LAZAR_ENV"] # should set sinatra environment
+# search for a central mongo database in use
+# http://opentox.github.io/installation/2017/03/07/use-central-mongodb-in-docker-environment
+CENTRAL_MONGO_IP = `grep -oP '^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}(?=.*mongodb)' /etc/hosts`.chomp
Mongoid.load_configuration({
:clients => {
:default => {
:database => ENV["LAZAR_ENV"],
- :hosts => ["localhost:27017"],
+ :hosts => (CENTRAL_MONGO_IP.blank? ? ["localhost:27017"] : ["#{CENTRAL_MONGO_IP}:27017"]),
}
}
})
Mongoid.raise_not_found_error = false # return nil if no document is found
-$mongo = Mongo::Client.new("mongodb://127.0.0.1:27017/#{ENV['LAZAR_ENV']}")
+$mongo = Mongo::Client.new("mongodb://#{(CENTRAL_MONGO_IP.blank? ? "127.0.0.1" : CENTRAL_MONGO_IP)}:27017/#{ENV['LAZAR_ENV']}")
$gridfs = $mongo.database.fs
# Logger setup