Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add project-specific startup script support (eg. for cron configuration) #263

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

set -e
set -u
set -o pipefail

############################################################
# Functions
############################################################

###
### Execute project-supplied scripts
###
execute_project_scripts() {
local debug="${1}"
local script_dir
local script_name
local DEVILBOX_PROJECT_DIR
local DEVILBOX_PROJECT_NAME
local DEVILBOX_PROJECT_DOCROOT

for DEVILBOX_PROJECT_DIR in /shared/httpd/*; do

script_dir=${DEVILBOX_PROJECT_DIR}/$(env_get HTTPD_TEMPLATE_DIR ".devilbox")/autostart

if [ -d "${DEVILBOX_PROJECT_DIR}" ] && [ -d "${script_dir}" ]; then

DEVILBOX_PROJECT_NAME=$(basename "${DEVILBOX_PROJECT_DIR}")
export DEVILBOX_PROJECT_NAME

DEVILBOX_PROJECT_DOCROOT=${DEVILBOX_PROJECT_DIR}/$(env_get HTTPD_DOCROOT_DIR "htdocs")
export DEVILBOX_PROJECT_DOCROOT

script_files="$(find -L "${script_dir}" -type f -iname '*.sh' | sort -n)"

# loop over them line by line
IFS='
'
for script_f in ${script_files}; do

script_name="$(basename "${script_f}")"

log "info" "Executing project startup script: ${DEVILBOX_PROJECT_NAME}:${script_name}" "${debug}"

if ! bash "${script_f}" "${debug}"; then
log "err" "Failed to execute script" "${debug}"
exit 1
fi

done
fi
done
}

############################################################
# Sanity Checks
############################################################

# find, sort, and basename are already checked in ./310-custom-startup-scripts.sh
6 changes: 6 additions & 0 deletions Dockerfiles/prod/data/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ execute_custom_scripts "/startup.1.d" "${DEBUG_LEVEL}"
execute_custom_scripts "/startup.2.d" "${DEBUG_LEVEL}"


###
### Run project supplied scripts
###
execute_project_scripts "${DEBUG_LEVEL}"


###
### Startup
###
Expand Down