我的java应用程序安装在OpenSUSE 13.2操作系统上,我使用systemd进行进程控制.(systemd版本210)
我想使用systemd-notify来利用systemd看门狗功能.但是,我注意到应用程序重新启动是由于看门狗的超时时间不一致.
使用WatchdogSec = 120,并且应用程序配置为每60秒调用systemd-notify,我观察平均每5到20分钟重新启动一次.
这是进程的(略微编辑的)systemd单元文件:
# 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
Run Code Online (Sandbox Code Playgroud)
这是调用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) …Run Code Online (Sandbox Code Playgroud)