Index: http-transport.scm ================================================================== --- http-transport.scm +++ http-transport.scm @@ -69,11 +69,11 @@ (server:get-best-guess-address hostname) #f))) (if ipstr ipstr hostn))) ;; hostname))) (start-port (open-run-close tasks:server-get-next-port tasks:open-db)) (link-tree-path (configf:lookup *configdat* "setup" "linktree"))) - (set! db *inmemdb*) + ;; (set! db *inmemdb*) (root-path (if link-tree-path link-tree-path (current-directory))) ;; WARNING: SECURITY HOLE. FIX ASAP! (handle-directory spiffy-directory-listing) ;; http-transport:handle-directory) ;; simple-directory-handler) @@ -86,11 +86,11 @@ (dat ($ 'dat)) (res #f)) (cond ((equal? (uri-path (request-uri (current-request))) '(/ "api")) - (send-response body: (api:process-request db $) ;; the $ is the request vars proc + (send-response body: (api:process-request *inmemdb* $) ;; the $ is the request vars proc headers: '((content-type text/plain))) (mutex-lock! *heartbeat-mutex*) (set! *last-db-access* (current-seconds)) (mutex-unlock! *heartbeat-mutex*)) ;; This is the /ctrl path where data is handed to the server and @@ -313,11 +313,11 @@ server-dat)) ;; run http-transport:keep-running in a parallel thread to monitor that the db is being ;; used and to shutdown after sometime if it is not. ;; -(define (http-transport:keep-running server-id) +(define (http-transport:keep-running server-id run-id) ;; if none running or if > 20 seconds since ;; server last used then start shutdown ;; This thread waits for the server to come alive (let* ((server-info (let loop ((start-time (current-seconds)) (changed #t) @@ -358,14 +358,16 @@ (set! sync-time (- (current-milliseconds) start-time)) (set! rem-time (quotient (- 4000 sync-time) 1000)) (debug:print 0 "SYNC: time= " sync-time ", rem-time=" rem-time) ;; - ;; set_running after our first pass through + ;; set_running after our first pass through and start the db ;; (if (eq? server-state 'available) - (tasks:server-set-state! tdb server-id "running")) + (begin + (set! *inmemdb* (db:setup run-id)) + (tasks:server-set-state! tdb server-id "running"))) (if (and (<= rem-time 4) (> rem-time 0)) (thread-sleep! rem-time) (thread-sleep! 4))) ;; fallback for if the math is changed ... @@ -467,14 +469,20 @@ (args:get-arg "-server") "-") run-id server-id)) "Server run")) (th3 (make-thread (lambda () - (http-transport:keep-running server-id)) + (http-transport:keep-running server-id run-id)) "Keep running"))) ;; Database connection - (set! *inmemdb* (db:setup run-id)) + + + ;; don't start the db here + + ;; (set! *inmemdb* (db:setup run-id)) + + (thread-start! th2) (thread-start! th3) (set! *didsomething* #t) (thread-join! th2) (exit)))))