A Lisp Daemon


I’ve been fid­dling with Sacraspot lately and I dis­cov­ered that the tech­nique I’ve been using to dae­mo­nize the server and inte­grate it into my init-en­vi­ron­ment was­n’t work­ing prop­er­ly. This is a lisp appli­ca­tion which I was run­ning with start-stop-­dae­mon. The prob­lem was that for some rea­son, start-stop-­dae­mon was fail­ing to fully dae­mo­nize the appli­ca­tion. The Repl seemed to con­flict with start-stop-­dae­mon’s abil­ity to do this prop­erly and while it would look like it worked at first, once one closed the shell which lisp was started from, the lisp process would close.

For­tu­nate­ly, this is a solved prob­lem in Com­mon Lisp, even though I don’t fully under­stand the cause and the solu­tion, of course, is to use detachtty.1

Any­way, I ended up chang­ing the initscript from this:

start-stop-daemon --start --exec /usr/bin/sbcl \
   --pidfile /path/to/pid -m -b \
   --user sacraspot \
   --chdir /path/to/sacraspot \
   --progress \
   -- --core sacraspot.core --eval "(in-package #:sacraspot)" \
                            --eval "(initialize)" \
                            --eval "(startup)"

To this:

start-stop-daemon --start --exec /usr/bin/detachtty \
   --user sacraspot \
   --chdir /path/to/sacraspot \
   --progress \
   -- --dribble-file sacraspot.dribble \
      --log-file messages \
      --pid-file /path/to/pid \
      /tmp/sacraspot.socket \
      /usr/bin/sbcl --core sacraspot.core --eval "(in-package #:sacraspot)" \
                                          --eval "(initialize)" \
                                          --eval "(startup)"

This seems to work. It does­n’t pro­vide any spe­cial abil­ity to attach or detach from the process like other solu­tions I’ve seen but it inte­grates per­fectly with the init setup. I use swank to attach and detach sep­a­rately so I think I’ve got that well under­hand.

  1. dtach might also work, and might be more appropriate in my situation, but I haven’t used detachtty before so this was a learning opportunity. 

Last update: 31/10/2011

blog comments powered by Disqus