All Downloads are FREE. Search and download functionalities are using the official Maven repository.

host.anzo.commons.utils.SystemdUtils Maven / Gradle / Ivy

There is a newer version: 1.29
Show newest version
package host.anzo.commons.utils;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

/**
 * @author ANZO
 * @since 6/30/2023
 */
@Slf4j
public class SystemdUtils {
	public static void notifyReady() {
		notify("--ready");
	}

	public static void setStatus(String status) {
		notify("--status=" + status);
	}

	private static void notify(String param) {
		if (System.getenv("NOTIFY_SOCKET") == null) {
			return;
		}
		try {
			final Process process = new ProcessBuilder("systemd-notify", param)
					.redirectOutput(ProcessBuilder.Redirect.INHERIT)
					.redirectError(ProcessBuilder.Redirect.INHERIT)
					.start();
			final int exitCode = process.waitFor();
			if (exitCode != 0) {
				log.error("Can't notify systemd exitCode={}", exitCode);
			}
		}
		catch (IOException | InterruptedException e) {
			log.error("Can't notify systemd", e);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy