2019-11-13 19:27:28 +03:00
|
|
|
#!/usr/bin/env bash
|
2020-03-27 03:26:10 +03:00
|
|
|
# Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
2019-11-13 19:27:28 +03:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -u
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
CANTON_COMMAND=(
|
|
|
|
"$(rlocation com_github_digital_asset_daml/ledger/ledger-api-test-tool-on-canton/canton)"
|
|
|
|
daemon
|
|
|
|
"--config=$(rlocation com_github_digital_asset_daml/ledger/ledger-api-test-tool-on-canton/canton.conf)"
|
|
|
|
"--bootstrap=$(rlocation com_github_digital_asset_daml/ledger/ledger-api-test-tool-on-canton/bootstrap.canton)"
|
|
|
|
)
|
|
|
|
|
2020-01-23 11:04:16 +03:00
|
|
|
PARTICIPANT_1_HOST=localhost
|
2019-11-13 19:27:28 +03:00
|
|
|
PARTICIPANT_1_LEDGER_API_PORT=5011
|
2020-01-23 11:04:16 +03:00
|
|
|
PARTICIPANT_1_MONITORING_PORT=7000
|
2019-11-13 19:27:28 +03:00
|
|
|
|
2020-01-23 11:04:16 +03:00
|
|
|
TIMEOUT=60
|
2019-11-13 19:27:28 +03:00
|
|
|
|
2020-01-23 11:04:16 +03:00
|
|
|
function wait_until() {
|
|
|
|
local start
|
2019-11-13 19:27:28 +03:00
|
|
|
|
|
|
|
start="$(date +%s)"
|
|
|
|
while true; do
|
2020-01-23 11:04:16 +03:00
|
|
|
if [[ "$(("$(date +%s)" - start))" -gt "$TIMEOUT" ]]; then
|
2019-11-13 19:27:28 +03:00
|
|
|
echo >&2 "Timed out after ${TIMEOUT} seconds."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2020-01-23 11:04:16 +03:00
|
|
|
if "$@" >&/dev/null; then
|
2019-11-13 19:27:28 +03:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
command=("${CANTON_COMMAND[@]}")
|
|
|
|
port_file=''
|
2020-01-23 11:04:16 +03:00
|
|
|
while (($#)); do
|
2020-08-18 16:25:02 +03:00
|
|
|
# Extract the port file.
|
2019-11-13 19:27:28 +03:00
|
|
|
if [[ "$1" == '--port-file' ]]; then
|
|
|
|
port_file="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
command+=("$1")
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ -z "$port_file" ]]; then
|
|
|
|
# shellcheck disable=SC2016
|
|
|
|
echo >&2 'You must specify a port file with the `--port-file` switch.'
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2020-11-10 20:09:58 +03:00
|
|
|
export UNIQUE_CONTRACT_KEYS="$(rlocation com_github_digital_asset_daml/ledger/ledger-api-test-tool-on-canton/unique-contract-keys.conf)"
|
|
|
|
if [[ -f ${UNIQUE_CONTRACT_KEYS} ]]; then
|
|
|
|
command+=("--config=${UNIQUE_CONTRACT_KEYS}")
|
|
|
|
fi
|
|
|
|
|
2020-11-23 17:28:04 +03:00
|
|
|
export ENABLE_FASTER_PRUNING="$(rlocation com_github_digital_asset_daml/ledger/ledger-api-test-tool-on-canton/enable-faster-pruning.conf)"
|
|
|
|
if [[ -f ${ENABLE_FASTER_PRUNING} ]]; then
|
|
|
|
command+=("--config=${ENABLE_FASTER_PRUNING}")
|
|
|
|
fi
|
|
|
|
|
2020-08-18 16:25:02 +03:00
|
|
|
# Change HOME since Canton uses ammonite in the default configuration, which tries to write to
|
|
|
|
# ~/.ammonite/cache, which is read-only when sandboxing is enabled.
|
|
|
|
HOME="$(mktemp -d)"
|
|
|
|
export HOME
|
|
|
|
# ammonite calls `System.getProperty('user.home')` which does not read $HOME.
|
2020-03-10 19:34:58 +03:00
|
|
|
command+=("--wrapper_script_flag=--jvm_flag=-Duser.home=$HOME")
|
2020-09-04 15:25:30 +03:00
|
|
|
command+=("--wrapper_script_flag=--jvm_flag=-Dlogback.configurationFile=$(rlocation com_github_digital_asset_daml/ledger/ledger-api-test-tool-on-canton/logback-debug.xml)")
|
2020-03-10 19:34:58 +03:00
|
|
|
|
2019-11-13 19:27:28 +03:00
|
|
|
echo >&2 'Starting Canton...'
|
2020-01-23 11:04:16 +03:00
|
|
|
"${command[@]}" &
|
2019-11-13 19:27:28 +03:00
|
|
|
pid="$!"
|
|
|
|
|
|
|
|
sleep 1
|
2020-01-23 11:04:16 +03:00
|
|
|
if ! kill -0 "$pid" 2>/dev/null; then
|
2019-11-13 19:27:28 +03:00
|
|
|
echo >&2 'Failed to start Canton.'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-01-23 11:04:16 +03:00
|
|
|
function stop() {
|
2019-11-13 19:27:28 +03:00
|
|
|
local status
|
|
|
|
status=$?
|
2020-01-23 11:04:16 +03:00
|
|
|
kill -INT "$pid" || :
|
2019-11-13 19:27:28 +03:00
|
|
|
rm -f "$port_file" || :
|
2020-03-10 19:34:58 +03:00
|
|
|
rm -rf "$HOME" || :
|
2019-11-13 19:27:28 +03:00
|
|
|
exit "$status"
|
|
|
|
}
|
|
|
|
|
|
|
|
trap stop EXIT INT TERM
|
|
|
|
|
2020-01-23 11:04:16 +03:00
|
|
|
wait_until curl -fsS "http://${PARTICIPANT_1_HOST}:${PARTICIPANT_1_MONITORING_PORT}/health"
|
2019-11-13 19:27:28 +03:00
|
|
|
|
|
|
|
# This should write two ports, but the runner doesn't support that.
|
2020-01-23 11:04:16 +03:00
|
|
|
echo "$PARTICIPANT_1_LEDGER_API_PORT" >"$port_file"
|
2019-11-13 19:27:28 +03:00
|
|
|
|
|
|
|
echo >&2 'Canton is up and running.'
|
|
|
|
|
|
|
|
wait "$pid"
|