From d5a0fbd7ec7928c85c4e2c9fec44a09a1fc42759 Mon Sep 17 00:00:00 2001 From: nmburgan <13688219+nmburgan@users.noreply.github.com> Date: Tue, 30 Dec 2025 20:13:26 -0800 Subject: [PATCH 1/5] Reference Jetty 10 instead of 9 in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a8ed6a3..89cc9ae 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ for each. Here are some additional projects that provide Trapperkeeper services, and other related functionality: -* [trapperkeeper-webserver-jetty9](https://github.com/openvoxproject/trapperkeeper-webserver-jetty9): a Jetty9-based webserver for use with TK applications +* [trapperkeeper-webserver-jetty10](https://github.com/openvoxproject/trapperkeeper-webserver-jetty10): a jetty10-based webserver for use with TK applications * [trapperkeeper-rpc](https://github.com/puppetlabs/trapperkeeper-rpc): a TK service that allows you to easily build a way to call remote TK services over RPC * [trapperkeeper-metrics](https://github.com/openvoxproject/trapperkeeper-metrics): a TK service that manages the life cycle of a [MetricRegistry](https://github.com/dropwizard/metrics), so that all of your TK services can register metrics with a common configuration syntax. * [trapperkeeper-comidi-metrics](https://github.com/openvoxproject/trapperkeeper-comidi-metrics): a TK utility library that provides middleware to automatically generate metrics for all requests to each of your bidi/comidi HTTP routes. From ab29382cc6da7f75a7f536b9d58c768b12627c9c Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Thu, 7 Aug 2025 14:48:41 -0400 Subject: [PATCH 2/5] Add initial systemd lifecycle notification support Code adapted with permission of the original author (this author) from nrepl socket.clj. cf. https://www.freedesktop.org/software/systemd/man/sd_notify.html --- project.clj | 4 ++- src/puppetlabs/trapperkeeper/internal.clj | 40 +++++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/project.clj b/project.clj index d81c156..e187e57 100644 --- a/project.clj +++ b/project.clj @@ -44,7 +44,9 @@ [org.openvoxproject/kitchensink "3.4.2" :exclusions [cheshire]] [org.openvoxproject/i18n] [nrepl/nrepl] - [io.github.clj-kondo/config-slingshot-slingshot "1.0.0"]] + [io.github.clj-kondo/config-slingshot-slingshot "1.0.0"] + + [com.kohlschutter.junixsocket/junixsocket-core "2.10.1" :extension "pom"]] :deploy-repositories [["releases" {:url "https://clojars.org/repo" :username :env/CLOJARS_USERNAME diff --git a/src/puppetlabs/trapperkeeper/internal.clj b/src/puppetlabs/trapperkeeper/internal.clj index d26ef21..f674326 100644 --- a/src/puppetlabs/trapperkeeper/internal.clj +++ b/src/puppetlabs/trapperkeeper/internal.clj @@ -1,6 +1,4 @@ (ns puppetlabs.trapperkeeper.internal - (:import (clojure.lang ExceptionInfo IFn IDeref) - (java.lang ArithmeticException NumberFormatException)) (:require [clojure.tools.logging :as log] [beckon] [plumbing.graph :as graph] @@ -14,7 +12,14 @@ [schema.core :as schema] [clojure.core.async :as async] [clojure.core.async.impl.protocols :as async-prot] - [me.raynes.fs :as fs])) + [me.raynes.fs :as fs]) + (:import + (clojure.lang ExceptionInfo IFn IDeref) + (java.lang ArithmeticException NumberFormatException) + (java.io File) + (java.net DatagramPacket SocketException) + ;; Looks like JDK 16+ support doesn't do SOCK_DGRAM yet + (org.newsclub.net.unix AFUNIXSocketAddress AFUNIXDatagramSocket))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Schemas @@ -28,6 +33,31 @@ ;; Private ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Optional systemd support + +(def systemd-notify-socket (System/getenv "NOTIFY_SOCKET")) + +(defn maybe-notify-systemd [message] + (when systemd-notify-socket + (with-open [s (AFUNIXDatagramSocket/newInstance)] + (let [buf (.getBytes message "UTF-8") + addr (-> systemd-notify-socket File. AFUNIXSocketAddress/of) + connected? (try + (.connect s addr) + true + ;; Doesn't appear to throw ConnectException + ;; for an unmonitored socket. + (catch SocketException _ + (log/warn (i18n/trs "Unable to connect to NOTIFY_SOCKET {0}" + (pr-str systemd-notify-socket))) + nil))] + (when connected? + (.send s (DatagramPacket. buf (count buf)))))))) + +(defn notice-service-ready [] (maybe-notify-systemd "READY=1\n")) +(defn notice-service-reloading [] (maybe-notify-systemd "RELOADING=1\n")) +(defn notice-service-stopping [] (maybe-notify-systemd "STOPPING=1\n")) + ;; This is (eww) a global variable that holds a reference to all of the running ;; Trapperkeeper apps in the process. It can be used when connecting via nrepl ;; to allow you to do useful things, and also may be used for other things @@ -615,11 +645,13 @@ this) (a/start [this] (run-lifecycle-fns app-context s/start "start" ordered-services) + (notice-service-ready) (inc-restart-counter! this) this) (a/stop [this] (a/stop this false)) (a/stop [this throw?] + (notice-service-stopping) (let [errors (shutdown! app-context)] (if (and throw? (seq errors)) (let [msg (i18n/trs "Error during app shutdown!")] @@ -628,10 +660,12 @@ this))) (a/restart [this] (try + (notice-service-reloading) (run-lifecycle-fns app-context s/stop "stop" (reverse ordered-services)) (doseq [svc-id (keys services-by-id)] (swap! app-context assoc-in [:service-contexts svc-id] {})) (run-lifecycle-fns app-context s/init "init" ordered-services) (run-lifecycle-fns app-context s/start "start" ordered-services) + (notice-service-ready) (inc-restart-counter! this) this (catch Throwable t From 4591fdb2a4448a5bd0a808b6854ce6a0bf2ddac2 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Tue, 26 Aug 2025 22:20:55 +0200 Subject: [PATCH 3/5] systemd notify: Avoid reflections, rework to idiomatic clojure --- src/puppetlabs/trapperkeeper/internal.clj | 51 +++++++++++++++-------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/src/puppetlabs/trapperkeeper/internal.clj b/src/puppetlabs/trapperkeeper/internal.clj index f674326..ab377da 100644 --- a/src/puppetlabs/trapperkeeper/internal.clj +++ b/src/puppetlabs/trapperkeeper/internal.clj @@ -19,8 +19,27 @@ (java.io File) (java.net DatagramPacket SocketException) ;; Looks like JDK 16+ support doesn't do SOCK_DGRAM yet - (org.newsclub.net.unix AFUNIXSocketAddress AFUNIXDatagramSocket))) - + (org.newsclub.net.unix AFUNIXSocketAddress AFUNIXDatagramSocket) + (java.nio.charset StandardCharsets))) + +;; helper functions to resolve unknown type references +;; this feels cleaner compared to type hints, but I've no idea what I'm doing +;; - bastelfreak 2025-08-26 +(defn utf8-bytes + "Convert a String to a UTF-8 byte array." + [^String s] + (.getBytes s StandardCharsets/UTF_8)) + +(defn socket-addr + "Convert a String path to a reflection-free AFUNIXSocketAddress." + [^String path] + (AFUNIXSocketAddress/of (File. path))) + +(defn send-packet! + "Send a UTF-8 message via a connected AFUNIXDatagramSocket." + [^AFUNIXDatagramSocket s ^String msg] + (let [^bytes buf (utf8-bytes msg)] + (.send s (DatagramPacket. buf (alength buf))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Schemas ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -37,22 +56,18 @@ (def systemd-notify-socket (System/getenv "NOTIFY_SOCKET")) -(defn maybe-notify-systemd [message] - (when systemd-notify-socket - (with-open [s (AFUNIXDatagramSocket/newInstance)] - (let [buf (.getBytes message "UTF-8") - addr (-> systemd-notify-socket File. AFUNIXSocketAddress/of) - connected? (try - (.connect s addr) - true - ;; Doesn't appear to throw ConnectException - ;; for an unmonitored socket. - (catch SocketException _ - (log/warn (i18n/trs "Unable to connect to NOTIFY_SOCKET {0}" - (pr-str systemd-notify-socket))) - nil))] - (when connected? - (.send s (DatagramPacket. buf (count buf)))))))) +(defn maybe-notify-systemd + "Send a message to systemd NOTIFY_SOCKET if available." + [^String message] + (when-let [^String socket-path systemd-notify-socket] + (let [^AFUNIXSocketAddress addr (socket-addr socket-path)] + (with-open [^AFUNIXDatagramSocket s (AFUNIXDatagramSocket/newInstance)] + (try + (.connect s addr) + (send-packet! s message) + (catch SocketException _ + (log/warn (i18n/trs "Unable to connect to NOTIFY_SOCKET {0}" + (pr-str socket-path))))))))) (defn notice-service-ready [] (maybe-notify-systemd "READY=1\n")) (defn notice-service-reloading [] (maybe-notify-systemd "RELOADING=1\n")) From ff43aae07adac9aa6cb07071817ce563b5de11ec Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Wed, 27 Aug 2025 15:05:01 +0200 Subject: [PATCH 4/5] order import statement before requirements --- src/puppetlabs/trapperkeeper/internal.clj | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/puppetlabs/trapperkeeper/internal.clj b/src/puppetlabs/trapperkeeper/internal.clj index ab377da..38dfb64 100644 --- a/src/puppetlabs/trapperkeeper/internal.clj +++ b/src/puppetlabs/trapperkeeper/internal.clj @@ -1,4 +1,13 @@ (ns puppetlabs.trapperkeeper.internal + (:import + (clojure.lang ExceptionInfo IFn IDeref) + (java.lang ArithmeticException NumberFormatException) + (java.io File) + (java.net DatagramPacket SocketException) + ;; Looks like JDK 16+ support doesn't do SOCK_DGRAM yet + (org.newsclub.net.unix AFUNIXSocketAddress AFUNIXDatagramSocket) + (java.nio.charset StandardCharsets)) + (:require [clojure.tools.logging :as log] [beckon] [plumbing.graph :as graph] @@ -12,15 +21,7 @@ [schema.core :as schema] [clojure.core.async :as async] [clojure.core.async.impl.protocols :as async-prot] - [me.raynes.fs :as fs]) - (:import - (clojure.lang ExceptionInfo IFn IDeref) - (java.lang ArithmeticException NumberFormatException) - (java.io File) - (java.net DatagramPacket SocketException) - ;; Looks like JDK 16+ support doesn't do SOCK_DGRAM yet - (org.newsclub.net.unix AFUNIXSocketAddress AFUNIXDatagramSocket) - (java.nio.charset StandardCharsets))) + [me.raynes.fs :as fs])) ;; helper functions to resolve unknown type references ;; this feels cleaner compared to type hints, but I've no idea what I'm doing From 8675a6e6d584730ee13ad9a1758029a445795853 Mon Sep 17 00:00:00 2001 From: Sebastian Rakel Date: Fri, 29 Aug 2025 11:12:38 +0200 Subject: [PATCH 5/5] Update line to ignore eastwood reflection fault --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index e187e57..5635f06 100644 --- a/project.clj +++ b/project.clj @@ -76,7 +76,7 @@ [org.openvoxproject/i18n "0.9.3"]] :eastwood {:ignored-faults {:reflection {puppetlabs.trapperkeeper.logging [{:line 92}] - puppetlabs.trapperkeeper.internal [{:line 128}] + puppetlabs.trapperkeeper.internal [{:line 174}] puppetlabs.trapperkeeper.testutils.logging true puppetlabs.trapperkeeper.testutils.logging-test true puppetlabs.trapperkeeper.services.nrepl.nrepl-service-test true