Skip to content

Commit f66ae34

Browse files
div8cnDaanHoogland
andauthored
Fix Usage failed to get pid (#4144)
* Update UsageManagerImpl.java When System.getProperty Failure to get the PID will cause the service to stay in the config phase. The startup cannot continue and there will be no log output Use managementfactory to get the PID and throw an exception when the PID cannot be obtained. * Update usage/src/main/java/com/cloud/usage/UsageManagerImpl.java Co-authored-by: dahn <daan.hoogland@gmail.com> * Update UsageManagerImpl.java * Update UsageManagerImpl.java * Update UsageManagerImpl.java Co-authored-by: dahn <daan.hoogland@gmail.com>
1 parent c1fb6b4 commit f66ae34

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

usage/src/main/java/com/cloud/usage/UsageManagerImpl.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,14 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
278278
s_logger.error("Unhandled exception configuring UsageManger", e);
279279
throw new ConfigurationException("Unhandled exception configuring UsageManager " + e.toString());
280280
}
281-
_pid = Integer.parseInt(System.getProperty("pid"));
281+
282+
try {
283+
_pid = (int) ProcessHandle.current().pid();
284+
} catch (Exception e) {
285+
String msg = String.format("Unable to get process Id for %s!", e.toString());
286+
s_logger.debug(msg);
287+
throw new ConfigurationException(msg);
288+
}
282289
return true;
283290
}
284291

0 commit comments

Comments
 (0)