balena-io-modules / open-balena-base

16 stars 12 forks source link

No useful logs going to stdout/stderr #333

Open shaunco opened 7 months ago

shaunco commented 7 months ago

As previously reported in https://github.com/balena-io/open-balena/issues/99 the only log that gets spit out to stdout/stderr is

Systemd init system enabled.

This is the case in Kubernetes and Docker for all the open-balena-* services... which makes capturing logs quite difficult in production, especially when the container is constantly restarting.

aslansutu commented 2 months ago

The VPN, API, Registry, and S3 containers all seem to have the same entrypoint /usr/bin/entry.sh. The script could benefit from a more detailed logs in case of errors. Maybe something like the following;

#!/bin/bash
set -m

GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color

# Function to print error message
print_error() {
    echo -e "${RED}Error: $1${NC}"
}

# Function to handle cleanup
cleanup() {
    # Add cleanup tasks here
    exit 1
}

# Trap error signals and call cleanup function
trap 'print_error "Script encountered an error"; cleanup' ERR

echo -e "${GREEN}Systemd init system enabled."

# systemd causes a POLLHUP for console FD to occur
# on startup once all other processes have stopped.
# We need this sleep to ensure this doesn't occur, else
# logging to the console will not work.
sleep infinity &

# Example command that may fail
# Uncomment to test error handling
#non_existent_command

for var in $(compgen -e); do
    printf '%q=%q\n' "$var" "${!var}"
done > /etc/docker.env

exec /sbin/init