
com.pixonic.simplesystemdservice.Systemd Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simple-systemd-service Show documentation
Show all versions of simple-systemd-service Show documentation
Lightweight library to notify systemd when your java service is started
The newest version!
package com.pixonic.simplesystemdservice;
import java.io.IOException;
public class Systemd {
/**
* Call this when your app is started.
*/
public static void sendReady() {
if (System.getenv("NOTIFY_SOCKET") == null) return;
try {
Process process = new ProcessBuilder("systemd-notify", "--ready")
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start();
int exitCode = process.waitFor();
if (exitCode != 0) {
throw new RuntimeException("Can't notify systemd");
}
} catch (IOException | InterruptedException e) {
throw new RuntimeException("Can't notify systemd", e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy