blob: 13bd1ec6bed5a299219bce47cebc254aed1b370e [file] [log] [blame]
#!/bin/bash
# Exit on error.
set -e
# $BUCK_BIN_DIRECTORY is the directory that hosts this script. Solution taken from:
# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
SOURCE="${BASH_SOURCE[0]}"
DIR="$( dirname "$SOURCE" )"
while [ -h "$SOURCE" ]
do
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
BUCK_BIN_DIRECTORY=$DIR
# Set environment and update buck if required.
# TODO(user): refactor buck_common in to functions that can be called
source "${BUCK_BIN_DIRECTORY}/buck_common"
# Kill any existing buckd process.
if [ $BUCKD_RUNNING -eq 0 ]; then
echo "Killing existing buckd process"
kill `cat $BUCKD_PID_FILE 2> /dev/null` &> /dev/null || true
fi
# Find an unused port.
for BUCKD_PORT in $(seq 2000 65000); do
nc -z localhost $BUCKD_PORT &> /dev/null || break
done
# Persist port.
mkdir -p "$BUCKD_DIR" &> /dev/null || true
echo $BUCKD_PORT > "$BUCKD_PORT_FILE"
# Run buckd.
java \
$BUCK_JAVA_ARGS \
-classpath \
${BUCK_JAVA_CLASSPATH} \
com.martiansoftware.nailgun.NGServer localhost:${BUCKD_PORT} \
&> $BUCKD_LOG_FILE &
echo $! > "$BUCKD_PID_FILE"