My java application installs on OpenSUSE 13.2, and I use systemd to control the process. (systemd version 210)
I would like to use the watchdog systemd function with systemd-notify. However, I notice that the application is restarting due to inconsistent timeouts from the watchdog.
With WatchdogSec = 120, and the application is configured to call a systemd notification every 60 seconds, I observe reboots every five to twenty minutes on average.
here is the systemd file (slightly edited) for the process:
# Cool systemd service [Unit] Description=Something Awesome After=awesomeparent.service Requires=awesomeparent.service [Service] Type=simple WorkingDirectory=/opt/awesome Environment="AWESOME_HOME=/opt/awesome" User=awesomeuser Restart=always WatchdogSec=120 NotifyAccess=all ExecStart=/home/awesome/jre1.8.0_05/bin/java -jar awesome.jar [Install] WantedBy=multi-user.target
And here is the code to call systemd-notify
String pidStr = ManagementFactory.getRuntimeMXBean().getName(); pidStr = pidStr.split("@")[0]; String cmd = "/usr/bin/systemd-notify"; Process process = new ProcessBuilder(cmd, "MAINPID=" + pidStr, "WATCHDOG=1").redirectErrorStream(true) .start(); int exitCode = 0; if ((exitCode = process.waitFor()) != 0) { String output = IOUtils.toString(process.getInputStream()); Log.MAIN_LOG.error("Failed to notify systemd: " + ((output.isEmpty()) ? "" : " " + output) + " Exit code: " + exitCode); }
I never see error messages in logs (the process always returns 0 exit code), and I am 100% sure that the task is executed once a minute per minute. I see how the task log starts just before rebooting.
Anyone have any ideas why systemd-notify just doesn't work?
I am thinking of writing code to directly call sd_pid_notify, but would like to know if there is a simple configuration that I can do before I go along this route.
source share