This is just a bit of code I end up copying through-out my projects. This projects bring one macro and one function of interest.
Pull-in the following dependency:
[spootnik/signal "0.2.5"]
The main signatures:
(on-signal signal handler)
: Execute handler (a function of one argument, the signal keyword).(with-handler signal & body)
: Handle signal by calling the body of forms supplied.
A few additional signatures may come in handy:
(->signal signal)
: Convert a signal keyword or string to asun.misc.Signal
instance.(signal->number signal)
: Show the number for a signal.(signal->kw signal)
: Convert asun.misc.Signal
instance to a keyword.(->handler f)
: Convert a function of one argument to asun.misc.SignalHandler
instance.
Here's one way of hooking this up with a component system:
(with-handler :term
(info "caught SIGTERM, quitting.")
(alter-var-root #'system component/stop-system)
(System/exit 0))
(with-handler :hup
(info "caught SIGHUP, reloading.")
(alter-var-root #'system (comp component/start-system component/stop-system)))
Copyright © 2016 Pierre-Yves Ritschard pyr@spootnik.org