Commit cea3c094 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Add a --log option to bootstrap-stage

Each time the option is given, its argument is created as a symlink to
/dev/stderr
parent afa3e505
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
set -eu -o pipefail
declare -r DEFAULT_STAGE=/stage

USAGE="Usage: $0 [--help] [-s STAGE]
USAGE="Usage: $0 [--help] [-s STAGE] [-l LOG]

Prepare the necessary components of an image in a staging directory

@@ -30,18 +30,25 @@ Options:
  -h|--help         Show this message and exit.
  -s|--stage STAGE  Set the output stage directory. If it does not exist it will
                    be created. (default: $DEFAULT_STAGE)
  -l|--log LOG      Create a symlink at LOG pointing to /dev/stderr

Environment:
  STAGE:  An alternate way of providing --stage

On Logging:
  Some software can only understand logging to a file. Use --log to make
  a symlink pointing to stderr to enable logging output that Docker can handle.
"

export PATH+=:$(dirname $0)
export STAGE=${STAGE-$DEFAULT_STAGE}
declare -a LOGS=()

until [[ $# -eq 0 ]]; do
	case $1 in
		-h|--help) echo "$USAGE"; exit 0 ;;
		-s|--stage) STAGE=$2; shift ;;
		-l|--log) LOGS+=($2); shift ;;
		--*=*) set -- ${1%=*} ${1#--*=} "${@:2}"; continue ;;
		*) echo >&2 "Unknown argument: $1"; exit 2 ;;
	esac
@@ -64,3 +71,9 @@ test -h $STAGE/tmp || ln -s /var/tmp $STAGE/tmp
# Run directories
mkdir -p --mode=0755 $STAGE/var/run
test -h $STAGE/run || ln -s /var/run /run

# Log directories
for log in "${LOGS[@]}"; do
	mkdir -p --mode=0755 "$(dirname "$log")"
	ln -s /dev/stderr "$log"
done