Commit 7e89d7a8 authored by Mihai Bazon's avatar Mihai Bazon

updated doc

parent 8d73a7e4
A tool to daemonize a Lisp process without the need for screen/detachtty.
All is SBCL-specific.
All is SBCL-specific and Linux-only (should work on any POSIX in fact).
Most of the meat in this package comes from restas-daemon [1] which is
copyright Moskvitin Andrey <archimag@gmail.com> and distributed under the
......@@ -8,9 +8,9 @@ LGPL.
[1] https://github.com/archimag/restas/blob/master/contrib/restas-daemon.lisp
Exports two functions:
* API - it exports two functions:
(daemonize &key out err stop pid)
** (daemonize &key out err stop pid)
Detach from the current terminal and run as a daemon. Redirects
standard output and standard error to `out' and `err' (which default to
......@@ -29,14 +29,18 @@ Exports two functions:
- SIGUSR1 -- call restart-process.
(restart-process)
** (restart-process)
Restarts the current process. The way this is handled, it pushes a
function to *exit-hooks* that does the following:
- stop swank
- stop swank (yes, this assumes that SWANK is running... some cleanup
would be in order I guess)
- terminate all threads except the running one
- close any open files (XXX: the way this is done is a bit brute)
- execve itself, passing the same arguments and environment.
Then it sends SIGTERM to our own PID. So this is the workflow: process
......@@ -47,3 +51,30 @@ Exports two functions:
There are chances that the exit hook that removes the PID file doesn't
get executed, but that's okay because the file will be overwritten as we
restart.
* Practical usage
The main thread still needs to do something even if you call (daemonize).
Otherwise, if the main thread exits, then the process terminates. I do it
like this:
(defparameter *finished* nil)
(daemonize :out "output.log"
:err "error.log"
:pid "my.pid"
:stop (lambda (&rest args)
(declare (ignore args))
(setf *finished* t)))
(start-web-server)
(loop :do
(sleep 1)
(when *finished*
(stop-web-server)
(sb-ext:quit)))
The only safe thing we can do in a signal handler is set a flag, so that's
what `stop' does. The main thread periodically checks for that flag and
stops the process with `sb-ext:quit'.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment