#!/bin/sh echo "Loading..." 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" "$@" !# (define-structure servlet-server (export main ; sh jump entry point server) ; scsh entry point (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 "Usage: start-web-server [-h htdocs-dir] [-s servlet-dir] [-p port] [-l log-file-name] [-r requests] [--help] with htdocs-dir directory of html files (default: ./web-server/root/htdocs) servlet-dir directory of servlet files (default: ./web-server/root/servlets) port port server is listening to (default: 8080) log-file-name directory where to store the logfile in CLF (default: ./web-server/httpd.log) 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) ; (define cgi-bin-dir #f) (define port #f) (define log-file-name #f) (define root #f) (define servlet-dir #f) (define simultaneous-requests #f) (define (init) (set! htdocs-dir "./web-server/root/htdocs") ; (set! cgi-bin-dir "./web-server/root/cgi-bin") (set! port "8088") (set! log-file-name "./web-server/httpd.log") (set! root "./web-server/root") (set! servlet-dir "./web-server/root/servlets") (set! simultaneous-requests "5")) (define (normalize-options) (set! htdocs-dir (absolute-file-name htdocs-dir)) (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))) (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) (normalize-options) (cond ((string=? (car options) "-h") (if (null? (cdr options)) (missing-argument-error (car options)) (set! htdocs-dir (cadr options))) (loop (cddr options))) ((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))))))))) (define (server . args) (if (pair? args) (main `(main ,@(car args))) (main '(main)))) (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 servlet-dir: ~a 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 servlet-dir port log-file-name simultaneous-requests) (httpd (with-port port (with-root-directory (cwd) (with-simultaneous-requests simultaneous-requests (with-syslog? #t (with-logfile log-file-name (with-request-handler (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)) (cons "servlet" (servlet-handler servlet-dir))) (rooted-file-or-directory-handler htdocs-dir)))))))))) )) ;; EOF ;;; Local Variables: ;;; mode:scheme ;;; End: