@@ -54,12 +54,29 @@ log_info "BASE_URL: $BASE_URL"
5454# Check if already bootstrapped
5555MANIFEST_DIR=" /var/lib/better-stack"
5656BOOTSTRAPPED_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
5861if [ -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
6380fi
6481
6582# Function to make API request with error handling
@@ -106,6 +123,8 @@ log_info "Fetching latest manifest version..."
106123LATEST_MANIFEST_URL=" $BASE_URL /api/collector/latest-manifest?collector_secret=$( printf %s " $COLLECTOR_SECRET " | jq -sRr @uri) "
107124
108125TEMP_VERSION_FILE=$( mktemp)
126+
127+ # shellcheck disable=SC2064
109128trap " rm -f $TEMP_VERSION_FILE " EXIT
110129
111130if ! make_api_request " $LATEST_MANIFEST_URL " " $TEMP_VERSION_FILE " ; then
@@ -207,15 +226,41 @@ log_info "Manifest version: $MANIFEST_VERSION"
207226log_info " Files downloaded: $FILES_COUNT "
208227log_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
211259date > " $BOOTSTRAPPED_FILE "
212260log_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..."
219264supervisorctl reread
220265supervisorctl update
221266
0 commit comments