vindarel / lisp-journey

Discovering the Common Lisp ecosystem. https://lisp-journey.gitlab.io/
2 stars 0 forks source link

blog/lisp-for-the-web-deploy-with-systemd/ #31

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Lisp for the web: deploying with Systemd, gotchas and solutions - Lisp journey

How do you run your Common Lisp (web) application on your server? Nowadays most GNU/Linux distros have Systemd. I recently used it more, with a mix of applications running from source, from a binary, running locally or on my VPS. I had to bypass a few gotchas, so let’s recap’ what you need to know.Also stay tuned: next, we’ll see how to build a standalone binary for your Common Lisp application with Deploy (so that we handle foreign libraries like libssl), how to include your Djula HTML templates as well as your static assets.

https://lisp-journey.gitlab.io/blog/lisp-for-the-web-deploy-with-systemd/

vindarel commented 1 year ago

Discussed, with a good addition: https://www.reddit.com/r/lisp/comments/xetci2/lisp_for_the_web_deploying_with_systemd_gotchas/


here are a few things that are different in my setup:

I have After=network.target in my .service file to set up the service start and stop order, i.e., the Lisp app starts after the networking stack is up and the Lisp app is stopped before the networking stack goes down.

I do have User=www-data in my .service file. The article too makes a note of the User= option towards the end. This option is critically important to me to ensure that the service is not running with root privileges to minimize the damage that can occur should a vulnerability be found in the service.

I did not seem to need the --disable-debugger option to make the service crash on error. Even without this option, the service crashes and restarts automatically in 5 seconds which I believe is due to the fact that the StandardInput option is null by default in Systemd.

To keep the app in foreground, I simply have (sleep most-positive-fixnum) at the end of form.lisp. While a bt:join-thread call would be the most ideal, I am happy with my (sleep most-positive-fixnum) solution because most-positive-fixnum is 4611686018427387903 on my implementation, so this setup is good for 146 billion years.

I install Quicklisp to /opt/quicklisp/ with (quicklisp-quickstart:install :path "/opt/quicklisp/") (see make setup link above) and load it with the --load /opt/quicklisp/setup.lisp arguments (see form.service link above).

Here is the source code to my setup if anyone is interested: https://github.com/susam/susam.net/blob/a052d7e/etc/form.service