I want to check the status of a service running on linux. On machine i use the command "systemctl is-active service-name" to check the status of services.And it gives the output as active/inactive(when service is running/not running).
I want to get the status of the service in java. how i do that?
I tried this..
String SERVER_STATUS = new String[]{SUDO_COMMAND, "systemctl is-active vpnd.service"};
try {
final Process process = new ProcessBuilder(SERVER_STATUS).start();
process.waitFor();
InputStream in = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line = null;
System.out.println("status: " + br.readLine());
} catch (IOException | InterruptedException e) {}
But br.readLine()
is coming as null.