Skip to content

Commit 06b3a94

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/*/.devilbox/autostart` which will then be executed on startup of the php container.
1 parent 06cb912 commit 06b3a94

File tree

2 files changed

+61
-0
lines changed

2 files changed

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

187187

188+
###
189+
### Run project supplied scripts
190+
###
191+
execute_project_scripts "${DEBUG_LEVEL}"
192+
193+
188194
###
189195
###
190196
### Startup

0 commit comments

Comments
 (0)