Running Clojure app under systemd
How do you deploy your Clojure applications, and how do you keep them running? In most recent and relevant Linux distributions, systemd is the default init system, so the easiest thing to do is create a systemd service to start your application as a service. You can find examples of that for the services running on my box hosting matthiasnehlsen.com and all of the related live examples in this repo.
Supervision by systemd
With systemd, there's the concept of the watchdog. An application needs to issue
sd_notify commands every so often, otherwise it's killed and restarted.
For more on the subject, I recommend this
blog post by Lennart Poettering,
one of systemd's original authors.
This library facilitates the required calls to systemd via JNA,
using the SDNotify library, but only if
NOTIFY_SOCKET environment variable is set. Otherwise, nothing happens, thus
there's no harm even if you're on an entirely different platform during development.
Import the library:
(:require [matthiasn.systemd-watchdog.core :as wd])
Start the watchdog notifier:
You can have a look at my live examples, these are all supervised by systemd now.
The service files for all these projects are in the conf
repo, have a look at the watchdog configuration there, for example in
birdwatch.service or in
You can call the
start-watchdog! function in any kind of REPL-driven workflow
as often as you want, it's not going to do anything unless the
environment variable is set.
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.