[tbnl-devel] tbnl as unix daemon

Tolstoy tolstoy at zentrope.com
Mon Jan 30 21:18:20 UTC 2006


Well, I solved this one.  Not saying it's the best solution, but it goes
something like:

(defvar *waiter* (make-waitqueue))
(defvar *locker* (make-mutex))

(defun unix-signals (sig code scp)
  (declare (ignorable code scp))
  (handler-case
      (condition-notify *waiter*)
    (condition (c)
      (format *standard-output* "~a" c)))
  (sb-ext::quit))

(defun daemon-mode-start ()
  (load-sample-data)
  (sb-sys:enable-interrupt sb-unix:sighup #'unix-signals)
  (sb-sys:enable-interrupt sb-unix:sigterm #'unix-signals)
  (sb-sys:enable-interrupt sb-unix:sigkill #'unix-signals)
  (tbnl:start-tbnl)
  (with-mutex (*locker*)
    (log-message :debug "wait mode")
    (condition-wait *waiter* *locker*)
    (log-message :debug "terminated.")
    (tbnl:stop-tbnl)
    (sb-ext::quit)))

*Shrug*.  Good enough for now! ;)

Keith

On Mon, 2006-01-30 at 12:17 -0800, Keith Irwin wrote:
> Folks--
> 
> I want to be able to start/stop a tbnl based app via a script.  I've
> done this before with my own server apps, so it all seems relatively
> straight forward.  In other words, I have a Makefile which builds a
> core, copies shared-libs, packages it all up in a tarball, etc, etc,
> such that I can deploy the app on any machine, regardless of whether
> or not SBCL is installed.
> 
> The problem is that (start-tbnl) starts up a thread, then returns, and
> with that return, sbcl quits, and I got no daemon.
> 
> Is there a way to start tbnl without it returning?
> 
> I suppose I can do something like:
> 
> (defun daemon-start ()
>   (tbnl:start-tbnl)
>   (wait-forever))
> 
> and then let my init.d script send a kill signal as I've already
> planned.  Is that the recommended method (assuming I can find a
> wait-forever function, or just (read) or something)?
> 
> In case it needs be said, I really value running tbnl inside a repl
> with slime and all that, but this is for the case where that's not
> desired or necessary.
> 
> Thanks for any lore about what you all do in a similar case! ;)
> 
> Keith
> _______________________________________________
> tbnl-devel site list
> tbnl-devel at common-lisp.net
> http://common-lisp.net/mailman/listinfo/tbnl-devel




More information about the Tbnl-devel mailing list