Add locking to poudboot.
This commit is contained in:
parent
0e86dac2ac
commit
9d16e1d42e
@ -5,26 +5,56 @@ set -euo pipefail
|
|||||||
IFS=$'\n\t'
|
IFS=$'\n\t'
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
: ${LOCKFILE:="/var/run/poudboot.lock"}
|
||||||
|
|
||||||
|
############## Setup #########################
|
||||||
|
|
||||||
|
# function cleanup {
|
||||||
|
# for f in "${folders[@]}"; do
|
||||||
|
# log "Deleting $f"
|
||||||
|
# rm -rf "$f"
|
||||||
|
# done
|
||||||
|
# }
|
||||||
|
# folders=()
|
||||||
|
# for sig in EXIT INT QUIT HUP TERM; do
|
||||||
|
# trap "set +e; cleanup" "$sig"
|
||||||
|
# done
|
||||||
|
|
||||||
|
function die {
|
||||||
|
local status_code="$1"
|
||||||
|
shift
|
||||||
|
(>&2 echo "${@}")
|
||||||
|
exit "$status_code"
|
||||||
|
}
|
||||||
|
|
||||||
|
function log {
|
||||||
|
(>&2 echo "${@}")
|
||||||
|
}
|
||||||
|
|
||||||
|
function run_locked {
|
||||||
|
if [ "${RUN_LOCKED:-}" != "RUN" ]; then
|
||||||
|
exec env RUN_LOCKED=RUN flock --nonblock $LOCKFILE $0 $@
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
############## Program #########################
|
||||||
|
|
||||||
function main {
|
function main {
|
||||||
COMMAND="$1"
|
local COMMAND="$1"
|
||||||
shift 1
|
|
||||||
|
|
||||||
if [ "$COMMAND" = "start" ]; then
|
if [ "$COMMAND" = "start" ]; then
|
||||||
|
run_locked "${@}"
|
||||||
|
shift 1
|
||||||
cmd_start "${@}"
|
cmd_start "${@}"
|
||||||
elif [ "$COMMAND" = "stop" ]; then
|
elif [ "$COMMAND" = "stop" ]; then
|
||||||
|
shift 1
|
||||||
cmd_stop "${@}"
|
cmd_stop "${@}"
|
||||||
else
|
else
|
||||||
die 1 "Unrecognized command: $COMMAND"
|
die 1 "Unrecognized command: $COMMAND"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function die {
|
|
||||||
exit_code="$1"
|
|
||||||
shift 1
|
|
||||||
(>&2 echo "${@}")
|
|
||||||
exit "$exit_code"
|
|
||||||
}
|
|
||||||
|
|
||||||
function abort_if_jobs_running {
|
function abort_if_jobs_running {
|
||||||
if [[ $(sudo poudriere status) != *"No running builds"* ]]; then
|
if [[ $(sudo poudriere status) != *"No running builds"* ]]; then
|
||||||
echo "There is already a poudriere build in progress, exiting."
|
echo "There is already a poudriere build in progress, exiting."
|
||||||
@ -40,21 +70,18 @@ function build {
|
|||||||
function cmd_start {
|
function cmd_start {
|
||||||
abort_if_jobs_running
|
abort_if_jobs_running
|
||||||
|
|
||||||
|
for conf in /opt/poudriere/build_configs/*; do
|
||||||
|
(
|
||||||
# Allow command failures without quitting the script because some
|
# Allow command failures without quitting the script because some
|
||||||
# package sets might fail whereas others may succeed based on which
|
# package sets might fail whereas others may succeed based on which
|
||||||
# packages are in each set.
|
# packages are in each set.
|
||||||
set +e
|
set +e
|
||||||
|
|
||||||
for conf in /opt/poudriere/build_configs/*; do
|
|
||||||
(
|
|
||||||
source "$conf"
|
source "$conf"
|
||||||
build -j "$JAIL" -p "$PORTS" -z "$SET" -f /usr/local/etc/poudriere.d/$JAIL-$PORTS-$SET-pkglist
|
build -j "$JAIL" -p "$PORTS" -z "$SET" -f /usr/local/etc/poudriere.d/$JAIL-$PORTS-$SET-pkglist
|
||||||
)
|
)
|
||||||
done
|
done
|
||||||
|
|
||||||
# Re-enable exiting on failed commands
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Cleanup old unused dist files
|
# Cleanup old unused dist files
|
||||||
for conf in /opt/poudriere/build_configs/*; do
|
for conf in /opt/poudriere/build_configs/*; do
|
||||||
(
|
(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user