From 421d089bab917691b5fc92076357926a6ac697cf Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Tue, 3 Dec 2024 11:17:26 +0100 Subject: [PATCH 1/2] debian packages: add script to download snapshot automatically --- docs/introduction/install-bin-deb.sh | 2 + scripts/packaging/octez/debian/control | 3 +- .../packaging/octez/debian/octez-node.config | 5 +- .../packaging/octez/debian/octez-node.install | 2 + .../packaging/octez/debian/octez-node.service | 1 + .../octez/debian/octez-node.templates | 53 +++++++----- .../octez/scripts/octez-node-prestart.sh | 50 +++++++++++ .../octez/scripts/snapshot-import.sh | 82 +++++++++++++++++++ 8 files changed, 175 insertions(+), 23 deletions(-) create mode 100755 scripts/packaging/octez/scripts/octez-node-prestart.sh create mode 100755 scripts/packaging/octez/scripts/snapshot-import.sh diff --git a/docs/introduction/install-bin-deb.sh b/docs/introduction/install-bin-deb.sh index fb0771de22ff..95e1cb166a5d 100755 --- a/docs/introduction/install-bin-deb.sh +++ b/docs/introduction/install-bin-deb.sh @@ -81,6 +81,8 @@ octez-node octez-node/configure string yes octez-node octez-node/history-mode string full octez-node octez-node/network string mainnet octez-node octez-node/purge_warning string yes +octez-node octez-node/snapshot-import boolean true +octez-node octez-node/snapshot-no-check boolean true debconf debconf/frontend select Noninteractive EOF # preseed the package diff --git a/scripts/packaging/octez/debian/control b/scripts/packaging/octez/debian/control index b97b1f3519f8..4bb9a47229cf 100644 --- a/scripts/packaging/octez/debian/control +++ b/scripts/packaging/octez/debian/control @@ -22,9 +22,10 @@ Depends: adduser, ${misc:Depends}, ${shlibs:Depends}, debconf (>= 0.5) | debconf-2.0, + curl, systemd Recommends: octez-client (= ${source:Version}), -Suggests: lz4, curl +Suggests: lz4 Description: L1 Octez node for the Tezos network This package serves as the core implementation for the Tezos blockchain node. It contains the fundamental components required for protocol execution, diff --git a/scripts/packaging/octez/debian/octez-node.config b/scripts/packaging/octez/debian/octez-node.config index 866495b5ee6c..3793d2371458 100755 --- a/scripts/packaging/octez/debian/octez-node.config +++ b/scripts/packaging/octez/debian/octez-node.config @@ -19,7 +19,10 @@ no) db_input high octez-node/network || true # shellcheck disable=SC2119 db_go || true - db_input high octez-node/snapshot_warning || true + db_input high octez-node/snapshot-import || true + # shellcheck disable=SC2119 + db_go || true + db_input medium octez-node/snapshot-no-check || true # shellcheck disable=SC2119 db_go || true ;; diff --git a/scripts/packaging/octez/debian/octez-node.install b/scripts/packaging/octez/debian/octez-node.install index fa0919382b0e..210dd605f7cd 100644 --- a/scripts/packaging/octez/debian/octez-node.install +++ b/scripts/packaging/octez/debian/octez-node.install @@ -1 +1,3 @@ binaries/octez-node /usr/bin/ +scripts/snapshot-import.sh /usr/share/octez-node/ +scripts/octez-node-prestart.sh /usr/share/octez-node/ diff --git a/scripts/packaging/octez/debian/octez-node.service b/scripts/packaging/octez/debian/octez-node.service index 037771911771..b47fb58e34a2 100644 --- a/scripts/packaging/octez/debian/octez-node.service +++ b/scripts/packaging/octez/debian/octez-node.service @@ -8,6 +8,7 @@ EnvironmentFile=-/etc/default/octez-node WorkingDirectory=/var/tezos Restart=on-failure User=tezos +ExecStartPre=/usr/share/octez-node/octez-node-prestart.sh ExecStart=/usr/bin/octez-node run --data-dir $DATADIR --log-output /var/log/tezos/node.log $RUNTIME_OPTS [Install] diff --git a/scripts/packaging/octez/debian/octez-node.templates b/scripts/packaging/octez/debian/octez-node.templates index 6609da009b90..c2d5450de949 100644 --- a/scripts/packaging/octez/debian/octez-node.templates +++ b/scripts/packaging/octez/debian/octez-node.templates @@ -18,6 +18,7 @@ Description: Select a mode for the node: Documentation: https://tezos.gitlab.io/user/history_modes.html Type: select Choices: rolling, full, archive +Default: rolling Template: octez-node/network Description: Select a network: @@ -36,26 +37,7 @@ Description: Select a network: Documentation: https://tezos.gitlab.io/user/multinetwork.html Type: select Choices: mainnet, ghostnet - -Template: octez-node/snapshot_warning -Type: note -Description: Important: Download and import a snapshot before starting the node - Before starting the node, you must import a recent snapshot of the current - blockchain state. If you start the node without importing a snapshot, it must - process every block since the blockchain genesis, which takes a very long - time. - . - You can download the latest snapshot from a trusted source (some suggestions in - snapshots doc linked below) and import it using the following command: - sudo su tezos -c "octez-node snapshot import " - . - After importing the snapshot, you can start the node using the following - command: - sudo systemctl start octez-node - . - - https://tezos.gitlab.io/user/snapshots.html - . - - https://tezos.gitlab.io/introduction/services.html +Default: mainnet Template: octez-node/purge_warning Description: Do you really want to remove all data: @@ -77,7 +59,10 @@ Description: Skipping node init: For example using the command: sudo su tezos -c "octez-node config init ..." . - And setting the desidered storage mode and network. + This allows you to set the desired storage mode and network according + to your requirements. + . + Skip if upgrading from Serokell packages. Type: select Choices: no, yes @@ -93,3 +78,29 @@ Description: Important upgrade information in /etc/default/octez-node have been revised and updated. . Please review the release notes for more information. + +Template: octez-node/snapshot-import +Type: boolean +Default: true +Description: Import the snapshot from snapshots.tzinit.org + This operation will download a recent snapshot from snapshots.tzinit.org when + starting the Octez Node from the network and import it using 'octez-node + snapshot import'. + . + If you choose not to proceed, you can run the import script later using the + following command: + . + sudo su tezos -c /usr/share/octez-node/snapshot-import.sh + . + The download and import time depends on the network speed and the available + system resources. + . + The snapshot size varies by network: Mainnet ~10GB, Ghostnet ~2GB. + . + Starting the node without a snapshot will bootstrap the node from genesis. + +Template: octez-node/snapshot-no-check +Type: boolean +Default: false +Description: Import the snapshot without checking + This option adds the '--no-check' flag to the snapshot import command. diff --git a/scripts/packaging/octez/scripts/octez-node-prestart.sh b/scripts/packaging/octez/scripts/octez-node-prestart.sh new file mode 100755 index 000000000000..d6d7beefc9e4 --- /dev/null +++ b/scripts/packaging/octez/scripts/octez-node-prestart.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +set -eu + +# Upgrade the storage before starting the node + +# Check if the script is run as the 'tezos' user +if [ "$(whoami)" != "tezos" ]; then + echo "Error: This script must be run as the 'tezos' user." + echo "This script is meant to run in the prestart section of octez-node.service" + echo "Run this script with sudo su tezos -c $0" + exit 1 +fi + +DATADIR=/var/tezos/.tezos-node + +# Function to get a Debconf value +get_debconf_value() { + PACKAGE=octez-node # Package name + TEMPLATE=$1 + + # Query the value using debconf-communicate + echo GET "$TEMPLATE" | + debconf-communicate "$PACKAGE" 2> /dev/null | awk '/^0/ {print $2}' +} + +# Either we upgrade the store if exists, or we import a snapshot + +if [ -d "$DATADIR/store" ]; then + echo "Storage upgrade. This might take some time." + octez-node upgrade storage + rm -rf "$DATADIR/lmdb_store_to_remove" +else + # we import the snapshot automatically only if the user wants to do so. + if [ "$(get_debconf_value "octez-node/snapshot-import")" = "true" ]; then + network=$(get_debconf_value "octez-node/network") + history_mode=$(get_debconf_value "octez-node/history-mode") + no_check= + if [ "$(get_debconf_value "octez-node/snapshot-no-check")" = "true" ]; then + no_check="-s --no-check" + fi + + # shellcheck disable=SC2086 + /usr/share/octez-node/snapshot-import.sh \ + -n "$network" \ + -h "$history_mode" \ + $no_check + + fi +fi diff --git a/scripts/packaging/octez/scripts/snapshot-import.sh b/scripts/packaging/octez/scripts/snapshot-import.sh new file mode 100755 index 000000000000..9ad0d51f2604 --- /dev/null +++ b/scripts/packaging/octez/scripts/snapshot-import.sh @@ -0,0 +1,82 @@ +#!/bin/sh + +set -eu + +# Check if the script is run as the 'tezos' user +if [ "$(whoami)" != "tezos" ]; then + echo "Error: This script must be run as the 'tezos' user." + echo "Run this script as sudo su tezos -c $0" + exit 1 +fi + +# Default values +NETWORK=mainnet +HISTORY_MODE=rolling +SNAPSHOT_NO_CHECK="" +DATADIR=/var/tezos/.tezos-node + +# Function to display help message +display_help() { + echo "Usage: $0 [options]" + echo + echo "Options:" + echo " -n NETWORK Specify the Tezos network (e.g., mainnet (default), ghostnet)." + echo " -h HISTORY_MODE Specify the history mode (e.g., rolling (default), full)." + echo " -s SNAPSHOT_OPTION Specify the snapshot import option (e.g., --no-check)." + echo " --help Display this help message." + echo + echo "Example:" + echo " $0 -n ghostnet -m rolling -s --no-check" + exit 0 +} + +# Parse command-line arguments +while [ "$#" -gt 0 ]; do + case "$1" in + -n) + NETWORK="$2" + shift 2 + ;; + -h) + HISTORY_MODE="$2" + shift 2 + ;; + -s) + SNAPSHOT_NO_CHECK="$2" + shift 2 + ;; + --help) + display_help + ;; + *) + echo "Unknown option: $1" + display_help + ;; + esac +done + +# We need access to the config.json as the tezos user. +# We simply check if the config file exist. But we don't +# try to update the octez node configuration. Trying to +# do anything automatically might lead to data loss. +if [ ! -e $DATADIR/config.json ]; then + echo "Init node in $DATADIR" + /usr/bin/octez-node config init --data-dir="$DATADIR" \ + --network="$NETWORK" \ + --history-mode="$HISTORY_MODE" \ + --net-addr="[::]:9732" \ + --rpc-addr="127.0.0.1:8732" +fi + +# Commands execution +echo "Downloading snapshot for network: $NETWORK, history mode: $HISTORY_MODE..." +curl -s -o "/tmp/$HISTORY_MODE" "https://snapshots.tzinit.org/$NETWORK/$HISTORY_MODE" + +echo "Importing snapshot with option: $SNAPSHOT_NO_CHECK..." +# shellcheck disable=SC2086 +octez-node snapshot import $SNAPSHOT_NO_CHECK "/tmp/$HISTORY_MODE" + +echo "Cleaning up temporary files..." +rm "/tmp/$HISTORY_MODE" + +echo "Snapshot import completed!" -- GitLab From 5dc8240b9cce16304cd66180f7f4ad0b4f3f8ed8 Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Tue, 10 Dec 2024 10:26:44 +0100 Subject: [PATCH 2/2] debian packages: rephase octez-node template --- scripts/packaging/octez/debian/octez-node.templates | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/packaging/octez/debian/octez-node.templates b/scripts/packaging/octez/debian/octez-node.templates index c2d5450de949..cf2813d256cb 100644 --- a/scripts/packaging/octez/debian/octez-node.templates +++ b/scripts/packaging/octez/debian/octez-node.templates @@ -2,11 +2,11 @@ Template: octez-node/history-mode Description: Select a mode for the node: The node can run in the following history modes: . - Rolling: Store only a rolling fragment of blockchain data so the node can - validate new blocks and stay in sync with the blockchain head. This mode - initializes the fastest and requires the least disk space. + Rolling: Store only a rolling fragment of blockchain data so the + node can validate new blocks and stay in sync with the blockchain head. This + mode initializes the fastest and requires the least disk space. . - Full (default): Store the minimum data to reconstruct the current state of the + Full: Store the minimum data to reconstruct the current state of the blockchain's ledger plus the full data for one previous cycle. This mode is appropriate for most uses including bakers and dApp developers who need a private node. -- GitLab