Skip to content

Commit 9b057b5

Browse files
committed
Add project-specific startup script support (e.g. for cron configuration)
Allow user to add *.sh files to `$HOST_PATH_HTTPD_DATADIR/*/$HTTPD_TEMPLATE_DIR/autostart` which will then be executed on startup of the php container.
1 parent b75c0eb commit 9b057b5

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -u
5+
set -o pipefail
6+
7+
############################################################
8+
# Functions
9+
############################################################
10+
11+
###
12+
### Execute project-supplied scripts
13+
###
14+
execute_project_scripts() {
15+
local debug="${1}"
16+
local script_dir
17+
local script_name
18+
local DEVILBOX_PROJECT_DIR
19+
local DEVILBOX_PROJECT_NAME
20+
local DEVILBOX_PROJECT_DOCROOT
21+
22+
for DEVILBOX_PROJECT_DIR in /shared/httpd/*; do
23+
24+
script_dir=${DEVILBOX_PROJECT_DIR}/.devilbox/autostart
25+
26+
if [ -d "${DEVILBOX_PROJECT_DIR}" ] && [ -d "${script_dir}" ]; then
27+
28+
DEVILBOX_PROJECT_NAME=$(basename "${DEVILBOX_PROJECT_DIR}")
29+
export DEVILBOX_PROJECT_NAME
30+
31+
DEVILBOX_PROJECT_DOCROOT=${DEVILBOX_PROJECT_DIR}/$(env_get HTTPD_DOCROOT_DIR "htdocs")
32+
export DEVILBOX_PROJECT_DOCROOT
33+
34+
script_files="$(find -L "${script_dir}" -type f -iname '*.sh' | sort -n)"
35+
36+
# loop over them line by line
37+
IFS='
38+
'
39+
for script_f in ${script_files}; do
40+
41+
script_name="$(basename "${script_f}")"
42+
43+
log "info" "Executing project startup script: ${DEVILBOX_PROJECT_NAME}:${script_name}" "${debug}"
44+
45+
if ! bash "${script_f}" "${debug}"; then
46+
log "err" "Failed to execute script" "${debug}"
47+
exit 1
48+
fi
49+
50+
done
51+
fi
52+
done
53+
}
54+
55+
############################################################
56+
# Sanity Checks
57+
############################################################
58+
59+
# find, sort, and basename are already checked in ./310-custom-startup-scripts.sh

Dockerfiles/prod/data/docker-entrypoint.sh

+6
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ execute_custom_scripts "/startup.1.d" "${DEBUG_LEVEL}"
191191
execute_custom_scripts "/startup.2.d" "${DEBUG_LEVEL}"
192192

193193

194+
###
195+
### Run project supplied scripts
196+
###
197+
execute_project_scripts "${DEBUG_LEVEL}"
198+
199+
194200
###
195201
### Startup
196202
###

0 commit comments

Comments
 (0)