#!/bin/bash # # Simple launcher script to start some worker scripts within a folder # sequentially, in ABC order. The workers' folder is a subfolder of the # script's folder with same name as the script, followed by a .d extension. # All worker scripts must be executable and must have .sh extension. # Other files within the folder will be simply ignored. # # This script usually get called via symlink, therefore the workers' folder's # name comes from the symlink's name. This folder selection may be overridden # using an environment variable. Another environment variable may order to # waiting a time between workers' launch. # # Author: Kovács Zoltán # Kovács Zoltán # License: GNU/GPL v3+ (https://www.gnu.org/licenses/gpl-3.0.en.html) # 2023-06-18 v1.0 # new: forked from the "Smartfront's DOCKER_skeleton" repository. # 2021-08-30 v0.1 Initial release # Accepted environment variables and their defaults. SLEEP_BETWEEN=${SLEEP_BETWEEN-"0"} # Secs between launches WORKER_DIR=${WORKER_DIR:-""} # Worker's folder # Messages. MSG_MISSINGWRK="Fatal: missing worker's folder" # Checks the components. [[ -z "$(which basename)" ]] && exit 1 [[ -z "$(which dirname)" ]] && exit 1 [[ -z "$(which printf)" ]] && exit 1 [[ -z "$(which sleep)" ]] && exit 1 # Where I'm? SCRPATH="$( cd -P "$(dirname "$0" )" && echo "$PWD" )" #" # Checks the worker's folder. [[ -z "$WORKER_DIR" ]] && WORKER_DIR="$SCRPATH/$(basename "$0").d" if [ -z "$WORKER_DIR" -o ! -d "$WORKER_DIR" ]; then echo "$MSG_MISSINGWRK $WORKER_DIR" >&2; exit 1 fi # Converts the (optional) time parameter to float. SLEEP_BETWEEN=$(printf '%.2f' "$SLEEP_BETWEEN" 2>/dev/null) # Enumerates the workers. WORKERS="$(cd "$WORKER_DIR"; ls -1 *.sh 2>/dev/null)" for worker in $WORKERS "" do # Safety first... if [ -n "$worker" -a -x "$WORKER_DIR/$worker" ]; then # Launches the worker then waits till it finishes. "$WORKER_DIR/$worker" "$@" # Optionally reduces the launch frequency. sleep ${SLEEP_BETWEEN//,/.} # decimal point need fi done # That's all, Folks!