if (pidLine == null) {
throw new ConfigurationException("Java process is being started twice. If this is not true, remove " + pidFile.getAbsolutePath());
}
try {
final long pid = Long.parseLong(pidLine);
final Script script = new Script("bash", 120000, s_logger);
script.add("-c", "ps -p " + pid);
final String result = script.execute();
if (result == null) {
throw new ConfigurationException("Java process is being started twice. If this is not true, remove " + pidFile.getAbsolutePath());
}
if (!pidFile.delete()) {
throw new ConfigurationException("Java process is being started twice. If this is not true, remove " + pidFile.getAbsolutePath());
}
if (!pidFile.createNewFile()) {
throw new ConfigurationException("Java process is being started twice. If this is not true, remove " + pidFile.getAbsolutePath());
}
} catch (final NumberFormatException e) {
throw new ConfigurationException("Java process is being started twice. If this is not true, remove " + pidFile.getAbsolutePath());
}
}
pidFile.deleteOnExit();
final Script script = new Script("bash", 120000, s_logger);
script.add("-c", "echo $PPID");
final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
script.execute(parser);
final String pid = parser.getLine();
final FileOutputStream strm = new FileOutputStream(pidFile);
strm.write((pid + "\n").getBytes());