in src/main/java/co/elastic/support/util/RemoteSystem.java [202:232]
public void copyLogsFromJournalctl(String serviceName, String targetDir) {
ChannelSftp channelSftp = null;
String tempDir = "templogs";
String mkdir = "mkdir templogs";
String journalctl = "journalctl -u {{SERVICE}} > '{{TEMP}}/{{SERVICE}}.log'";
journalctl = journalctl.replace("{{SERVICE}}", serviceName);
journalctl = journalctl.replace("{{TEMP}}", tempDir);
try {
runCommand(mkdir);
runCommand(journalctl);
// Now they have been moved from the log directory into the temp dir created in the user's home
// we can move them to the the calling host. It should pull them all in one pass.
channelSftp = (ChannelSftp) session.openChannel("sftp");
channelSftp.connect();
channelSftp.get("templogs/*", targetDir);
channelSftp.exit();
// clean up the temp logs on the remote host
runCommand("rm -Rf templogs");
} catch (Exception e) {
logger.info(Constants.CONSOLE, "Error occurred copying remote logfiles. {}", Constants.CHECK_LOG);
logger.error( e);
} finally {
if(channelSftp != null && channelSftp.isConnected()){
channelSftp.disconnect();
}
}
}