-
Notifications
You must be signed in to change notification settings - Fork 4
/
vclod_do_dir
executable file
·48 lines (41 loc) · 2.4 KB
/
vclod_do_dir
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#! /bin/ksh
# Launches all VCLOD batches defined in a directory, running up to VCLOD_JOBS at a time.
set -a
: ${CONFIG_FILE:=${CONFIG_ENV_PATH:-/etc}/vclods} # Where to find the global config. Fully Qualified version is $CONFIG_FILE
[ -f "$CONFIG_FILE" ] || { echo "CONFIG_FILE must exist - default of /etc/vclods - current $CONFIG_FILE" ; exit 1; }
: "${VCLOD_BASE_DIR:=$(dirname "$(readlink -f "$(which "$0")")")}" # PRIVATE
: "${1:?Missing a directory or file to process}"
IS_TERMINAL=$([ -t 1 ] && echo 1 || echo 0)
cat "$CONFIG_FILE" "${VCLOD_BASE_DIR%/}"/includes/* "${VCLOD_BASE_DIR%/}"/connections/* | . /dev/stdin || exit $?
VCLOD_FILE_EXTS="$(ls -1 "${VCLOD_BASE_DIR%/}/extensions/" | paste -sd'|')"
VCLOD_FILE_REGEX='^.*[^.]+(\.('$VCLOD_FILE_EXTS')(-[^.]+)?)+$'
: "${VCLOD_LOCK_DIR:=/dev/shm/}" # Where to put lock files (and internal fifos). Generally /dev/shm
: "${LOG_BASE_DIR:?}" # Where to store log files (will also store error output)
: "${VCLOD_ERR_DIR:?}" # Where to store error files (/dev/shm is a good option)
: "${VCLOD_JOBS:=10}" # How many scripts to run in parallel. Must be at least 1 or nothing will happen.
: "${OPERATIONS_EMAIL:?}" # Email address list to send error output to
MAIL_ELF="${LOG_BASE_DIR}/$$.err" # used to send batched error emails.
set +a
check_dirs
[ -s "$MAIL_ELF" ] && : >"$MAIL_ELF" # force it to start empty
ulimit -s unlimited # log files might get large, need to let them float in however much memory is needed/available.
PIPE_FIFO="${VCLOD_LOCK_DIR%/}/pipe.$$.fifo" ; mkfifo "$PIPE_FIFO" ; exec 9<>"$PIPE_FIFO" ; add_file_cleanup "$PIPE_FIFO"
stdbuf -i0 -o0 -e0 seq 1 "$VCLOD_JOBS" >&9
post_exit_trap 'for j in "$(jobs -p)";do kill -SIGINT "$j" 2>/dev/null;done;[ -n "$(jobs -p)" ] && wait'
if [ ! -e "$1" ]; then # needs to be here instead of the next if because of the pipe.
export pIN_FILE="$(mktemp)" # the p stands for private and prevents it from showing up in the doco
add_file_cleanup "$pIN_FILE"
cat >"$pIN_FILE" # not sure why this works here but not in run_script
fi
if [ -e "$1" ]; then
find "$@" ! -empty -xtype f -regextype posix-egrep -regex "$VCLOD_FILE_REGEX" | sort -n
else
printf '%s\n' "$1"
fi | while read filename ; do
stdbuf -i0 -o0 -e0 read dummy <&9
: | run_script "$filename" &
done
[ -n "$(jobs -p)" ] && wait
ret=$?
[ -s "$MAIL_ELF" ] && [ "$IS_TERMINAL" -eq 0 ] && mail -s "Script error digest on $(hostname)" "$OPERATIONS_EMAIL" <"$MAIL_ELF"
exit $ret