<p>we have a batch data processing script inside a container and want to check it is alive and actually working or whether it should be restarted.</p>
<p>It is PHP command line script and doesn't expose any kind of server. Currently running in Docker soon in Kubernetes.</p>
<p>How can we monitor liveness of such script without introducing unnecessary features/libraries?</p>

Jindra
<p>You can use liveness probe <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-liveness-command" rel="nofollow noreferrer">command</a> to check whether process is alive or not.  Below the sample from k8s documentation. You can write small script to return 0 if process is alive or return non zero code in case of process is dead</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-exec
spec:
  containers:
  - name: liveness
    image: k8s.gcr.io/busybox
    args:
    - /bin/sh
    - -c
    - touch /tmp/healthy; sleep 30; rm -f /tmp/healthy; sleep 600
    livenessProbe:
      exec:
        command:
        - cat
        - /tmp/healthy
      initialDelaySeconds: 5
      periodSeconds: 5
</code></pre>
