Created
January 16, 2026 15:51
-
-
Save Phury/da214fc333e3412ca96bedc6811e10fa to your computer and use it in GitHub Desktop.
Process executor to check if HSM is available via the enquiry command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import lombok.extern.slf4j.Slf4j; | |
| import org.springframework.beans.factory.annotation.Value; | |
| import org.springframework.stereotype.Service; | |
| import java.io.BufferedReader; | |
| import java.io.IOException; | |
| import java.io.InputStreamReader; | |
| /** | |
| * Executes the "enquiry" command to check availability of the HSM security module. | |
| */ | |
| @Slf4j | |
| @Service | |
| public class EnquiryCommand { | |
| @Value("/opt/appnam/nfast/bin/enquiry") | |
| private String enquiryCommand; | |
| public boolean execute() { | |
| if (enquiryCommand == null || enquiryCommand.trim().isEmpty()) { | |
| throw new IllegalArgumentException("enquiry command for hsm cannot be null. Check property: enquiryCommand"); | |
| } | |
| log.debug("executing nfast command: " + enquiryCommand); | |
| ProcessBuilder processBuilder = new ProcessBuilder(); | |
| processBuilder.command(enquiryCommand); | |
| try { | |
| Process process = processBuilder.start(); | |
| process.getOutputStream().close(); | |
| try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { | |
| String line; | |
| while ((line = reader.readLine()) != null) { | |
| log.debug(line); | |
| if (line.contains("mode") && line.contains("operational")) { | |
| return true; | |
| } | |
| } | |
| } | |
| int exitCode = process.waitFor(); | |
| if (exitCode != 0) { | |
| log.error("nfast enquiry command failed with exit code: " + exitCode); | |
| } | |
| } catch (IOException | InterruptedException e) { | |
| log.error("An exception occurred on nfast enquiry command", e); | |
| } | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment