Recently, I found out something by creating stand-alone executable files for web applications, and wrote about it in lisp-trip / web-dev (sections on delivery and deployment), as well as on the assembly part in Common Lisp Cookbook / scripting # for web applications .
I copy the interesting parts here, there is a little more on each resource. Editing is welcome, especially on these resources, thanks!
change July 2019 I added the page to the cookbook: https://lispcookbook.imtqy.com/cl-cookbook/web.html
: . , CL: https://github.com/CodyReichert/awesome-cl#deployment
https://github.com/CodyReichert/awesome-cl#interfaces-to-other-package-managers Homebrew Debian.
SBCL
() (.
Buildapp Rowsell). SBCL,
,
:
(sb-ext:save-lisp-and-die #P"path/name-of-executable" :toplevel #'my-app:main-function :executable t)
sb-ext SBCL .
SBCL
( ).
:executable t ,
. ,
Lisp, . ,
, .
Slime, :
.
SBCL.
, Quicklisp. :
- , Quicklisp Lisp (
Quicklisp)
load .asd- .
:
(load "my-app.asd")
(ql:quickload :my-app)
(sb-ext:save-lisp-and-die
Makefile --load --eval:
build:
sbcl --non-interactive \
--load my-app.asd \
--eval '(ql:quickload :my-app)' \
--eval "(sb-ext:save-lisp-and-die #p\"my-app\" :toplevel #my-app:main :executable t)"
ASDF
, , .
3.1, ASDF . make,
.asd. .asd:
:build-operation "program-op" ;; leave as is
:build-pathname "<binary-name>"
:entry-point "<my-system:main-function>"
asdf:make :my-system.
, Makefile:
LISP ?= sbcl
build:
$(LISP) --non-interactive \
--load my-app.asd \
--eval '(ql:quickload :my-app)' \
--eval '(asdf:make :my-system)'
Roswell Buildapp
,
, ros build,
.
Roswell ros install
my-app. .
Buildapp,
- SBCL CCL,
Common Lisp ".
(,
pgloader),
Debian: apt install buildapp, asdf: make Roswell.
-
-.
, -
:
$ ./my-web-app
Hunchentoot server is started.
Listening on localhost:9003.
, -, ,
VPS
.
, ,
- . main
- :
(defun main ()
(start-app :port 9003) ;; our start-app, for example clack:clack-up
;; let the webserver run.
;; warning: hardcoded "hunchentoot".
(handler-case (bt:join-thread (find-if (lambda (th)
(search "hunchentoot" (bt:thread-name th)))
(bt:all-threads)))
;; Catch a user C-c
(#+sbcl sb-sys:interactive-interrupt
#+ccl ccl:interrupt-signal-condition
#+clisp system::simple-interrupt-condition
#+ecl ext:interactive-interrupt
#+allegro excl:interrupt-signal
() (progn
(format *error-output* "Aborting.~&")
(clack:stop *server*)
(uiop:quit)))
(error (c) (format t "Woops, an unknown error occured:~&~a~&" c))))
bordeaux-threads ((ql:quickload
"bordeaux-threads"), bt) uiop, ASDF,
, (uiop:quit,
sb-ext:quit).
. .
. - .
Heroku
.
, ,
, .
GNU/Linux Systemd.
:
, :
[Unit]
Description=stupid simple example
[Service]
WorkingDirectory=/path/to/your/app
ExecStart=/usr/local/bin/sthg sthg
Type=simple
Restart=always
RestartSec=10
:
sudo systemctl start my-app.service
:
systemctl status my-app.service
Systemd ( stdout stderr, ):
journalctl -f -u my-app.service
, :
Restart=always
:
[Install]
WantedBy=basic.target
:
sudo systemctl enable my-app.service
SBCL: sure_space: n
SBCL :
mmap: wanted 1040384 bytes at 0x20000000, actually mapped at 0x715fa2145000
ensure_space: failed to allocate 1040384 bytes at 0x20000000
(hint: Try "ulimit -a"; maybe you should increase memory limits.)
ASLR:
sudo bash -c "echo 0 > /proc/sys/kernel/randomize_va_space"
Swank
: http://cvberry.com/tech_writings/howtos/remotely_modifying_a_running_program_using_swank.html.
, :
;; a little common lisp swank demo
;; while this program is running, you can connect to it from another terminal or machine
;; and change the definition of doprint to print something else out!
;; (ql:quickload :swank)
;; (ql:quickload :bordeaux-threads)
(require :swank)
(require :bordeaux-threads)
(defparameter *counter* 0)
(defun dostuff ()
(format t "hello world ~a!~%" *counter*))
(defun runner ()
(bt:make-thread (lambda ()
(swank:create-server :port 4006)))
(format t "we are past go!~%")
(loop while t do
(sleep 5)
(dostuff)
(incf *counter*)
))
(runner)
sbcl --load demo.lisp
:
ssh -L4006:127.0.0.1:4006 username@example.com
4006 example.com
4006 (Swanks
).
M-x slime-connect
4006.
:
(defun dostuff ()
(format t "goodbye world ~a!~%" *counter*))
(setf *counter* 0)
, , M-x slime-eval-region, . .
CV Berry .
Quickutil. .
( fabfile
). fab update git pull
, , .
swank, ,
.
, , Docker
https://lispcookbook.imtqy.com/cl-cookbook/testing.html#continuous-integration