common-lispweb-deploymentsbclasdfhunchentoot

Common Lisp Executable doesn't do anything


I have followed all the steps in the cl-cookbook. I created a webapp project with quickprojects.

I have my .asd file:


(asdf:defsystem #:serve
  :description "Describe server here"
  :author "Your Name <your.name@example.com>"
  :license  "Specify license here"
  :version "0.0.1"
  :serial t
  :depends-on (#:hunchentoot)
  :components ((:file "package")
               (:file "serve"))
  :build-operation "program-op" ;; leave as is
  :build-pathname "serve"
  :entry-point "serve:main")


I have the lisp server file:

(ql:quickload "serve")
(in-package #:serve)


(defvar *acceptor* (make-instance 'hunchentoot:easy-acceptor :port 4242
                  :document-root #p"www/"))


;; start the server
(defun main ()
  (hunchentoot:start *acceptor*))

(setf (hunchentoot:acceptor-document-root *acceptor*) #p"./www/")

I have the package.lisp file:


(defpackage #:serve
  (:use #:cl)
  (:export main))

Finally, I have the make file for creating the executable:


build:
        sbcl \
         --eval '(load "serve.asd")' \
         --eval '(ql:quickload "serve")' \
         --eval "(asdf:make :serve)" \
         --eval '(quit)'

When the executable comes out after running make build, and I run it with ./serve.... nothing happens.

My expectation is that the server will run as it does when i run it with emacs.

My goal is to send the executable to the server to run it. Not sure if that is the best deploy process. But at the moment, it's good enough for testing.

Even more worrying is that when I send the executable to my ubuntu server, i get a zsh error. This only happens when I build it on my MacOs and send it to ubuntu. However, when I build on ubuntu (i rebuilt the project on the VM to test it), the executable does nothing.


Solution

  • Your main problem is that your main function immediately returns, terminating the server as soon as it is started. I would change it as follows:

    ;; start the server
    (defun main ()
      (hunchentoot:start *acceptor*)
      (sb-impl::toplevel-init))
    

    When you rebuild and run ./serve, a simple prompt appears *, which is the SBCL REPL. Your webserver is running in another thread. This can be useful to query the state of the server, or debug. You can even start a Swank server to connect and hack the code while it runs. When you want to stop the server, press CTRL-D to exit the REPL and the program terminates.

    You can imagine other mechanisms to keep the server running until everything stops (like joining all threads, etc.) but this should be enough for testing.

    Also,

    (ql:quickload "serve")
    

    This is not required in serve.lisp, the code by itself should not contain invocations to ql:quickload, it is sufficient to do it in the build command.

    Likewise:

    --eval '(load "serve.asd")' \
    

    can be removed if you put your .asd file in a place where quicklisp can find it, see 4.1 Configuring ASDF to find your systems.