Skip to content

Commit

Permalink
elasticsearch shutdown code issue resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
rakesh-jain committed Oct 6, 2024
1 parent 218a613 commit fb932f9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,26 +143,15 @@ private void createIndex(ElasticsearchClient client, String indexName) {
}
}

private void shutDownElasticsearch() {
//shut down for linux system (optional)
@Override
public void closeStorage(final ParameterOptions params) throws IOException {
try {
String[] command = {"sh", "-c", "sudo systemctl stop elasticsearch"};
Process process = Runtime.getRuntime().exec(command);
int exitCode = process.waitFor();

if (exitCode == 0) {
Printer.log.info("Elasticsearch shut down successfully.");
} else {
Printer.log.info("Failed to shut down Elasticsearch.");
}
} catch (IOException | InterruptedException e) {
elasticsearchClient._transport().close();
} catch (ElasticsearchException e) {
e.printStackTrace();
Printer.log.error("Failed to close the connection");
}
}

@Override
public void closeStorage(final ParameterOptions params) throws IOException {
shutDownElasticsearch();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,5 @@ public String read() throws IOException {

@Override
public void close() throws IOException {
shutDownElasticsearch();
}

private void shutDownElasticsearch() {
try {
String[] command = {"sh", "-c", "sudo systemctl stop elasticsearch"};
Process process = Runtime.getRuntime().exec(command);
int exitCode = process.waitFor();

if (exitCode == 0) {
Printer.log.info("Elasticsearch shut down successfully.");
} else {
Printer.log.info("Failed to shut down Elasticsearch.");
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public void sync() throws IOException {

@Override
public void close() throws IOException {
shutDownElasticsearch();
}


Expand All @@ -72,21 +71,4 @@ private void writeData(String data) {
throw new RuntimeException(ex);
}
}

private void shutDownElasticsearch() {
try {
String[] command = {"sh", "-c", "sudo systemctl stop elasticsearch"};
Process process = Runtime.getRuntime().exec(command);
int exitCode = process.waitFor();

if (exitCode == 0) {
System.out.println("Elasticsearch shut down successfully.");
} else {
System.out.println("Failed to shut down Elasticsearch.");
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}

}

0 comments on commit fb932f9

Please sign in to comment.