使用 ASDF 启动 Hunchentoot
我正在使用 Hunchentoot(在 SBCL 和 Linux 上)开发一个 Web 应用程序,通常我只是从 Emacs (SLIME) 运行它,但对于部署,我想要更容易自动化的东西。 所以我试图找出 ASDF,因为这似乎是现在每个人都在使用的。
myapp.asd:
(in-package #:asdf)
(defsystem :myapp
:name "my app"
:depends-on ("hunchentoot")
:components ((:file "package")
(:file "server" :depends-on ("package"))))
package.lisp:
(defpackage myapp
(:use :cl))
server.lisp:
(setq hunchentoot:*dispatch-table*
(list (hunchentoot:create-static-file-dispatcher-and-handler "/foo" "foo")))
(hunchentoot:start-server :port 8705)
如果我尝试手动加载它:
$ sbcl
* (require 'asdf)
* (asdf:operate 'asdf:load-op 'myapp)
它会加载并编译一大堆函数,但然后就停止了。 Hunchentoot 未运行,并且提示不接受输入。 我不知道它认为自己处于什么状态:打印的最后几行是:
STYLE-WARNING: Implicitly creating new generic function STRINGIFY-COOKIE.
STYLE-WARNING: Implicitly creating new generic function DISPATCH-REQUEST.
STYLE-WARNING: Implicitly creating new generic function WRITE-HEADER-LINE.
有办法让这个工作吗? (坦白说:我真的不太理解 ASDF 或 Common Lisp 包,尽管我花了很多时间阅读它们。)
I'm working on a web app using Hunchentoot (on SBCL and Linux), and usually I just run it from Emacs (SLIME), but for deployment I want something that's easier to automate. So I'm trying to figure out ASDF, because that seems to be what everybody's using these days.
myapp.asd:
(in-package #:asdf)
(defsystem :myapp
:name "my app"
:depends-on ("hunchentoot")
:components ((:file "package")
(:file "server" :depends-on ("package"))))
package.lisp:
(defpackage myapp
(:use :cl))
server.lisp:
(setq hunchentoot:*dispatch-table*
(list (hunchentoot:create-static-file-dispatcher-and-handler "/foo" "foo")))
(hunchentoot:start-server :port 8705)
If I try loading it by hand:
$ sbcl
* (require 'asdf)
* (asdf:operate 'asdf:load-op 'myapp)
it loads and compiles a whole bunch of functions, but then just stops. Hunchentoot isn't running, and the prompt doesn't accept input. I don't know what state it thinks it's in: the last lines printed are:
STYLE-WARNING: Implicitly creating new generic function STRINGIFY-COOKIE.
STYLE-WARNING: Implicitly creating new generic function DISPATCH-REQUEST.
STYLE-WARNING: Implicitly creating new generic function WRITE-HEADER-LINE.
Is there a way to make this work? (Confession: I really don't understand ASDF or Common Lisp packages very well at all, despite many hours of reading about them.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
从命令行运行 Lisp 应用程序
许多(不是全部)Lisp 实现都支持保存映像(或保存世界或转储)机制,该机制将封装代码体并在启动时运行函数。 正如另一位发帖者所说,这些机制是特定于平台和供应商的。
大多数 Lisp 实现(全部?)都有一个命令行界面。 因此,部署 Lisp 应用程序的传统方法是围绕 Lisp 封装 shell 脚本。 该脚本必须设置程序环境并传递命令行参数。 通常,运行时上下文包括要加载的应用程序文件(通过 ASD 或 LOAD-FILE)以及要评估的一个或多个表单或要运行的函数。
使用/扩展 clbuild
您可以推出自己的脚本,也可以重复使用某些现有技术。 看一下 clbuild ,它很有用,有几个原因。 (有关 clbuild 功能和可移植性的更多信息,请参阅下文。)
您可以扩展 clbuild 以使用命令行参数运行您自己的应用程序。 例如,要加载“myapps”系统并运行函数“myapp1:start”,您可以按如下方式调用 clbuild:
注意括号的字符转义语法; 这是大多数命令解释器所需要的。
另一种方法是重定向文件中的标准输入。 例如:
clbuild 功能和可移植性
clbuild 最常用于安装和运行开源 CommonLisp 库。
它是一个 bash 脚本,因此具有很高的可移植性。 下载工具依赖于 CVS、Subversion、darcs、git 和 Mercurial 等程序。
默认情况下,clbuild 运行 sbcl,但很容易将其配置为运行另一个 Lisp,例如(无耻插件) Clozure CL (ccl)。 将
clbuild.conf.default
复制到clbuild.conf
并编辑clbuild.conf
以指向您要使用的 Lisp 可执行文件。Running Lisp applications from command line
Many (not all) Lisp implementations support a save-image (or save-world or dump) mechanism that will encapsulate a body of code and run functions at startup. As another poster said, these mechanisms are platform- and vendor-specific.
Most Lisp implementations (all?) have a command-line interface. So a conventional approach to deploying a Lisp application is to wrap a shell script around Lisp. The script must set up the program environment and pass command line arguments. Typically the runtime context includes application files to load (via ASD or LOAD-FILE) and one or more forms to evaluate or functions to run.
Using / extending clbuild
You can roll your own script, or you can re-use some existing technology. Take a look at clbuild which is useful for several reasons. (See below for more about clbuild functionality and portability.)
You can extend clbuild to run your own application with command line arguments. For example, to load the "myapps" system and run the function "myapp1:start" you would invoke clbuild as follows:
Note the character escape syntax for parentheses; this is needed for most command interpreters.
An alternative approach is to redirect standard input from a file. For example:
clbuild functionality and portability
clbuild is most commonly used to install and run open source CommonLisp libraries.
It is a bash script, so it is highly portable. The download facility relies on programs like CVS, Subversion, darcs, git, and Mercurial.
By default clbuild runs sbcl but it is very easy to configure it to run another Lisp such as (shameless plug) Clozure CL (ccl). Copy
clbuild.conf.default
toclbuild.conf
and editclbuild.conf
to point to the Lisp executable you want to use.您的示例适用于我,至少修改为与当前的 Hunchentoot 1.0.0 一起使用,但这只是将
(hunchentoot:start-server :port 8705)
更改为(hunchentoot:start ( make-instance 'hunchentoot:acceptor:端口 8705))
。无论如何,虽然可能,但您实际上不应该从 ASDF 加载的文件内部运行某些内容。 它的作用类似于构建系统,我不认为使用
make
启动网络服务器是很常见的......有关部署,请参阅 cl-launch, sbcl 命令行选项,特别是
--eval
,或保存图像。Your example works for me, at least modified to work with current Hunchentoot 1.0.0, but that is merely change of
(hunchentoot:start-server :port 8705)
to(hunchentoot:start (make-instance 'hunchentoot:acceptor :port 8705))
.In any case, while possible, you are not really supposed to run things from inside files loaded by ASDF. It serves a role analogous to a build system, and I don't think having
make
launch a webserver is exactly common...For deployment see cl-launch, sbcl command-line options, in particular
--eval
, or saving an image.我所做的就是创建一个文件,为我的 Web 应用程序加载 ASDF 系统定义,然后启动 Hunchentoot,并按应有的方式设置所有内容。 然后使用 sbcl --load start-stuff 运行。
What I do is to have a file that loads the ASDF system definition for my web application, then starts Hunchentoot with everything set up as it should be. This is then run with sbcl --load start-stuff.
请看这里:http://xach.livejournal.com/278047.html
我是我自己是新手,扎克·比恩 (Zach Beane) 的这篇博文将拼图碎片放在了适当的位置。
他解释了如何使用 ASDF 启动一个小项目、将什么放在哪里、如何尝试以及如何将其构建为二进制文件。 很棒的底漆。
阅读完后,您将在 .asd 中使用“:serial t”,将启动 Hunchentoot 移至函数,在 REPL 中尝试并为您的应用程序构建二进制文件。
Take a look here: http://xach.livejournal.com/278047.html
I am a novice myself and this blog post of Zach Beane puts puzzle pieces in places.
He explains how to start a small project with ASDF, what to put where, how to try it and how to build it as a binary. Great primer.
After reading that you'll use ":serial t" in .asd, move starting Hunchentoot to a function, try it in REPL and build a binary for your application.
我知道的甚至比你还少,但这个链接似乎相关: http ://common-lisp.net/pipermail/tbnl-devel/2008-November/004455.html。 显然,在 SLIME 中运行它(某种程度上)并不是一个糟糕的主意。 通过谷歌搜索“部署 hunchentoot”发现。
I know even less than you, but this link seems relevant: http://common-lisp.net/pipermail/tbnl-devel/2008-November/004455.html. Apparently just running it in SLIME (sort of) isn't such a terrible idea after all. Found by googling for "deploying hunchentoot".
您应该避免将任何逻辑放入 asd 文件中。 您可以将它们视为简单的 makefile。 您需要的是一种保存 lisp 图像的方法,该图像将在启动时启动您的服务器实例。
这是依赖于平台的,你需要搜索你的 Lisp 实现文档。
You should avoid putting any logic in asd files. You can treat them as simlple makefiles. What you need is a way to save lisp image which will start your server instance on startup.
This is platform dependent, to you will need to search your lisp implementation documentation.