<p>I have a microservice that is not a webservice.  </p>

<p>It is a Spring Boot (1.5) CommandLineRunner app that does not have a need to expose an API or do anything with http.</p>

<p>However, I need to give it a liveness probe for Kubernetes.</p>

<p>Can this be accomplished without refactoring it into a webservice app?</p>

<p>I have this configuration added to enable Spring's info endpoint</p>

<pre><code>management:
  endpoint:
    health:
      enabled: true
    info:
      enabled: true

# https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready-endpoints
info:
  app:
    name: foo-parser
    description: parses binary files from S3 and updates the database
</code></pre>

<p>I implemented this health check class</p>

<pre><code>import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health.Builder;

@Component
public class HealthCheck extends AbstractHealthIndicator {

  Logger log = LoggerFactory.getLogger("jsonLogger");

  private final MySQLAccessor mySQLAccessor;
  private static final String FOO_TABLE = "foo";

  @Autowired
  public HealthCheck(final MySQLAccessor mySQLAccessor) {
    this.mySQLAccessor = mySQLAccessor;
  }

  @Override
  protected void doHealthCheck(Builder builder) throws Exception {
    boolean result = mySQLAccessor.healthCheck(FOO_TABLE);
    if (result) {
      log.info("HELLO! the health check is good!");
      builder.up().withDetail("test", "good");
    }
    else {
      log.info("HELLO! OH NOES the health check is ungood!");
      builder.down().withDetail("test", "bad");
    }
  }
}


</code></pre>

<p>Can this idea work?  Or do I have to refactor it to serve web requests?</p>

<p>Thank you for any clues</p>

<p>you can expose actuator endpoint details including the healthcheck using JMX.</p>

<p>example <code>application.yml</code></p>

<pre><code>management:
  endpoints:
    jmx:
      exposure:
        include: health,info,metrics,mappings
</code></pre>

<p>Then define the liveness probe to run a script (or java program) to call the JMX endpoint and answer the healthcheck:</p>

<p>example k8s config</p>

<pre><code>apiVersion: v1
kind: Pod
spec:
  containers:
  - name: liveness
    image: my-app 
    livenessProbe:
      exec:
        command:
        - /bin/sh
        - test_app_with_jmx.sh 
      initialDelaySeconds: 5
      periodSeconds: 5
</code></pre>
