Files
zulip/tools/provision
Tim Abbott 699d30b1eb provision: Ensure that stderr output isn't buffered badly.
Previously, if a script called by provision threw an error, the
traceback for the called script would be lost far above the traceback
from provision itself in the terminal history, resulting in a great
deal of confusion about what the actual problem was.
2017-01-17 14:28:10 -08:00

35 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
set -e
if [ "$EUID" -eq 0 ]; then
echo "Error: The provision script must not be run as root" >&2
exit 1
fi
#Make the script independent of the location from where it is
#executed
PARENT_PATH=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P )
cd "$PARENT_PATH"
mkdir -p ../var/log
LOG_PATH="../var/log/provision.log"
PROVISION_PATH="lib/provision.py"
echo "PROVISIONING STARTING." >> $LOG_PATH
# PYTHONUNBUFFERED is important to ensure that tracebacks don't get
# lost far above where they should be in the output.
export PYTHONUNBUFFERED=1
python "$PROVISION_PATH" $@ 2>&1 | tee -a "$LOG_PATH"
failed=${PIPESTATUS[0]}
if [ $failed = 1 ]; then
echo -e "\033[0;31m"
echo "Provisioning failed!"
echo
echo -n "The provision process is designed to be idempotent, so you can retry "
echo -n "after resolving whatever issue caused the failure (there should be a traceback above). "
echo -n "A log of this installation is available in zulip/log/provision.log"
echo -e "\033[0m"
exit 1
fi
exit 0