Index: megatest.scm ================================================================== --- megatest.scm +++ megatest.scm @@ -345,38 +345,12 @@ "\n")) (set! *didsomething* #t))) (if (args:get-arg "-ping") (let* ((run-id (string->number (args:get-arg "-run-id"))) - (host-port (let ((slst (string-split (args:get-arg "-ping") ":"))) - (if (eq? (length slst) 2) - (list (car slst)(string->number (cadr slst))) - #f))) - (toppath (setup-for-run)) - (server-db-dat (if (not host-port)(open-run-close tasks:get-server tasks:open-db run-id) #f))) - (if (not run-id) - (begin - (debug:print 0 "ERROR: must specify run-id when doing ping, -run-id n") - (print "ERROR: No run-id") - (exit 1)) - (if (and (not host-port) - (not server-db-dat)) - (begin - (print "ERROR: bad host:port") - (exit 1)) - (let* ((iface (if host-port (car host-port) (tasks:hostinfo-get-interface server-db-dat))) - (port (if host-port (cadr host-port)(tasks:hostinfo-get-port server-db-dat))) - (server-dat (http-transport:client-connect iface port)) - (login-res (rmt:login-no-auto-client-setup server-dat run-id))) - (if (and (list? login-res) - (car login-res)) - (begin - (print "LOGIN_OK") - (exit 0)) - (begin - (print "LOGIN_FAILED") - (exit 1)))))))) + (host:port (args:get-arg "-ping"))) + (server:ping run-id host:port))) ;;====================================================================== ;; 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 ;;====================================================================== Index: server.scm ================================================================== --- server.scm +++ server.scm @@ -80,18 +80,23 @@ ;; if the run-id is zero and the target-host is set ;; try running on that host ;; (define (server:run run-id) (let* ((curr-host (get-host-name)) + (curr-ip (server:get-best-guess-address curr-host)) (target-host (configf:lookup *configdat* "server" "homehost" )) (logfile (conc *toppath* "/db/" run-id ".log")) (cmdln (conc (common:get-megatest-exe) " -server " (or target-host "-") " -run-id " run-id " >> " logfile " 2>&1 &"))) (debug:print 0 "INFO: Starting server (" cmdln ") as none running ...") (push-directory *toppath*) ;; host.domain.tld match host? - (if (and target-host (not (string-match (conc "("curr-host "|" curr-host"\\..*)") target-host))) + (if (and target-host + ;; look at target host, is it host.domain.tld or ip address and does it + ;; match current ip or hostname + (not (string-match (conc "("curr-host "|" curr-host"\\..*)") target-host)) + (not (equal? curr-ip target-host))) (begin (debug:print-info 0 "Starting server on " target-host ", logfile is " logfile) (setenv "TARGETHOST" target-host) (setenv "TARGETHOST_LOGF" logfile) (system (conc "nbfake " cmdln))) @@ -135,10 +140,44 @@ (open-run-close tasks:server-force-clean-running-records-for-run-id tasks:open-db run-id " server:check-if-running") res))) #f))) +;; called in megatest.scm, host-port is string hostname:port +;; +(define (server:ping run-id host:port) + (let* ((host-port (let ((slst (string-split host:port ":"))) + (if (eq? (length slst) 2) + (list (car slst)(string->number (cadr slst))) + #f))) + (toppath (setup-for-run)) + (server-db-dat (if (not host-port)(open-run-close tasks:get-server tasks:open-db run-id) #f))) + (if (not run-id) + (begin + (debug:print 0 "ERROR: must specify run-id when doing ping, -run-id n") + (print "ERROR: No run-id") + (exit 1)) + (if (and (not host-port) + (not server-db-dat)) + (begin + (print "ERROR: bad host:port") + (exit 1)) + (let* ((iface (if host-port (car host-port) (tasks:hostinfo-get-interface server-db-dat))) + (port (if host-port (cadr host-port)(tasks:hostinfo-get-port server-db-dat))) + (server-dat (http-transport:client-connect iface port)) + (login-res (rmt:login-no-auto-client-setup server-dat run-id))) + (if (and (list? login-res) + (car login-res)) + (begin + (print "LOGIN_OK") + (exit 0)) + (begin + (print "LOGIN_FAILED") + (exit 1)))))))) + +;; run ping in separate process, safest way in some cases +;; (define (server:ping-server run-id iface port) (with-input-from-pipe (conc (common:get-megatest-exe) " -run-id " run-id " -ping " (conc iface ":" port)) (lambda () (let loop ((inl (read-line))