probe.sh


Overview

`probe.sh` is a minimalistic shell script designed primarily for use as a Kubernetes probe script within containerized blockchain node deployments. Its core purpose is to keep a container alive indefinitely without performing any active health checks or complex logic. This script acts as a placeholder or baseline liveness/readiness probe, ensuring Kubernetes perceives the pod as healthy and running.

The script achieves this by tailing `/dev/null` indefinitely, effectively blocking the container’s main process from exiting until it receives termination signals. It also handles common termination signals gracefully, allowing Kubernetes to stop the container cleanly during pod shutdown or redeployment.


Script Breakdown and Functionality

Script Content

#!/bin/sh

set -e

trap 'exit' SIGTERM SIGINT

tail -f /dev/null &

wait $!

Explanation of Each Part

Line

Code

Description

1

`#!/bin/sh`

Shebang specifying the script should be executed with `sh` shell interpreter.

3

`set -e`

Enables immediate exit if any command returns a non-zero status, ensuring failure is not ignored.

5

`trap 'exit' SIGTERM SIGINT`

Sets up signal handlers to catch `SIGTERM` and `SIGINT` signals and exit the script cleanly.

7

`tail -f /dev/null &`

Launches a background process that tails an empty stream indefinitely, keeping the script alive.

9

`wait $!`

Waits for the background tail process to finish, which only happens on termination signals.


Detailed Explanation


Usage Example

This script is typically deployed as the container's entrypoint or as a probe command in Kubernetes Pod specifications.

Example Kubernetes Pod Spec Snippet

containers:
  - name: blockchain-node
    image: blockchain/node:latest
    readinessProbe:
      exec:
        command: ["/bin/sh", "/path/to/probe.sh"]
      initialDelaySeconds: 5
      periodSeconds: 10
    livenessProbe:
      exec:
        command: ["/bin/sh", "/path/to/probe.sh"]
      initialDelaySeconds: 15
      periodSeconds: 20

In this configuration:


Important Implementation Details


Interaction with Other System Components


Mermaid Flowchart: Workflow of probe.sh

flowchart TD
    Start[Container Starts] --> SetSignalTrap[Set trap for SIGTERM and SIGINT]
    SetSignalTrap --> StartTail[Tail /dev/null indefinitely in background]
    StartTail --> Wait[Wait for tail process to terminate]
    Wait -->|Receive SIGTERM or SIGINT| Exit[Exit Script]

Summary

`probe.sh` is a simple, robust shell script used as a Kubernetes probe to keep a container alive by tailing an empty file indefinitely. It handles termination signals gracefully, allowing Kubernetes to manage pod lifecycle events cleanly. While it does not perform any active health checking, it provides a reliable baseline probe useful in scenarios where more complex checks are unnecessary or unavailable.


Appendix: Related Scripts and Context