             dbg("create new pid file")
             fs.writeFile(PID_FILE, "#{process.pid}", cb)
         (cb) ->
-            require('smc-hub/rethink').rethinkdb
-                hosts : DB
-                pool  : 1
-                cb    : (err, db) ->
-                    database = db
-                    cb(err)
+            get_db (err, db) ->
+                database = db
+                cb(err)
         (cb) ->
             exports.assign_storage_to_all_projects(database, cb)
         (cb) ->

                                project_id : project_id
                                host       : host
                                cb         : cb
            async.mapLimit(projects, 10, f, cb)
    ], cb)



get_storage = (project_id, database, cb) ->
    dbg = (m) -> winston.debug("get_storage(project_id='#{project_id}'): #{m}")
    database.get_project
        project_id : project_id
        columns    : ['storage']
        cb         : (err, x) ->
            if err
                cb(err)
            else if not x?
                cb("no such project")
            else
                cb(undefined, x.storage?.host)

get_host_and_storage = (project_id, database, cb) ->
    dbg = (m) -> winston.debug("get_host_and_storage(project_id='#{project_id}'): #{m}")
