Lib for java daemons to send keep-alive messages to refresh the systemd watchdog timestamp using the native interface. Or you can use this project to do it using the /usr/bin/systemd-notify utility.
Use the version 1.1 build artifact.
<groupId>org.tricorder</groupId>
<artifactId>java-sysd-notify-watchdog</artifactId>
<version>1.1</version>
SysDNotifier() notifier = new SysDNotifier();
notifier.start();
SysDNotifier notifier = new SysDNotifier();
notifier.setAuditor(new Auditor() {
@Override
public boolean allGood() {
//Do more extensive internal checking of the process, if ok, return true.
//Returning false will have the effect of suppressing the keep-alive
//message, causing systemd to kill and restart the process.
return true;
}
});
notifier.start();
[Unit]
Description=My Service
[Service]
#PIDFile=/tmp/my-service.pid
Environment=LD_PRELOAD=/usr/lib64/libsystemd-daemon.so
ExecStart=/usr/lib/jvm/java-1.8.0/bin/java -jar /usr/local/bin/my-service.jar
WatchdogSec=500
Restart=on-failure
[Install]
WantedBy=multi-user.target