Skip to content

Commit 54026a3

Browse files
committed
Fix entrypoint commands
1 parent 9ba2cb9 commit 54026a3

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

entrypoint.sh

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
#!/bin/bash
12
set -euo pipefail
23

34
### generate pgpass file
45

5-
gen_pgpass="$(find /nix/store -name '*gen-pgpass')"
6+
gen_pgpass="$(find /nix/store -maxdepth 1 -name '*gen-pgpass' -print -quit)"
67
export PGPASSFILE=/configuration/pgpass
78
$gen_pgpass
89

@@ -20,17 +21,22 @@ fi;
2021

2122
export CARDANO_NODE_SOCKET_PATH="/node-ipc/node.socket"
2223

24+
WAIT_FOR_NODE_SYNC=$(echo -n "${WAIT_FOR_NODE_SYNC:-}" | tr '[:upper:]' '[:lower:]')
2325

2426

25-
if true # wait for the node sync by default.
26-
then
27+
if [[ "${WAIT_FOR_NODE_SYNC,,}" =~ ^(y|yes|1|true)$ ]]; then
2728
until [ -S $CARDANO_NODE_SOCKET_PATH ]; do
2829
echo Waiting for $CARDANO_NODE_SOCKET_PATH
2930
sleep 10
3031
done
3132

3233

3334
DB_MAX_BLOCK=$(psql -h $PGHOST $PGDATABASE -U $PGUSER -t -c 'select max (block_no) from block;')
35+
# Ensure DB_MAX_BLOCK is a valid integer, if not, exit with an error
36+
if ! [[ "$DB_MAX_BLOCK" =~ ^[0-9]+$ ]]; then
37+
echo "Block in db:"$DB_MAX_BLOCK
38+
DB_MAX_BLOCK=0
39+
fi
3440
NODE_CUR_BLOCK=0
3541
while [ $NODE_CUR_BLOCK -lt $DB_MAX_BLOCK ]; do
3642
NODE_STATUS="$(cardano-cli query tip --mainnet 2>/dev/null || true)"
@@ -54,7 +60,7 @@ CONFIG_HOME="/environments"
5460
if [ -z "${NETWORK:-}" ]; then
5561
echo "NETWORK is not set, defaulting to mainnet"
5662
NETWORK="mainnet"
57-
NO_NETWORK_SET=1
63+
NO_NETWORK_SET="1"
5864
else
5965
echo "NETWORK is set to $NETWORK"
6066
fi
@@ -76,7 +82,7 @@ fi
7682
if [[ -z "${DB_SYNC_CONFIG:-}" ]]; then
7783
DB_SYNC_CONFIG="$CONFIG_HOME/$NETWORK"
7884

79-
elif [[ -z "${NO_NETWORK_SET}" ]]; then # dbsync config is set and network is not
85+
elif [[ -z "${NO_NETWORK_SET:-}" ]]; then # dbsync config is set and network is not
8086
DB_SYNC_CONFIG="$CONFIG_HOME"
8187

8288
else ## both NETWORK and DB_SYNC_CONFIG are set
@@ -90,9 +96,17 @@ else ## both NETWORK and DB_SYNC_CONFIG are set
9096
fi
9197

9298

93-
SCHEMA_DIR=$(find /nix/store -name -type d '*-schema')}
99+
SCHEMA_DIR=$(find /nix/store -maxdepth 1 -type d -name '*-schema' -print -quit)
94100

95-
exec cardano-db-sync \
101+
102+
echo '>' cardano-db-sync \
103+
--config "$DB_SYNC_CONFIG" \
104+
--socket-path "$CARDANO_NODE_SOCKET_PATH" \
105+
--schema-dir ${SCHEMA_DIR} \
106+
${LEDGER_OPTS} \
107+
${EXTRA_DB_SYNC_ARGS:-}
108+
109+
exec cardano-db-sync \
96110
--config "$DB_SYNC_CONFIG" \
97111
--socket-path "$CARDANO_NODE_SOCKET_PATH" \
98112
--schema-dir ${SCHEMA_DIR} \

0 commit comments

Comments
 (0)