eth-statediff-service/startup_script.sh

63 lines
1.9 KiB
Bash
Raw Normal View History

2023-04-28 03:24:22 +00:00
#!/bin/bash
2020-08-19 20:30:52 +00:00
# Exit if the variable tests fail
set -e
2023-04-28 03:24:22 +00:00
set -o pipefail
if [[ -n "$CERC_SCRIPT_DEBUG" ]]; then
set -x
fi
2020-08-19 20:30:52 +00:00
# Check the database variables are set
test "$VDB_COMMAND"
2023-04-27 03:58:28 +00:00
# docker must be run in privileged mode for mounts to work
echo "Setting up /app/geth-rw overlayed onto /app/geth-ro"
mkdir -p /tmp/overlay
mount -t tmpfs tmpfs /tmp/overlay
mkdir -p /tmp/overlay/upper
mkdir -p /tmp/overlay/work
mkdir -p /app/geth-rw
mount -t overlay overlay -o lowerdir=/app/geth-ro,upperdir=/tmp/overlay/upper,workdir=/tmp/overlay/work /app/geth-rw
mkdir /var/run/statediff
cd /var/run/statediff
SETUID=""
if [[ -n "$TARGET_UID" ]] && [[ -n "$TARGET_GID" ]]; then
SETUID="su-exec $TARGET_UID:$TARGET_GID"
chown -R $TARGET_UID:$TARGET_GID /var/run/statediff
fi
2023-04-27 03:58:28 +00:00
START_TIME=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
echo "Running the statediff service" && \
if [[ ! -z "$LOG_FILE" ]]; then
$SETUID /app/eth-statediff-service "$VDB_COMMAND" --config=/app/config.toml $* |& $SETUID tee ${LOG_FILE}.console
2023-04-28 03:24:22 +00:00
rc=$?
else
$SETUID /app/eth-statediff-service "$VDB_COMMAND" --config=/app/config.toml $*
2023-04-28 03:24:22 +00:00
rc=$?
fi
2023-04-27 03:58:28 +00:00
STOP_TIME=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
2023-05-08 22:19:51 +00:00
if [ $rc -eq 0 ] && [ "$VDB_COMMAND" == "serve" ] && [ "$PRERUN_ONLY" == "true" ] && [ ! -z "$PRERUN_RANGE_START" ] && [ ! -z "$PRERUN_RANGE_STOP" ] && [ ! -z "$DATABASE_FILE_CSV_DIR" ] && [ "$DATABASE_FILE_MODE" == "csv" ]; then
cat >metadata.json <<EOF
2023-04-27 03:58:28 +00:00
{
2023-05-08 22:19:51 +00:00
"type": "statediff",
2023-04-27 03:58:28 +00:00
"range": { "start": $PRERUN_RANGE_START, "stop": $PRERUN_RANGE_STOP },
"nodeId": "$ETH_NODE_ID",
"genesisBlock": "$ETH_GENESIS_BLOCK",
"networkId": "$ETH_NETWORK_ID",
"chainId": "$ETH_CHAIN_ID",
"time": { "start": "$START_TIME", "stop": "$STOP_TIME" }
}
EOF
if [[ -n "$TARGET_UID" ]] && [[ -n "$TARGET_GID" ]]; then
echo 'metadata.json' | cpio -p --owner $TARGET_UID:$TARGET_GID $DATABASE_FILE_CSV_DIR
else
cp metadata.json $DATABASE_FILE_CSV_DIR
fi
2023-04-27 03:58:28 +00:00
fi
exit $rc