Skip to content

Commit

Permalink
feat: introduce archive node scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mrekucci committed Feb 6, 2025
1 parent a821a0c commit f5d7daa
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
23 changes: 23 additions & 0 deletions infrastructure/scripts/archive/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
BASE_DIR="/home/ubuntu/mainenv"
DATA_DIR="${BASE_DIR}/data/node-0"
ARTIFACTS_DIR="${BASE_DIR}/artifacts"
ARTIFACTS_URL="<artifacts_url>"
BIN_DIR="${BASE_DIR}/bin"
CONFIG_FILE="${ARTIFACTS_DIR}/config_v1.0.0.toml"
GENESIS_FILE="${ARTIFACTS_DIR}/genesis_v1.0.0.json"
GETH_ARCHIVE_TAR="${ARTIFACTS_DIR}/mev-commit-geth_v1.0.0_Linux_x86_64.tar.gz"
GETH_BIN="${BIN_DIR}/mev-commit-geth"
GETH_DATA_DIR="${DATA_DIR}"
GENESIS_L1_PATH="${GENESIS_FILE}"
GETH_LOG_FORMAT="json"
GETH_LOG_TAGS="service.name:mev-commit-geth-archive-node-0,service.version:v1.0.0"
GETH_STATE_SCHEME="path"
GETH_CONFIG="${CONFIG_FILE}"
GETH_BIN_PATH="${GETH_BIN}"
NODE_IP="0.0.0.0"
PUBLIC_NODE_IP="<public_node_ip>"
NET_RESTRICT="0.0.0.0/0"
GETH_NODE_TYPE="archive"
GETH_VERBOSITY=3
GETH_SYNC_MODE="full"
BOOTNODE_ENDPOINT="<bootnode_endpoint>"
43 changes: 43 additions & 0 deletions infrastructure/scripts/archive/archive-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

set -euo pipefail

download_artifact() {
local url=$1
local dest=$2
echo "Downloading ${url} to ${dest}..."
curl -fsSL "${url}" -o "${dest}"
}

ENV_FILE=".env"
if [[ -f "${ENV_FILE}" ]]; then
echo "Loading environment variables from $ENV_FILE..."
set -a
source "${ENV_FILE}"
set +a
else
echo "Error: $ENV_FILE not found." >&2
exit 1
fi

mkdir -p "${DATA_DIR}" "${ARTIFACTS_DIR}" "${BIN_DIR}"

download_artifact "${ARTIFACTS_URL}/config_v1.0.0.toml" "${CONFIG_FILE}"
download_artifact "${ARTIFACTS_URL}/genesis_v1.0.0.json" "${GENESIS_FILE}"
download_artifact "${ARTIFACTS_URL}/mev-commit-geth_v1.0.0_Linux_x86_64.tar.gz" "${GETH_ARCHIVE_TAR}"

if [[ ! -x "${GETH_BIN}" ]]; then
tar -xzf "${GETH_ARCHIVE_TAR}" -C "${BIN_DIR}"
chmod +x "${GETH_BIN}"
fi

GETH_ZERO_FEE_ADDRESSES="0x509b6a48fc573f0e987cb075cabee75d40e7db85"
GETH_ZERO_FEE_ADDRESSES+=",0xb8a1dac79f4674146a1e49f159107ee2817fdb81"
GETH_ZERO_FEE_ADDRESSES+=",0xf0e4285d437be60975149d5cac2dea49756a238b"
export GETH_ZERO_FEE_ADDRESSES
CHAIN_ID=$(cat "${GENESIS_FILE}" | jq -r .config.chainId)
export CHAIN_ID

echo "Starting node..."
chmod +x ${BIN_DIR}/entrypoint.sh
exec ${BIN_DIR}/entrypoint.sh
18 changes: 18 additions & 0 deletions infrastructure/scripts/archive/mev-commit-geth.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=MEV Commit Geth Archive Node
After=network.target

[Service]
User=ubuntu
WorkingDirectory=/home/ubuntu/mainenv
ExecStart=/home/ubuntu/mainenv/archive-node.sh

Restart=always
RestartSec=10

# Log output configuration: logs will be appended to these files
StandardOutput=append:/home/ubuntu/mainenv/mev-commit-geth.log
StandardError=append:/home/ubuntu/mainenv/mev-commit-geth.err.log

[Install]
WantedBy=multi-user.target
26 changes: 26 additions & 0 deletions infrastructure/scripts/archive/post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -e

SERVICE_NAME="mev-commit-geth"
MOUNT_POINT="/mnt/geth-data"

echo "=== Post-Snapshot Script: Unfreezing Filesystem and Starting ${SERVICE_NAME} ==="

echo "Unfreezing filesystem at ${MOUNT_POINT}..."
sudo fsfreeze -u "${MOUNT_POINT}"
echo "Filesystem unfrozen successfully."

echo "Starting ${SERVICE_NAME} service..."
sudo systemctl start "${SERVICE_NAME}"

if systemctl is-active --quiet "${SERVICE_NAME}"; then
echo "${SERVICE_NAME} service started successfully."
else
echo "Error: Failed to start ${SERVICE_NAME} service."
exit 1
fi

echo "=== Post-Snapshot Steps Completed Successfully ==="

exit 0
26 changes: 26 additions & 0 deletions infrastructure/scripts/archive/pre.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -e

SERVICE_NAME="mev-commit-geth"
MOUNT_POINT="/mnt/geth-data"

echo "=== Pre-Snapshot Script: Stopping ${SERVICE_NAME} and Freezing Filesystem ==="

echo "Stopping ${SERVICE_NAME} service..."
sudo systemctl stop "${SERVICE_NAME}"

if systemctl is-active --quiet "${SERVICE_NAME}"; then
echo "Error: ${SERVICE_NAME} service is still running."
exit 1
else
echo "${SERVICE_NAME} service stopped successfully."
fi

echo "Freezing filesystem at ${MOUNT_POINT}..."
sudo fsfreeze -f "${MOUNT_POINT}"
echo "Filesystem frozen successfully."

echo "=== Pre-Snapshot Steps Completed Successfully ==="

exit 0

0 comments on commit f5d7daa

Please sign in to comment.