How to keep a Kubernetes pod running when main process is not blocking? How to keep a Kubernetes pod running when main process is not blocking? kubernetes kubernetes

How to keep a Kubernetes pod running when main process is not blocking?


You need to use a custom CMD script that keeps staying in foreground after the postfix start command.

For instance, you can use this one, took from here:

#!/bin/bash# Wait before postfix is really started.function get_state {    echo $(script -c 'postfix status' | grep postfix/postfix-script)}postfix startecho $(get_state)while true; do    state=$(get_state)    if [[ "$state" != "${state/is running/}" ]]; then        PID=${state//[^0-9]/}        if [[ -z $PID ]]; then            continue        fi        if [[ ! -d "/proc/$PID" ]]; then            echo "Postfix proces $PID does not exist."            break        fi    else        echo "Postfix is not running."        break    fidone

This script keeps running a while loop until the postfix process is up, and it exits when the process exits. This way you'll have your container correctly stop if postfix dies for any reason.


Since Postfix 3.3 (2018), you can run postfix in the foreground (blocking). You could use command:

postfix startfg

More about dockerizing postfix here (answer also extracted from that link).