10

I started playing with SBCL Common Lisp and want to develop a small web application using Hunchentoot. For easy deployment I planned to save everything in a binary using sb-ext:save-lisp-and-die as I can live with the big output size.

For the executable you need to supply a toplevel function. The problem is that the program exits when the toplevel function returns. I tried to start Hunchentoot from the executable, but the program ended after two seconds.

How can I wait until Hunchentoot was shut down (from inside a request) before stopping the program? Can I do something like join the Hunchentoot acceptor thread? Or can I even include the REPL into the executable to be able to do live debugging?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Sojaki
  • 187
  • 1
  • 8
  • Did you ever figure out how to deploy your app? I am in the same position now. I wrote a quick app and would like to deploy it. What tools did you use? – MadPhysicist Oct 09 '17 at 01:02
  • 1
    @MadPhysicist I'm taking notes on that on [lisp-journey/web-dev#deployment](https://lisp-journey.gitlab.io/web-dev/#deployment). Just can't say for sure since I couldn't run my app yet because of an sbcl error. – Ehvince Dec 14 '17 at 12:22
  • @Ehvince great! I will keep my eye on it. By the way, I would be curious to get a list of Lisp resources that you have found useful on your Lisp journey. Suggestions for books, online articles, etc. – MadPhysicist Dec 14 '17 at 12:48
  • The resources I found really useful are basically in the Good Resources tab, + CL Recipes by E. Weitz (highly recommended to have a large overview of practical things. Lacks modern tools and libraries though) + reading sources. – Ehvince Dec 14 '17 at 14:02

2 Answers2

4
(ql:quickload :hunchentoot)
(use-package :hunchentoot)

(defun main ()
  (hunchentoot:start-server :port 8082)
  (sb-thread:join-thread (find-if
                          (lambda (th)
                            (string= (sb-thread:thread-name th) "hunchentoot-listener-1"))
                          (sb-thread:list-all-threads))))

No explicit code is required to give you access to a REPL if you keep a terminal open (perhaps via GNU Screen). Send Ctrl+C to the terminal to break into the debugger.

Throw Away Account
  • 2,593
  • 18
  • 21
  • It seems like I am working with a newer version of Hunchentoot. I had to use (hunchentoot:start (make-instance 'hunchentoot:easy-acceptor :port 8080) and the thread was called "hunchentoot-listener-*:8080". Works like a charm. – Sojaki May 24 '15 at 19:14
  • 1
    how about ```(find-if (lambda (th) (search "hunchentoot-listener" (sb-thread:thread-name th))) (sb-thread:list-all-threads))``` for the ```find-if``` part – Peter Slotko Oct 23 '16 at 09:10
1
;;; I simply use sleep to yield the main thread.
;;; To start the server while developing I use
;;; start-server.  For deployment I use the main
;;; function.

(defun start-server ()
  (hunchentoot:start
    (make-instance 'hunchentoot:easy-acceptor :port 8000)))

(defun main()
  (start-server)
  (sleep #xffffffff))

HerrBlume
  • 11
  • 2
  • This might be the best answer, because joining threads can be subject to a race condition. Also `(sleep most-positive-fixnum)`. – Ehvince May 12 '23 at 09:51