dtfscript: Move code into functions

This commit is contained in:
Salt 2018-08-28 13:16:32 -05:00
parent 979558098f
commit 167571f31a

View File

@ -83,9 +83,10 @@ else
dtf_log "Performing a subset of all tasks"
fi
## Run tasks
for task in $DTF_TASKS; do
task_full="$DTF_TASKS_DIR/$task"
## Define (and export) a task run function
function dtf_task_run() {
[ -z ${1+x} ] && return 1
task_full="$DTF_TASKS_DIR/$1"
(
if ! [ -r "$task_full" ]; then
dtf_log "Task is unreadable or missing: $task"
@ -98,6 +99,12 @@ for task in $DTF_TASKS; do
source "$DTF_CONFIG_HOME/common_task.sh"
source "$task_full"
)
}
export -f dtf_task_run
## Run tasks
for task in $DTF_TASKS; do
dtf_task_run $task
done
## Determine which services to run
@ -111,28 +118,39 @@ else
dtf_log "Starting a subset of available services"
fi
## Run startup scripts
for service in $DTF_SERVICES; do
service_full="$DTF_SERVICES_DIR/$service"
(
## Define (and export) service functions
function dtf_service_validate() {
service_full="$DTF_SERVICES_DIR/$1"
if ! [ -r "$service_full" ]; then
dtf_log "Service is unreadable or missing: $service"
exit 1
dtf_log "Service is unreadable or missing: $1"
return 1
fi
if ! [ -x "$service_full" ]; then
dtf_log "Service is unexecutable: $service"
exit 1
dtf_log "Service is unexecutable: $1"
return 1
fi
return 0
}
export -f dtf_service_validate
function dtf_service_start() {
service_full="$DTF_SERVICES_DIR/$1"
dtf_service_validate $1 || return 1
(
source "$DTF_CONFIG_HOME/common_service.sh"
source "$service_full"
if isup && [[ "$service_kill_on_reload" == "true" ]] ; then
stop
fi
if ! prestart; then exit 1; fi
if ! prestart-extra; then exit 1; fi
isup && [[ "$service_kill_on_reload" == "true" ]] && stop
prestart || exit 1
prestart-extra || exit 1
start
start-extra
)
}
export -f dtf_service_start
## Run startup scripts
for service in $DTF_SERVICES; do
dtf_service_start $service
done
dtf_log "Finished initialization"