Skip to content

Commit 9f53cc6

Browse files
authored
Safer bootstrapping (#76)
1 parent e4ab945 commit 9f53cc6

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

beyla/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ FROM ghcr.io/coroot/coroot-node-agent:1.27.0 AS node-agent
55
FROM ghcr.io/coroot/coroot-cluster-agent:1.2.4 AS cluster-agent
66

77
# Add Beyla to the image
8-
FROM grafana/beyla:2.7.5 AS beyla-source
8+
FROM grafana/beyla:2.7.7 AS beyla-source
99

1010
# Final stage - Using Debian 12.11-slim for glibc compatibility with node-agent
1111
FROM debian:12.11-slim

collector/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ RUN mkdir -p /versions/0-default \
3333
# Set environment variables
3434
ENV BASE_URL=https://telemetry.betterstack.com
3535
ENV CLUSTER_COLLECTOR=false
36-
ENV COLLECTOR_VERSION=1.1.0
36+
ENV COLLECTOR_VERSION=1.1.1
3737
ENV VECTOR_VERSION=0.47.0
3838
ENV BEYLA_VERSION=2.7.5
3939
ENV CLUSTER_AGENT_VERSION=1.2.4

collector/bootstrap.sh

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,29 @@ log_info "BASE_URL: $BASE_URL"
5454
# Check if already bootstrapped
5555
MANIFEST_DIR="/var/lib/better-stack"
5656
BOOTSTRAPPED_FILE="$MANIFEST_DIR/bootstrapped.txt"
57+
BEYLA_UNPROVISIONED_FILE="$MANIFEST_DIR/beyla-unprovisioned.txt"
5758

59+
# sanity check: if bootstrap is restarted and bootstrap marker is found, it's likely supervisor restart failed
60+
# perhaps a bad supervisord.conf file was sent - in any case, re-attempt bootstrapping on latest manifest
5861
if [ -f "$BOOTSTRAPPED_FILE" ]; then
59-
log_info "Bootstrap already completed (found $BOOTSTRAPPED_FILE)"
60-
log_info "Bootstrapped on: $(cat "$BOOTSTRAPPED_FILE")"
61-
log_info "Exiting without changes."
62-
exit 0
62+
log_info "Bootstrap marker found (bootstrapped on: $(cat "$BOOTSTRAPPED_FILE"))"
63+
64+
# Verify bootstrap actually succeeded by checking if updater process exists
65+
log_info "Verifying bootstrap integrity..."
66+
if supervisorctl status | grep -q "updater"; then
67+
log_info "Bootstrap verified successfully (updater process found)"
68+
log_info "Exiting without changes."
69+
exit 0
70+
else
71+
log_warn "Bootstrap marker exists but updater process not found!"
72+
log_warn "Bootstrap may have failed previously. Re-bootstrapping..."
73+
74+
# Remove markers to allow re-bootstrap
75+
rm -f "$BOOTSTRAPPED_FILE"
76+
rm -f "$BEYLA_UNPROVISIONED_FILE"
77+
78+
log_info "Removed bootstrap markers, proceeding with bootstrap..."
79+
fi
6380
fi
6481

6582
# Function to make API request with error handling
@@ -106,6 +123,8 @@ log_info "Fetching latest manifest version..."
106123
LATEST_MANIFEST_URL="$BASE_URL/api/collector/latest-manifest?collector_secret=$(printf %s "$COLLECTOR_SECRET" | jq -sRr @uri)"
107124

108125
TEMP_VERSION_FILE=$(mktemp)
126+
127+
# shellcheck disable=SC2064
109128
trap "rm -f $TEMP_VERSION_FILE" EXIT
110129

111130
if ! make_api_request "$LATEST_MANIFEST_URL" "$TEMP_VERSION_FILE"; then
@@ -207,15 +226,41 @@ log_info "Manifest version: $MANIFEST_VERSION"
207226
log_info "Files downloaded: $FILES_COUNT"
208227
log_info "Location: $MANIFEST_DIR"
209228

229+
# Wait for Beyla supervisor socket (up to 30 seconds)
230+
BEYLA_SOCKET="/var/lib/better-stack/beyla-supervisor.sock"
231+
WAIT_SECONDS=30
232+
BEYLA_SOCKET_EXISTS=false
233+
234+
log_info "Waiting up to ${WAIT_SECONDS}s for Beyla supervisor socket..."
235+
for i in $(seq 1 $WAIT_SECONDS); do
236+
if [ -S "$BEYLA_SOCKET" ]; then
237+
log_info "Beyla supervisor socket found after ${i}s"
238+
BEYLA_SOCKET_EXISTS=true
239+
break
240+
fi
241+
sleep 1
242+
done
243+
244+
if [ "$BEYLA_SOCKET_EXISTS" = true ]; then
245+
# Socket exists - reload Beyla supervisor
246+
log_info "Reloading Beyla supervisor configuration..."
247+
supervisorctl -s unix://"$BEYLA_SOCKET" reread
248+
supervisorctl -s unix://"$BEYLA_SOCKET" update
249+
else
250+
# Socket not found - mark as unprovisioned
251+
log_warn "Beyla supervisor socket not found after ${WAIT_SECONDS}s"
252+
log_warn "Marking Beyla as unprovisioned"
253+
date > "$BEYLA_UNPROVISIONED_FILE"
254+
log_info "Beyla unprovisioned marker written to: $BEYLA_UNPROVISIONED_FILE"
255+
fi
256+
210257
# Mark bootstrap as completed
258+
# XXX: it may still fail on supervisorctl commands, but if it does, the integrity check will re-bootstrap
211259
date > "$BOOTSTRAPPED_FILE"
212260
log_info "Bootstrap marker written to: $BOOTSTRAPPED_FILE"
213261

214-
# same thing for Beyla container
215-
supervisorctl -s unix:///var/lib/better-stack/beyla-supervisor.sock reread
216-
supervisorctl -s unix:///var/lib/better-stack/beyla-supervisor.sock update
217-
218262
# reload supervisord config and start processes as indicated by new config (overwriting bootstrap config)
263+
log_info "Reloading local supervisor configuration..."
219264
supervisorctl reread
220265
supervisorctl update
221266

0 commit comments

Comments
 (0)