import java.net.HttpURLConnection; import java.net.URI; /** Compiled in the build stage; works in a JRE without curl, shell parsing or extra packages. */ public class Healthcheck { public static void main(String[] args) { try { String port = System.getenv().getOrDefault("APP_PORT", "8080"); HttpURLConnection connection = (HttpURLConnection) URI.create( "http://127.0.0.1:" + port + "/health/ready").toURL().openConnection(); connection.setConnectTimeout(1000); connection.setReadTimeout(1000); int status = connection.getResponseCode(); connection.disconnect(); System.exit(status == 200 ? 0 : 1); } catch (Exception exception) { System.exit(1); } } }