@@ -255,14 +255,15 @@ (print megatest-version) (exit))) (define *didsomething* #f) -(if (and (or (args:get-arg "-list-targets") - (args:get-arg "-list-db-targets")) - (not (args:get-arg "-transport"))) - (hash-table-set! args:arg-hash "-transport" "fs")) +;; Force default transport to fs +;; (if ;; (and (or (args:get-arg "-list-targets") +;; ;; (args:get-arg "-list-db-targets")) +;; (not (args:get-arg "-transport")) +;; (hash-table-set! args:arg-hash "-transport" "fs")) ;;====================================================================== ;; Misc setup stuff ;;====================================================================== @@ -304,48 +305,83 @@ ;; Start the server - can be done in conjunction with -runall or -runtests (one day...) ;; we start the server if not running else start the client thread ;;====================================================================== (if (args:get-arg "-server") - (let ((transport (args:get-arg "-transport" "http"))) + + ;; Server? Start up here. + ;; + (let ((tl (setup-for-run)) + (transport (or (configf:lookup *configdat* "setup" "transport") + (args:get-arg "-transport" "http")))) (debug:print 2 "Launching server using transport " transport) (server:launch (string->symbol transport))) - (if (not (null? (lset-intersection + + ;; Not a server? This section will decide how to communicate + ;; + ;; Setup client for all expect listed here + (if (null? (lset-intersection equal? (hash-table-keys args:arg-hash) - '("-runtests" "-list-runs" "-rollup" - "-remove-runs" "-lock" "-unlock" - "-update-meta" "-extract-ods")))) + '("-list-servers" + "-stop-server" + "-show-cmdinfo"))) (if (setup-for-run) - (let loop ((servers (open-run-close tasks:get-best-server tasks:open-db)) - (trycount 0)) - (if (or (not servers) - (null? servers)) - (begin - (if (even? trycount) ;; just do the server start every other time through this loop (every 8 seconds) - (begin - (debug:print 0 "INFO: Starting server as none running ...") - ;; (server:launch (string->symbol (args:get-arg "-transport" "http")))) - ;; no need to use fork, no need to do the list-servers trick. Just start the damn server, it will exit on it's own - ;; if there is an existing server - (system "megatest -server - -daemonize") - (thread-sleep! 3) - ;; (process-run (car (argv)) (list "-server" "-" "-daemonize" "-transport" (args:get-arg "-transport" "http"))) - ;; (system (conc "megatest -list-servers | egrep '" megatest-version ".*alive' || megatest -server - -daemonize && sleep 3")) - ;; (process-fork (lambda () - ;; (daemon:ize) - ;; (server:launch (string->symbol (args:get-arg "-transport" "http"))))) - ) - (begin - (debug:print-info 0 "Waiting for server to start") - (thread-sleep! 4))) - (if (< trycount 10) - (loop (open-run-close tasks:get-best-server tasks:open-db) - (+ trycount 1)) - (debug:print 0 "WARNING: Couldn't start or find a server."))) - (debug:print 0 "INFO: Server(s) running " servers) - ))))) + (begin + + ;; if not list or kill then start a client (if appropriate) + (if (or (args-defined? "-h" "-version" "-gen-megatest-area" "-gen-megatest-test") + (eq? (length (hash-table-keys args:arg-hash)) 0)) + (debug:print-info 1 "Server connection not needed") + ;; ok, so lets connect to the server + (let* ((transport-from-config (configf:lookup *configdat* "setup" "transport")) + (transport-from-cmdln (args:get-arg "-transport")) + (transport-from-cmdinfo (if (getenv "MT_CMDINFO") + (let ((res (assoc 'transport + (read + (open-input-string + (base64:base64-decode + (getenv "MT_CMDINFO"))))))) + (if res (cadr res) #f)) + #f)) + (chosen-transport (string->symbol (or transport-from-cmdln + transport-from-cmdinfo + transport-from-config + "fs")))) + (debug:print 2 "chosen-transport: " chosen-transport " have; config=" transport-from-config ", cmdln=" transport-from-cmdln ", cmdinfo=" transport-from-cmdinfo) + (case chosen-transport + ((http) + (set! *transport-type 'http) + (server:ensure-running) + (client:launch)) + (else ;; (fs) + (set! *transport-type* 'fs) + (set! *megatest-db* (open-db)))))))))) +;; (cond +;; ;; command line overrides other mechanisms +;; (transport-from-cmdln +;; (if (equal? transport-from-cmdln "fs") +;; (set! *transport-type* 'fs) +;; (begin +;; (server:ensure-running) +;; (client:launch)))) +;; ;; cmdinfo is second priority +;; (transport-from-cmdinfo +;; (if (equal? transport-from-cmdinfo "fs") +;; (set! *transport-type* 'fs) +;; (begin +;; (server:ensure-running) +;; (client:launch)))) +;; ;; config file is next highest priority for determinining transport +;; (transport-from-config +;; (if (equal? transport-from-config "fs") +;; (set! *transport-type* 'fs) +;; (begin +;; (server:ensure-running) +;; (client:launch)))) +;; (else +;; (set! *transport-type* 'fs))))))))) (if (or (args:get-arg "-list-servers") (args:get-arg "-stop-server")) (let ((tl (setup-for-run))) (if tl @@ -390,17 +426,11 @@ (tasks:kill-server status hostname pullport pid transport))))) servers) (debug:print-info 1 "Done with listservers") (set! *didsomething* #t) (exit)) ;; must do, would have to add checks to many/all calls below - (exit))) - ;; if not list or kill then start a client (if appropriate) - (if (or (args-defined? "-h" "-version" "-gen-megatest-area" "-gen-megatest-test") - (eq? (length (hash-table-keys args:arg-hash)) 0)) - (debug:print-info 1 "Server connection not needed") - ;; ok, so lets connect to the server - (client:launch))) + (exit)))) ;;====================================================================== ;; Weird special calls that need to run *after* the server has started? ;;====================================================================== @@ -443,11 +473,12 @@ (else (debug:print 0 "ERROR: -dumpmode of " (args:get-arg "-dumpmode") " not recognised"))) (set! *didsomething* #t))) (if (args:get-arg "-show-config") - (let ((data *configdat*)) ;; (read-config "megatest.config" #f #t))) + (let ((tl (setup-for-run)) + (data *configdat*)) ;; (read-config "megatest.config" #f #t))) ;; keep this one local (cond ((not (args:get-arg "-dumpmode")) (pp (hash-table->alist data))) ((string=? (args:get-arg "-dumpmode") "json") @@ -455,15 +486,17 @@ (else (debug:print 0 "ERROR: -dumpmode of " (args:get-arg "-dumpmode") " not recognised"))) (set! *didsomething* #t))) (if (args:get-arg "-show-cmdinfo") - (let ((data (read (open-input-string (base64:base64-decode (getenv "MT_CMDINFO")))))) - (if (equal? (args:get-arg "-dumpmode") "json") - (json-write data) - (pp data)) - (set! *didsomething* #t))) + (if (getenv "MT_CMDINFO") + (let ((data (read (open-input-string (base64:base64-decode (getenv "MT_CMDINFO")))))) + (if (equal? (args:get-arg "-dumpmode") "json") + (json-write data) + (pp data)) + (set! *didsomething* #t)) + (debug:print-info 0 "environment variable MT_CMDINFO is not set"))) ;;====================================================================== ;; Remove old run(s) ;;====================================================================== @@ -697,11 +730,11 @@ (status (args:get-arg ":status")) (target (args:get-arg "-target")) (toppath (assoc/default 'toppath cmdinfo))) (change-directory toppath) ;; (set! *runremote* runremote) - (set! *transport-type* (string->symbol transport)) + ;; (set! *transport-type* (string->symbol transport)) (if (not target) (begin (debug:print 0 "ERROR: -target is required.") (exit 1))) (if (not (setup-for-run)) @@ -748,11 +781,11 @@ (state (args:get-arg ":state")) (status (args:get-arg ":status")) (target (args:get-arg "-target"))) (change-directory testpath) ;; (set! *runremote* runremote) - (set! *transport-type* (string->symbol transport)) + ;; (set! *transport-type* (string->symbol transport)) (if (not target) (begin (debug:print 0 "ERROR: -target is required.") (exit 1))) (if (not (setup-for-run)) @@ -829,11 +862,12 @@ (itemdat (assoc/default 'itemdat cmdinfo)) (work-area (assoc/default 'work-area cmdinfo)) (db #f)) (change-directory testpath) ;; (set! *runremote* runremote) - (set! *transport-type* (string->symbol transport)) + ;; The transport is handled earlier in the loading process of megatest. + ;; (set! *transport-type* (string->symbol transport)) (if (not (setup-for-run)) (begin (debug:print 0 "Failed to setup, exiting") (exit 1))) (if (and state status) @@ -881,17 +915,17 @@ (work-area (assoc/default 'work-area cmdinfo)) (db #f) ;; (open-db)) (state (args:get-arg ":state")) (status (args:get-arg ":status"))) ;; (set! *runremote* runremote) - (set! *transport-type* (string->symbol transport)) + ;; (set! *transport-type* (string->symbol transport)) (if (not (setup-for-run)) (begin (debug:print 0 "Failed to setup, exiting") (exit 1))) - (debug:print-info 1 "Runing -runstep, first change to directory " work-area) + (if (args:get-arg "-runstep")(debug:print-info 1 "Running -runstep, first change to directory " work-area)) (change-directory work-area) ;; can setup as client for server mode now ;; (client:setup) (if (args:get-arg "-load-test-data") @@ -1075,12 +1109,10 @@ (db (if toppath (open-db) #f))) (if db (begin (set! *db* db) (set! *client-non-blocking-mode* #t) - ;; (client:setup) - ;; (client:launch) (import readline) (import apropos) (gnu-history-install-file-manager (string-append (or (get-environment-variable "HOME") ".") "/.megatest_history"))