fukamachi / clack

Web server abstraction layer for Common Lisp
MIT License
1.05k stars 86 forks source link

How you deploy clack? #88

Closed EuAndreh closed 6 years ago

EuAndreh commented 9 years ago

What's your setup for deploying clack apps?

I'm writing an app and can't figure out how to deploy it, and I need just a few tips. Any help?

eudoxia0 commented 9 years ago

I would recommend using supervisor to keep the Lisp image running on, say, port 8000; and Nginx acting as a reverse proxy with something like the following configuration:

server {
   listen 80;

   location / {
     proxy_pass http://0.0.0.0:8000;

     charset utf-8;
   }
}
ghost commented 9 years ago

I personally just use something like this in a screen session:

sbcl --eval '(ql:quickload :my-app)' --eval '(my-app:start :port 12345)'

and Apache to ProxyPass to it:

ServerName example.com
ProxyPass / http://localhost:12345

From there its just a small bit of work to write a shell script to act as an init daemon and auto start on boot.

fukamachi commented 9 years ago

The way to deploy a web application is not established yet. Though I write the latest method I'm using for my company, it could be changed in the future.

First of all, I use Roswell to install SBCL on servers. It provides a command ros to invoke SBCL.

And I wrote a Roswell script bin/clackup which calls clack:clackup for app.lisp. The app.lisp must be a Common Lisp file which returns a Clack app at the end.

You can use the script like this:

$ cd /path/to/project
$ APP_ENV=production clackup app.lisp --server hunchentoot --port 9090 --debug nil

Usually, I use the command with Qlot for fixing versions of libraries. Qlot also provides a shell script named qlot.

$ cd /path/to/project
$ qlot install
$ APP_ENV=production qlot exec clackup app.lisp --server hunchentoot --port 9090 --debug nil

I don't recommend to run the server on 80 port directly because some servers (ex. Hunchentoot) are weak for DoS attack and Slowloris attack. Using nginx as a reverse proxy for it would be better. You can serve static files from it and it reduces the load of your app server.

If you'd like hot-deployment, a certain tool to do it like Server::Starter would help.

And make sure that your application will be restarted if the process dies unexpectedly with a process monitor tool like daemontools or supervisor.

fukamachi commented 9 years ago

If you'd like to deploy without Roswell, you can run it by a one-liner as ghost is saying.

One thing you should know is threading. It starts a new thread if the SBCL supports threads and the process ends right away. Use :use-thread nil option for the situation.

eudoxia0 commented 8 years ago

Also, is it possible to clackup to 0.0.0.0 instead of localhost?

fukamachi commented 8 years ago

It depends on which handler you choose. Currently, Woo is the only one which accepts :address keyword and it can be specified at --address from clackup command. 0.0.0.0 is the default value, though.

eudoxia0 commented 8 years ago

Cool, thanks.

Kevinizevbigie commented 2 years ago

I am curious @fukamachi, how has your deployment process changed over the years for CL apps? Your bin/clackup link is broken. Thanks.