Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ COPY gotty-service /usr/local/bin/gotty-service
RUN chmod +x /usr/local/bin/gotty-service

COPY entrypoint.sh /docker/entrypoint.sh
COPY if-wait.sh /docker/if-wait.sh

# Start nginx in foreground (pass CMD to docker entrypoint.sh):
CMD ["/usr/sbin/nginx", "-g", "daemon off;"]
Expand Down
4 changes: 4 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#!/bin/sh

sh /docker/if-wait.sh

ifup -a
#########
# create directories for ssh host keys
Expand Down
54 changes: 54 additions & 0 deletions if-wait.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh

# Validate CLAB_INTFS environment variable
REQUIRED_INTFS_NUM=${CLAB_INTFS:-0}
if ! echo "$REQUIRED_INTFS_NUM" | grep -qE '^[0-9]+$' || [ "$REQUIRED_INTFS_NUM" -eq 0 ]; then
echo "Warning: CLAB_INTFS not set or invalid, skipping interface wait"
REQUIRED_INTFS_NUM=0
fi

SLEEP=0
TIMEOUT=300 # 5 minute timeout
WAIT_TIME=0

int_calc() {
if [ ! -d "/sys/class/net/" ]; then
echo "Error: /sys/class/net/ not accessible"
AVAIL_INTFS_NUM=0
return 1
fi

# More comprehensive interface pattern including common container interfaces
AVAIL_INTFS_NUM=$(ls -1 /sys/class/net/ 2>/dev/null | grep -cE '^(eth[1-9]|et[0-9]|ens|eno|enp|e[1-9]|net[0-9])')
return 0
}

# Only wait for interfaces if CLAB_INTFS is set
if [ "$REQUIRED_INTFS_NUM" -gt 0 ]; then
echo "Waiting for $REQUIRED_INTFS_NUM interfaces to be connected (timeout: ${TIMEOUT}s)"

while [ "$WAIT_TIME" -lt "$TIMEOUT" ]; do
if ! int_calc; then
echo "Failed to check interfaces, continuing..."
break
fi

if [ "$AVAIL_INTFS_NUM" -ge "$REQUIRED_INTFS_NUM" ]; then
echo "Found $AVAIL_INTFS_NUM interfaces (required: $REQUIRED_INTFS_NUM)"
break
fi

echo "Connected $AVAIL_INTFS_NUM interfaces out of $REQUIRED_INTFS_NUM (waited ${WAIT_TIME}s)"
sleep 1
WAIT_TIME=$((WAIT_TIME + 1))
done

if [ "$WAIT_TIME" -ge "$TIMEOUT" ]; then
echo "Warning: Timeout reached, proceeding with $AVAIL_INTFS_NUM interfaces"
fi
fi

if [ "$SLEEP" -ne 0 ]; then
echo "Sleeping $SLEEP seconds before boot"
sleep $SLEEP
fi