Skip to content

Commit bddc6d9

Browse files
committed
FEATURE: Adds multiple hooks on startup
This allows for more specific scripting at the start of a pod, the order of operations is now: - syslog init - set env - setup user_profile, igbinary, blackfire - run beach-hook-initialize (as an early hook) - doctrine migrate, resource publish, cache warmup - run startup script (old) + beach-hook-warmup - enable user services - fpm + supervisor init/conf - supervisor start - crawler starts (haven't changed order for now) - sshd, metrics, cron started - supervisor status check - run beach-hook-ready (here fpm should be up) - write .warmupdone - run beach-hook-live
1 parent 5842ac3 commit bddc6d9

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

root-files/entrypoint.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ if [[ "$*" = *"run"* ]]; then
6262
set +o errexit
6363
supervisorctl status 2>&1 | (sed 's/^/Supervisor: /' | output)
6464
set -o errexit
65+
66+
beach_startup_complete
67+
6568
info "Entrypoint: Start up complete"
6669
# We can't use "wait" because supervisord is not a direct child of this shell:
6770
while [ -e "/proc/${supervisor_pid}" ]; do sleep 1.1; done

root-files/opt/flownative/lib/beach.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,24 @@ beach_run_custom_startup() {
206206
"${BEACH_APPLICATION_PATH}/beach-startup.sh" 2>&1 | (sed 's/^/Beach: (flow) /' | output)
207207
}
208208

209+
beach_run_specified_hook() {
210+
if [ -n "$1" ]; then
211+
if is_boolean_yes "$BEACH_APPLICATION_CUSTOM_STARTUP_SCRIPTS_ENABLE"; then
212+
if [ ! -f "${BEACH_APPLICATION_PATH}/$1.sh" ]; then
213+
info "Beach: No $1.sh found, skipping hook"
214+
return
215+
fi
216+
info "Beach: Running '$1' hook ($1.sh) ..."
217+
chmod +x "${BEACH_APPLICATION_PATH}/$1.sh"
218+
"${BEACH_APPLICATION_PATH}/$1.sh" 2>&1 | (sed 's/^/Beach: (flow) /' | output)
219+
else
220+
info "Beach: Skipping '$1' hook because custom startup scripts are disabled"
221+
fi
222+
else
223+
warn "No hook name given to run hook function, this should not happen"
224+
fi
225+
}
226+
209227
# ---------------------------------------------------------------------------------------
210228
# beach_run_sitemap_crawler() - Invoke a crawler which warms up caches for all urls of a sitemap
211229
#
@@ -315,6 +333,8 @@ beach_initialize() {
315333
beach_setup_user_profile
316334
beach_setup_igbinary
317335
beach_setup_addon_blackfire
336+
337+
beach_run_specified_hook "beach-hook-initialize"
318338
}
319339

320340
# ---------------------------------------------------------------------------------------
@@ -340,10 +360,11 @@ beach_prepare_flow() {
340360

341361
if is_boolean_yes "$BEACH_APPLICATION_CUSTOM_STARTUP_SCRIPTS_ENABLE"; then
342362
info "Beach: Running custom startup scripts ..."
343-
beach_run_custom_startup
363+
beach_run_custom_startup
344364
else
345365
info "Beach: Skipping custom startup scripts"
346366
fi
367+
beach_run_specified_hook "beach-hook-warmup"
347368

348369
beach_enable_user_services
349370
}
@@ -364,7 +385,12 @@ beach_finalize_flow() {
364385
info "Beach: Running sitemap crawler ..."
365386
beach_run_sitemap_crawler
366387
fi
388+
}
367389

390+
beach_startup_complete() {
391+
beach_run_specified_hook "beach-hook-ready"
368392
debug "Beach: Writing .warmupdone flag"
369393
touch /application/.warmupdone
394+
info ".warmupdone written, this pod will now become ready"
395+
beach_run_specified_hook "beach-hook-live"
370396
}

0 commit comments

Comments
 (0)