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