                 console.log(err, output)
                 cb?(err)
 
-wait_for_url_to_work = (opts) ->
+get_with_retry = (opts) ->
     opts = defaults opts,
         url           : required
         initial_delay : 100
         max_delay     : 15000     # once delay hits this, give up
         factor        : 1.2       # for exponential backoff
-        cb            : required  # cb(err)
+        cb            : required  # cb(err, data)  # data = content of that url
     delay = opts.initial_delay
     f = () =>
         if delay >= opts.max_delay  # too many attempts
             opts.cb("unable to connect to remote server")
             return
         $.get(opts.url, (data) ->
-            console.log(data.slice(0,100))
-            if 'ECONNREFUSED' in data or '404: Not Found' in data
+            if 'ECONNREFUSED' in data
                 delay *= opts.factor
                 setTimeout(f, delay)
             else
-                opts.cb(false)
+                opts.cb(false, data)
         ).fail(() ->
             delay *= 1.2
             setTimeout(f, delay)

                if err
                    cb(err)
                else
                    delay = 100
                    @info = misc.from_json(output.stdout)
                    {base, pid, port} = @info
                    wait_for_url_to_work
                        url : base
                        cb  : (err) => cb(err, base)

    stop_server: (cb) =>
        if not @info?.pid?
            cb?(); return
        salvus_client.exec
            project_id : @project_id

# IPython Support
#**************************************************

ipython_notebook_server = (opts) ->
    opts = defaults opts,
        project_id : required
        path       : required   # directory from which the files are served
        cb         : required   # cb(err, server)

    I = new IPythonNotebookServer(opts.project_id, opts.path)
    I.start_server (err, base) =>
        opts.cb(err, I)

class IPythonNotebookServer  # call ipython_notebook_server above
    constructor: (@project_id, @path) ->

    start_server: (cb) =>
        salvus_client.exec
            project_id : @project_id
            path       : @path
