Sd_notify () from Java

I have a Java service (implemented using Dropwizard ) that I run from a user instance of systemd . So far, so good. Now, I would like to use the systemd notification functions to find out about the status of the service (accessible as a function of the C library or shell script , but ultimately both methods communicate with the socket referenced by the environment variable). I can run arbitrary code when the service has finished launch, but I'm not sure how best to notify systemd from Java.

Other developers run this service on Windows, so it would be very useful for bonus points if my notification code was restrained and did not cause any exit if I did not work with systemd.

+6
source share
1 answer

I found this implementation that uses system interceptors, but at least does not require JNA / JNI.

https://gist.github.com/yrro/18dc22513f1001d0ec8d

As you say, systemd uses the sockets referenced by the environment variable (System.getenv ("NOTIFY_SOCKET" in the code), so I would suggest that there might also be a way to use the Java Socket, although I would imagine that it would take a lot of research and / or trial and error.

+2
source

Source: https://habr.com/ru/post/1207833/


All Articles