-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstart.sh
executable file
·48 lines (40 loc) · 1.39 KB
/
start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
cd -- "$(dirname -- "${BASH_SOURCE[0]}")"
# prints its arguments to STDERR in green
function info {
echo >&2 "> $(tput setaf 2)$*$(tput sgr0)"
}
if [[ -e ./agent.pid ]]; then
info 'Stopping the agent from a previous run'
AGENT_PID="$(< ./agent.pid)"
kill "$AGENT_PID" && wait "$AGENT_PID" || :
rm ./agent.pid
fi
info 'Building the agent'
cargo build --release -p ndc-postgres
info 'Starting the dependencies'
(cd ../.. && docker compose up --wait jaeger) # avoid port clobbering by re-using Jaeger
docker compose up --wait postgres grafana
POSTGRESQL_SOCKET="$(docker compose port postgres 5432)"
info 'Starting the agent'
if nc -z localhost 8080; then
echo >&2 'ERROR: There is already an agent running on port 8080.'
exit 1
fi
CONNECTION_URI="postgresql://postgres:password@${POSTGRESQL_SOCKET}" \
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT='http://localhost:4317' \
OTEL_SERVICE_NAME='ndc-postgres' \
cargo run -p ndc-postgres --quiet --release -- \
serve --configuration='../../static/postgres/v5-configuration' \
>& agent.log &
AGENT_PID=$!
echo "$AGENT_PID" > ./agent.pid
echo >&2 "The agent is running with PID ${AGENT_PID}"
../../scripts/wait-until --timeout=30 --report -- cargo run -p ndc-postgres --quiet -- check-health
if ! kill -0 "$AGENT_PID"; then
echo >&2 'The agent stopped abruptly. Take a look at agent.log for details.'
exit 1
fi