2002-09-20 15:23:17 -04:00
|
|
|
#!/bin/sh
|
|
|
|
echo "Loading..."
|
2002-09-26 08:13:01 -04:00
|
|
|
fullpath=`which $0`
|
|
|
|
# $sunet is either $SUNETHOME or created out of fullpath
|
|
|
|
# Kind of a hack, I know.
|
|
|
|
sunet=${SUNETHOME:-`dirname $fullpath`/../..}
|
|
|
|
ssax=${SSAXPATH:-$sunet/SSAX} # path to SSAX
|
|
|
|
|
|
|
|
exec scsh -lm $sunet/packages.scm -lm $ssax/lib/packages.scm -lm $sunet/httpd/servlets/packages.scm -dm -o servlet-server -e main -s "$0" "$@"
|
2002-09-20 15:23:17 -04:00
|
|
|
!#
|
|
|
|
|
|
|
|
(define-structure servlet-server
|
2002-09-26 08:13:01 -04:00
|
|
|
(export main ; sh jump entry point
|
|
|
|
server) ; scsh entry point
|
2002-09-20 15:23:17 -04:00
|
|
|
(open httpd-core
|
|
|
|
httpd-make-options
|
|
|
|
httpd-basic-handlers
|
|
|
|
httpd-file-directory-handlers
|
|
|
|
; cgi-server
|
|
|
|
; seval-handler
|
|
|
|
; rman-gateway
|
|
|
|
; info-gateway
|
|
|
|
servlet-handler
|
|
|
|
let-opt
|
|
|
|
scsh
|
|
|
|
scheme)
|
|
|
|
|
|
|
|
(begin
|
|
|
|
|
|
|
|
(define (usage)
|
|
|
|
(format #f
|
2002-10-22 12:01:25 -04:00
|
|
|
"Usage: start-servlet-server [-h htdocs-dir] [-s servlet-dir] [-i images-dir]
|
|
|
|
[-p port] [-l log-file-name]
|
|
|
|
[-r requests] [--help]
|
2002-09-20 15:23:17 -04:00
|
|
|
|
|
|
|
with
|
2002-09-26 08:13:01 -04:00
|
|
|
htdocs-dir directory of html files (default: ./web-server/root/htdocs)
|
|
|
|
servlet-dir directory of servlet files (default: ./web-server/root/servlets)
|
2002-10-22 12:01:25 -04:00
|
|
|
images-dir directory of images files (default: ./web-server/root/img)
|
2002-09-20 15:23:17 -04:00
|
|
|
port port server is listening to (default: 8080)
|
|
|
|
log-file-name directory where to store the logfile in CLF
|
2002-09-26 08:13:01 -04:00
|
|
|
(default: ./web-server/httpd.log)
|
2002-09-20 15:23:17 -04:00
|
|
|
requests maximal amount of simultaneous requests (default 5)
|
|
|
|
--help show this help
|
|
|
|
|
|
|
|
NOTE: This is the servlet-server. It does not support cgi-bin.
|
|
|
|
"
|
|
|
|
))
|
|
|
|
|
|
|
|
(define htdocs-dir #f)
|
2002-10-22 12:01:25 -04:00
|
|
|
(define images-dir #f)
|
2002-09-26 08:13:01 -04:00
|
|
|
; (define cgi-bin-dir #f)
|
2002-09-20 15:23:17 -04:00
|
|
|
(define port #f)
|
|
|
|
(define log-file-name #f)
|
|
|
|
(define root #f)
|
|
|
|
(define servlet-dir #f)
|
|
|
|
(define simultaneous-requests #f)
|
|
|
|
|
|
|
|
(define (init)
|
2002-09-26 08:13:01 -04:00
|
|
|
(set! htdocs-dir "./web-server/root/htdocs")
|
2002-10-22 12:01:25 -04:00
|
|
|
(set! images-dir "./web-server/root/img")
|
2002-09-26 08:13:01 -04:00
|
|
|
; (set! cgi-bin-dir "./web-server/root/cgi-bin")
|
2002-09-20 15:23:17 -04:00
|
|
|
(set! port "8088")
|
2002-09-26 08:13:01 -04:00
|
|
|
(set! log-file-name "./web-server/httpd.log")
|
|
|
|
(set! root "./web-server/root")
|
|
|
|
(set! servlet-dir "./web-server/root/servlets")
|
2002-09-20 15:23:17 -04:00
|
|
|
(set! simultaneous-requests "5"))
|
|
|
|
|
2002-09-26 08:13:01 -04:00
|
|
|
(define (normalize-options)
|
|
|
|
(set! htdocs-dir (absolute-file-name htdocs-dir))
|
2002-10-22 12:01:25 -04:00
|
|
|
(set! images-dir (absolute-file-name images-dir))
|
2002-09-26 08:13:01 -04:00
|
|
|
(set! log-file-name (absolute-file-name log-file-name))
|
|
|
|
; (set! cgi-bin-dir (absolute-file-name cgi-bin-dir))
|
|
|
|
(set! port (string->number port))
|
|
|
|
(set! servlet-dir (absolute-file-name servlet-dir))
|
|
|
|
(set! simultaneous-requests (string->number simultaneous-requests)))
|
|
|
|
|
2002-09-20 15:23:17 -04:00
|
|
|
(define get-options
|
|
|
|
(let* ((unknown-option-error
|
|
|
|
(lambda (option)
|
|
|
|
(format (error-output-port)
|
|
|
|
"unknown option `~A'~%try `servlet-server --help'~%"
|
|
|
|
option)
|
|
|
|
(exit 1)))
|
|
|
|
(missing-argument-error
|
|
|
|
(lambda (option)
|
|
|
|
(format (error-output-port)
|
|
|
|
"option `~A' requires an argument~%try `servlet-server --help'~%"
|
|
|
|
option)
|
|
|
|
(exit 1))))
|
|
|
|
(lambda (options)
|
|
|
|
(let loop ((options options))
|
|
|
|
(if (null? options)
|
2002-09-26 08:13:01 -04:00
|
|
|
(normalize-options)
|
2002-09-20 15:23:17 -04:00
|
|
|
(cond
|
|
|
|
((string=? (car options) "-h")
|
|
|
|
(if (null? (cdr options))
|
|
|
|
(missing-argument-error (car options))
|
|
|
|
(set! htdocs-dir (cadr options)))
|
|
|
|
(loop (cddr options)))
|
2002-10-22 12:01:25 -04:00
|
|
|
((string=? (car options) "-i")
|
|
|
|
(if (null? (cdr options))
|
|
|
|
(missing-argument-error (car options))
|
|
|
|
(set! images-dir (cadr options)))
|
|
|
|
(loop (cddr options)))
|
2002-09-20 15:23:17 -04:00
|
|
|
((string=? (car options) "-c")
|
|
|
|
(format (error-output-port)
|
|
|
|
"This is the servlet server. It does not support cgi.~%")
|
|
|
|
; (if (null? (cdr options))
|
|
|
|
; (missing-argument-error (car options))
|
|
|
|
; (set! cgi-bin-dir (cadr options)))
|
|
|
|
(loop (cddr options)))
|
|
|
|
((string=? (car options) "-p")
|
|
|
|
(if (null? (cdr options))
|
|
|
|
(missing-argument-error (car options))
|
|
|
|
(set! port (cadr options)))
|
|
|
|
(loop (cddr options)))
|
|
|
|
((string=? (car options) "-l")
|
|
|
|
(if (null? (cdr options))
|
|
|
|
(missing-argument-error (car options))
|
|
|
|
(set! log-file-name (cadr options)))
|
|
|
|
(loop (cddr options)))
|
|
|
|
((string=? (car options) "-s")
|
|
|
|
(if (null? (cdr options))
|
|
|
|
(missing-argument-error (car options))
|
|
|
|
(set! servlet-dir (cadr options)))
|
|
|
|
(loop (cddr options)))
|
|
|
|
((string=? (car options) "-r")
|
|
|
|
(if (null? (cdr options))
|
|
|
|
(missing-argument-error (car options))
|
|
|
|
(set! simultaneous-requests (cadr options)))
|
|
|
|
(loop (cddr options)))
|
|
|
|
((string=? (car options) "--help")
|
|
|
|
(display (usage))
|
|
|
|
(exit 0))
|
|
|
|
((string=? (car options) "--dump")
|
|
|
|
(let ((image-name (if (null? (cdr options))
|
|
|
|
"servlet-server"
|
|
|
|
(cadr options))))
|
|
|
|
(dump-scsh-program main image-name))
|
|
|
|
(exit 0))
|
|
|
|
(else
|
|
|
|
(unknown-option-error (car options)))))))))
|
|
|
|
|
2002-09-26 08:13:01 -04:00
|
|
|
(define (server . args)
|
|
|
|
(if (pair? args)
|
|
|
|
(main `(main ,@(car args)))
|
|
|
|
(main '(main))))
|
2002-09-20 15:23:17 -04:00
|
|
|
|
|
|
|
(define (main args)
|
|
|
|
(init)
|
|
|
|
(format #t "reading options: ~s~%" (cdr args))
|
|
|
|
(get-options (cdr args))
|
|
|
|
(cond ((zero? (user-uid))
|
|
|
|
(set-gid (->gid "nobody"))
|
|
|
|
(set-uid (->uid "nobody"))))
|
|
|
|
|
|
|
|
(format #t "Going to run Servlet server with:
|
|
|
|
htdocs-dir: ~a
|
2002-09-26 08:13:01 -04:00
|
|
|
servlet-dir: ~a
|
2002-10-22 12:01:25 -04:00
|
|
|
images-dir: ~a
|
2002-09-20 15:23:17 -04:00
|
|
|
port: ~a
|
|
|
|
log-file-name: ~a
|
|
|
|
a maximum of ~a simultaneous requests, syslogging activated,
|
|
|
|
and home-dir-handler (public_html) activated.
|
|
|
|
|
|
|
|
NOTE: This is the Servlet server. It does not support cgi.
|
|
|
|
"
|
|
|
|
htdocs-dir
|
2002-09-26 08:13:01 -04:00
|
|
|
servlet-dir
|
2002-10-22 12:01:25 -04:00
|
|
|
images-dir
|
2002-09-20 15:23:17 -04:00
|
|
|
port
|
|
|
|
log-file-name
|
|
|
|
simultaneous-requests)
|
|
|
|
|
|
|
|
(httpd (with-port port
|
2002-09-26 08:13:01 -04:00
|
|
|
(with-root-directory (cwd)
|
2002-09-20 15:23:17 -04:00
|
|
|
(with-simultaneous-requests simultaneous-requests
|
|
|
|
(with-syslog? #t
|
|
|
|
(with-logfile log-file-name
|
2002-10-21 04:24:58 -04:00
|
|
|
;; The following settings are made to avoid dns lookups.
|
|
|
|
(with-reported-port port
|
|
|
|
(with-fqdn "localhost"
|
|
|
|
(with-resolve-ips? #f
|
2002-09-22 11:41:41 -04:00
|
|
|
(with-request-handler
|
2002-09-20 15:23:17 -04:00
|
|
|
(alist-path-dispatcher
|
|
|
|
(list (cons "h" (home-dir-handler "public_html"))
|
|
|
|
; (cons "seval" seval-handler)
|
|
|
|
; (cons "man" (rman-handler #f "man?%s(%s)"
|
|
|
|
; "Generated by rman-gateway"))
|
|
|
|
; (cons "info" (info-handler #f #f #f
|
|
|
|
; "Generated by info-gateway"))
|
|
|
|
; (cons "cgi-bin" (cgi-handler cgi-bin-dir))
|
2002-10-22 12:01:25 -04:00
|
|
|
(cons "source" (rooted-file-or-directory-handler servlet-dir))
|
|
|
|
(cons "img" (rooted-file-handler images-dir))
|
2002-10-01 08:12:03 -04:00
|
|
|
(cons "servlet" (servlet-handler servlet-dir "/servlet/")))
|
2002-10-21 04:24:58 -04:00
|
|
|
(rooted-file-or-directory-handler htdocs-dir)))))))))))
|
|
|
|
))
|
2002-09-20 15:23:17 -04:00
|
|
|
))
|
|
|
|
;; EOF
|
|
|
|
|
|
|
|
;;; Local Variables:
|
|
|
|
;;; mode:scheme
|
|
|
|
;;; End:
|