Ubuntu 12.04でCommon Lispやるよ!
Common Lisp / Caveman2でルーティングにアノテーション使う
の続き、番外編です。
Common Lispでシェルを便利に!「Shelly」をリリースしました – 八発白中
Shellyの新しい使い方を紹介します – 八発白中
Shellyのインストール
echo '(ql:quickload :shelly) (shelly:install)' | sbcl
エラー発生
[package shelly.util].;
; compilation aborted because of fatal error:
; Symbol "EXIT" not found in the SB-EXT package.
;
; Line: 106, Column: 21, File-Position: 3700
;
; Stream: #<SB-SYS:FD-STREAM
; for "file /path/to/quicklisp/dists/quicklisp/software/shelly-20131211-git/src/util.lisp"
; {10093BBD13}>
;
“Symbol “EXIT” not found in the SB-EXT package.”で検索してみる。
ロングタイムアゴーにシンボル sb-ext::exit は sb-ext::quit に変更されてるだよとかいってる。
エラーに
「for “file /path/to/quicklisp/dists/quicklisp/software/shelly-20131211-git/src/util.lisp”」と出ているのでファイル見てみる。
$ vim /path/to/quicklisp/dists/quicklisp/software/shelly-20131211-git/src/util.lisp
103 @export
104 (defun terminate (&optional (status 0))
105 #+ccl (ccl:quit status)
106 #+sbcl (sb-ext:exit :code status)
107 #+allegro (excl:exit status :quiet t)
108 #+clisp (ext:quit status)
109 #+cmucl (unix:unix-exit status)
110 #+ecl (ext:quit status)
111 #-(or ccl sbcl allegro clisp cmucl ecl) (cl-user::quit))
んー、106行目のsb-ext:exitをsb-ext:quitに変更したら動きそうじゃね?ってことで変更して再度インストール実行。
$ echo '(ql:quickload :shelly) (shelly:install)' | sbcl
This is SBCL 1.0.55.0.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
* To load "shelly":
Load 1 ASDF system:
shelly
; Loading "shelly"
..................................................
[package shelly.util].............................
[package shelly.impl].............................
[package shelly.install]..........................
[package shelly.error]............................
[package shelly.core].............................
[package shelly].
(:SHELLY)
*
Successfully installed!
Add this to your shell rc file (".bashrc", ".zshrc" and so on).
PATH=$HOME/.shelly/bin:$PATH
Successfully installed!
ちょっと適当な対応すぎて恐縮ですが、、、まだ試行錯誤&学習中ってことで御勘弁ください。永遠の試行錯誤ですけど。
実行環境毎に分けているのでそれぞれ違うもののようですが、、バージョンの問題だろうか。
Macに入れた「SBCL 1.1.16」だとエラーでなかった記憶。「SBCL 1.0.55.0.debian」だとこの問題発生(?)
$ vim ~/.bash_profile
PATH=$HOME/.shelly/bin:$PATH
$ source ~/.bash_profile
$ shly --version
Shelly ver 0.5.8
よい。
$ cd ~/commonlisp/myapp
$ APP_ENV=development shly -Lclack clackup app.lisp --server :fcgi --port 8080
; Fetching #<URL "http://beta.quicklisp.org/archive/cl-fastcgi/2013-11-11/cl-fastcgi-20131111-git.tgz">
; 3.71KB
==================================================
.3,800 bytes in 0.01 seconds (337.36KB/sec)
; Loading "cl-fastcgi"
................................................
[package cl-fastcgi];
; compilation unit aborted
; caught 1 fatal ERROR condition
Error: Unable to load any of the alternatives:
(CL-FASTCGI::PATH "libfcgi.so")
unhandled SB-INT:SIMPLE-PROGRAM-ERROR in thread #:
unknown &KEY argument: :CODE
0: (SB-DEBUG::MAP-BACKTRACE
#
:START
0
:COUNT
128)
1: (SB-DEBUG:BACKTRACE
128
#)
2: (SB-DEBUG::DEBUGGER-DISABLED-HOOK
#
#)
3: (SB-DEBUG::RUN-HOOK
SB-EXT:*INVOKE-DEBUGGER-HOOK*
#)
4: (INVOKE-DEBUGGER
#)
5: (ERROR
SB-INT:SIMPLE-PROGRAM-ERROR
:FORMAT-CONTROL
"unknown &KEY argument: ~S"
:FORMAT-ARGUMENTS
(:CODE))
6: (SB-KERNEL::UNKNOWN-KEY-ARG-ERROR-HANDLER
#
#.(SB-SYS:INT-SAP #X7FFFF6B475A0)
#
(597))
7: (SB-KERNEL:INTERNAL-ERROR
#.(SB-SYS:INT-SAP #X7FFFF6B46FC0)
#)
8: ("foreign function: call_into_lisp")
9: ("foreign function: funcall2")
10: ("foreign function: interrupt_internal_error")
11: ("foreign function: #x41171B")
12: (SB-EXT:QUIT :CODE 1)[:OPTIONAL]
13: (TERMINATE 1)
14: (INTERPRET
("clackup" "app.lisp" "--server" ":fcgi" "--port" "8080")
:VERBOSE
NIL)
15: (SB-INT:SIMPLE-EVAL-IN-LEXENV
(INTERPRET (LIST "clackup" "app.lisp" "--server" ":fcgi" "--port" "8080")
:VERBOSE NIL)
#)
16: (EVAL
(INTERPRET (LIST "clackup" "app.lisp" "--server" ":fcgi" "--port" "8080")
:VERBOSE NIL))
17: (SB-IMPL::PROCESS-EVAL/LOAD-OPTIONS
((:EVAL . "(shelly.util::check-version \"0.5.8\")")
(:EVAL . "(shelly.util::load-systems (list :clack) :verbose nil)")
(:EVAL . "(shelly.util::load-global-shlyfile)")
(:EVAL . "(shelly.util::load-local-shlyfile)")
(:EVAL
. "(shelly.core::interpret (list \"clackup\" \"app.lisp\" \"--server\" \":fcgi\" \"--port\" \"8080\") :verbose nil)")
(:EVAL . "(swank-backend:quit-lisp)")))
18: (SB-IMPL::TOPLEVEL-INIT)
19: ((FLET #:WITHOUT-INTERRUPTS-BODY-235615 :IN SB-EXT:SAVE-LISP-AND-DIE))
20: ((LABELS SB-IMPL::RESTART-LISP :IN SB-EXT:SAVE-LISP-AND-DIE))
unhandled condition in --disable-debugger mode, quitting
惜しい。libfcgiはいってなかったのでいれる。
$ sudo apt-get install libfcgi
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libfcgi0ldbl' instead of 'libfcgi'
The following NEW packages will be installed:
libfcgi0ldbl
0 upgraded, 1 newly installed, 0 to remove and 65 not upgraded.
Need to get 283 kB of archives.
After this operation, 670 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ precise/universe libfcgi0ldbl amd64 2.4.0-8.1 [283 kB]
Fetched 283 kB in 1s (153 kB/s)
Selecting previously unselected package libfcgi0ldbl.
(Reading database ... 37645 files and directories currently installed.)
Unpacking libfcgi0ldbl (from .../libfcgi0ldbl_2.4.0-8.1_amd64.deb) ...
Setting up libfcgi0ldbl (2.4.0-8.1) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
まただめ。
そうだ、libfcgi-dev必要。
$ sudo apt-get install libfcgi-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
libfcgi-dev
0 upgraded, 1 newly installed, 0 to remove and 64 not upgraded.
Need to get 37.2 kB of archives.
After this operation, 161 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ precise/universe libfcgi-dev amd64 2.4.0-8.1 [37.2 kB]
Fetched 37.2 kB in 0s (37.4 kB/s)
Selecting previously unselected package libfcgi-dev.
(Reading database ... 38761 files and directories currently installed.)
Unpacking libfcgi-dev (from .../libfcgi-dev_2.4.0-8.1_amd64.deb) ...
Setting up libfcgi-dev (2.4.0-8.1) ...
$ APP_ENV=development shly -Lclack clackup app.lisp --server :fcgi --port 8080
(略)
To load "myapp":
Load 1 ASDF system:
myapp
; Loading "myapp"
To load "clack-handler-fcgi":
Load 1 ASDF system:
clack-handler-fcgi
; Loading "clack-handler-fcgi"
Fcgi server is started.
Listening on localhost:8080.
#<CLACK.HANDLER:<HANDLER> {10080AB203}>
動いたー。あ、ここまでやっておいてなんだけど別に今fcgiで動かしたいわけではなかった。
$ APP_ENV=development shly -Lclack clackup app.lisp --server :hunchentoot --port 8080
(略)
To load "myapp":
Load 1 ASDF system:
myapp
; Loading "myapp"
To load "clack-handler-hunchentoot":
Load 1 ASDF system:
clack-handler-hunchentoot
; Loading "clack-handler-hunchentoot"
.
Hunchentoot server is started.
Listening on localhost:8080.
#<CLACK.HANDLER:<HANDLER> {1007158D23}>
http://localhost:8080/
よし。いいですね。これでらくちん。
この投稿の最初で紹介したページ
Shellyの新しい使い方を紹介します – 八発白中
をこの段階で読んだ。気がついた。スケルトン作成時にプロジェクト直下に作られる「shlyfile.lisp」あるの知ってた。
気がつかないふりしてた。
$ vim shlyfile.lisp
;; -*- mode: common-lisp -*-
(ql:quickload '(:myapp :split-sequence))
(import 'split-sequence:split-sequence)
#+sbcl(setf sb-impl::*default-external-format* :utf-8)
#+sbcl(setf sb-alien::*default-c-string-external-format* :utf-8)
(defun start (&key (port 8080)
;(server :fcgi)
(server :hunchentoot)
(debug nil))
(flet ((start (&rest args)
(apply #'myapp:start
:debug debug :server server args)))
(let ((server-starter-port (asdf::getenv "SERVER_STARTER_PORT")))
(if server-starter-port
(destructuring-bind (port fd)
(split-sequence #\=
(car (split-sequence #\; server-starter-port :count 1)))
(start :port (parse-integer port)
:fd (parse-integer fd)))
(start :port port)))))
(server)だけ :hunchentootにかえて
$ shly start
で起動するー!シンプルらくちんかんたん!