diff --git a/docs/introduction/install-bin-deb.sh b/docs/introduction/install-bin-deb.sh index 8228d2569edeae36e87cbe6cd2e5f09f8ea38ed2..a55adee7031df86f669c110968d9f03a6f509c4d 100755 --- a/docs/introduction/install-bin-deb.sh +++ b/docs/introduction/install-bin-deb.sh @@ -18,70 +18,8 @@ else PREFIX= fi -#shellcheck disable=SC2317 -# Function to run apt-get with retries and exponential backoff for a specific error -apt_get_with_retries() { - set +x - # Maximum retries - max_retries=5 - # Initial delay in seconds - delay=1 - - # Loop for retries - for i in $(seq 1 "$max_retries"); do - - set +e - # Run apt-get and capture the output and exit status - output=$(apt-get "$@" 2>&1) - status=$? - set -e - - # Check if apt-get succeeded - if [ "$status" -eq 0 ]; then - echo "$output" - set -x - return 0 - fi - - case "$output" in - *"Mirror sync in progress"*) - retry=1 - ;; - *"Unknown error executing apt-key"*) - retry=1 - ;; - *) - retry=0 - ;; - esac - - #shellcheck disable=SC2181 - if [ "$retry" -eq 1 ]; then - # If the specific error occurs, retry with exponential backoff - echo "-----------" - echo "Attempt $i of $max_retries..." - echo "Error detected. Retrying in $delay seconds..." - echo "$output" - echo "-----------" - sleep "$delay" - # Exponential backoff (doubling the delay) - # 1 + 3 + 9 + 27 + 81 = 31, so we wait 121s maximum - # in total with max_retries = 5. - delay=$((delay * 3)) - else - # If the error is not the one we are looking for, exit with failure - echo "apt-get failed with an unexpected error. Exiting." - echo "$output" - exit 1 - fi - done - - echo "apt-get failed after $max_retries attempts." - exit 1 -} - -# Replace apt-get with the new function -alias apt-get="apt_get_with_retries" +# include apt-get function with retry +. scripts/packaging/tests/tests-common.inc.sh . scripts/ci/octez-packages-version.sh diff --git a/images/packages/debian-systemd-tests.Dockerfile b/images/packages/debian-systemd-tests.Dockerfile index 5923f9aba319da4d72c34c84edf35e7ed8f369e6..8cf113db824165c3e09690d654d54d89cbf584d1 100644 --- a/images/packages/debian-systemd-tests.Dockerfile +++ b/images/packages/debian-systemd-tests.Dockerfile @@ -12,10 +12,12 @@ COPY scripts/ci/systemd-entrypoint.service /etc/systemd/system/bash.service #hadolint ignore=DL3045 COPY scripts/ci/systemd-entrypoint.sh /entrypoint.sh #hadolint ignore=DL3045 -COPY docs/introduction/install-bin-deb.sh docs/introduction/install-bin-deb.sh -#hadolint ignore=DL3045 COPY scripts/ci/octez-packages-version.sh scripts/ci/octez-packages-version.sh #hadolint ignore=DL3045 +COPY scripts/packaging/tests/tests-common.inc.sh scripts/packaging/tests/tests-common.inc.sh +#hadolint ignore=DL3045 +COPY scripts/packaging/tests/tests-systemd-common.inc.sh scripts/packaging/tests/tests-systemd-common.inc.sh +#hadolint ignore=DL3045 COPY script-inputs/active_protocol_versions_without_number script-inputs/active_protocol_versions_without_number RUN chown root:root /entrypoint.sh \ && chmod 755 /entrypoint.sh \ diff --git a/images/packages/rpm-systemd-tests.Dockerfile b/images/packages/rpm-systemd-tests.Dockerfile index f6f18c227b6da34ade2e5d21491c0cba5aedd122..0e21c97fcc3ce124baba8a245e8a919ee1704025 100644 --- a/images/packages/rpm-systemd-tests.Dockerfile +++ b/images/packages/rpm-systemd-tests.Dockerfile @@ -16,6 +16,8 @@ COPY scripts/ci/systemd-entrypoint.sh /entrypoint.sh COPY scripts/ci/octez-packages-version.sh scripts/ci/octez-packages-version.sh #hadolint ignore=DL3045 COPY script-inputs/active_protocol_versions_without_number script-inputs/active_protocol_versions_without_number +#hadolint ignore=DL3045 +COPY scripts/packaging/tests/tests-systemd-common.inc.sh scripts/packaging/tests/tests-systemd-common.inc.sh RUN chown root:root /entrypoint.sh \ && chmod 755 /entrypoint.sh \ && chown root:root /etc/systemd/system/bash.service \ diff --git a/scripts/packaging/octez/debian/octez-baker.default b/scripts/packaging/octez/debian/octez-baker.default index 9e6e89537f5fd3325bd7f8867d18e09a1d51b108..1d5ddc13c9c9aa6fcbf0748cd4b3b56ae82f79f9 100644 --- a/scripts/packaging/octez/debian/octez-baker.default +++ b/scripts/packaging/octez/debian/octez-baker.default @@ -4,4 +4,4 @@ # Other options # Keep the daemon process alive -RUNTIME_OPTS="--keep-alive" +RUNTIME_OPTS="--keep-alive --dal-node http://127.0.0.1:10732" diff --git a/scripts/packaging/octez/debian/octez-baker.postinst b/scripts/packaging/octez/debian/octez-baker.postinst index 95060727a1fbeb722cb8fa2bdb9670ed76728d48..19d2317a427511eed7b7e437c8cf435d1e2e12cf 100755 --- a/scripts/packaging/octez/debian/octez-baker.postinst +++ b/scripts/packaging/octez/debian/octez-baker.postinst @@ -42,10 +42,10 @@ configure) true) db_get octez-baker/dal-node-url DALURL=${RET} - echo "RUNTIME_OPTS=\"--dal-node $DALURL\"" >> /etc/default/octez-baker + echo "RUNTIME_OPTS=\"--keep-alive --dal-node $DALURL\"" >> /etc/default/octez-baker ;; false) - echo "RUNTIME_OPTS=--without-dal" >> /etc/default/octez-baker + echo "RUNTIME_OPTS=--keep-alive --without-dal" >> /etc/default/octez-baker ;; esac @@ -78,12 +78,12 @@ configure) true) db_get octez-baker/dal-node-url DALURL=${RET} - echo "RUNTIME_OPTS=\"--dal-node $DALURL\"" >> /etc/default/octez-baker - echoerr "RUNTIME_OPTS=--dal-node $DALURL" + echo "RUNTIME_OPTS=\" --keep-alive --dal-node $DALURL\"" >> /etc/default/octez-baker + echoerr "RUNTIME_OPTS=--keep-alive --dal-node $DALURL" ;; false) - echo "RUNTIME_OPTS=--without-dal" >> /etc/default/octez-baker - echoerr "RUNTIME_OPTS=--without-dal" + echo "RUNTIME_OPTS=--keep-alive --without-dal" >> /etc/default/octez-baker + echoerr "RUNTIME_OPTS=--keep-alive --without-dal" ;; esac diff --git a/scripts/packaging/octez/debian/octez-baker.service b/scripts/packaging/octez/debian/octez-baker.service index 15b26a76118c96730a492e737da58cab6e484ed1..6562dd0263d683460ee6531ec234e7b97cb07efa 100644 --- a/scripts/packaging/octez/debian/octez-baker.service +++ b/scripts/packaging/octez/debian/octez-baker.service @@ -4,7 +4,6 @@ After=network.target [Service] Type=oneshot -ExecStart=/bin/true RemainAfterExit=yes Restart=on-failure TimeoutStartSec=300 @@ -16,8 +15,8 @@ EnvironmentFile=-/etc/default/octez-baker # The baker is started only if the node is up and running ExecStartPre=/usr/share/octez-baker/wait-for-node-up.sh -ExecStartPre=/usr/share/octez-baker/systemd-octez-bakers.sh start -ExecStopPost=/usr/share/octez-baker/systemd-octez-bakers.sh stop +ExecStart=/usr/share/octez-baker/systemd-octez-bakers.sh start +ExecStop=/usr/share/octez-baker/systemd-octez-bakers.sh stop [Install] WantedBy=multi-user.target diff --git a/scripts/packaging/octez/debian/octez-baker@.service b/scripts/packaging/octez/debian/octez-baker@.service index c922a3139f25be333aae79bbad397c689e6f23e6..d21b1937f5749066432efcddf2455be672d87ae0 100644 --- a/scripts/packaging/octez/debian/octez-baker@.service +++ b/scripts/packaging/octez/debian/octez-baker@.service @@ -12,7 +12,7 @@ Restart=on-failure User=tezos # We wrap the command in /bin/sh to identify the baker associated to $PROTOCOL -ExecStart=/bin/sh -c "/usr/bin/octez-baker-%i --base-dir /var/tezos/.tezos-client run with local node $DATADIR --liquidity-baking-toggle-vote $LQVOTE $RUNTIME_OPTS $BAKING_KEY" +ExecStart=/bin/sh -c "/usr/bin/octez-baker-%i --base-dir $HOME/.tezos-client run with local node $DATADIR --liquidity-baking-toggle-vote $LQVOTE $RUNTIME_OPTS $BAKING_KEY" ExecStartPre=+touch /var/log/tezos/baker-%i.log ExecStartPre=+chown tezos:tezos /var/log/tezos/baker-%i.log diff --git a/scripts/packaging/octez/debian/rules b/scripts/packaging/octez/debian/rules index 0dcda9ed861d832034f7356b3da5c7d03a824dad..141457694cb8d4beb495d5455c86e5c604c29347 100755 --- a/scripts/packaging/octez/debian/rules +++ b/scripts/packaging/octez/debian/rules @@ -43,6 +43,8 @@ override_dh_installlogrotate: override_dh_install: dh_install + mkdir -p debian/octez-baker/etc/default/ + cp debian/octez-baker.octez-accuser.default debian/octez-baker/etc/default/octez-accuser dh_installdebconf override_dh_fixperms: diff --git a/scripts/packaging/octez/scripts/systemd-octez-bakers.sh b/scripts/packaging/octez/scripts/systemd-octez-bakers.sh index f884f5bf43e7d8bd7b06e37fd99f1e1ba07de71e..ee5e7d10b6a7b69120af9eed24eec2b9eb4c6062 100755 --- a/scripts/packaging/octez/scripts/systemd-octez-bakers.sh +++ b/scripts/packaging/octez/scripts/systemd-octez-bakers.sh @@ -20,10 +20,14 @@ for file in /usr/bin/octez-baker-P*; do systemctl start octez-dal-node fi systemctl enable "octez-baker@$proto" + systemctl enable "octez-accuser@$proto" systemctl start "octez-baker@$proto" + systemctl start "octez-accuser@$proto" + elif [ "$1" = "stop" ]; then systemctl stop "octez-baker@$proto" - if grep -q '--dal-node' /etc/default/octez-baker; then + systemctl stop "octez-accuser@$proto" + if grep -q "\-\-dal-node" /etc/default/octez-baker; then systemctl stop octez-dal-node fi fi diff --git a/scripts/packaging/tests/deb/install-bin-deb.sh b/scripts/packaging/tests/deb/install-bin-deb.sh index c74c4e306dfc4e75dc13b934ed784391d55b35eb..901537ee51dcb048a0880a86bbccb4b17060cc78 100755 --- a/scripts/packaging/tests/deb/install-bin-deb.sh +++ b/scripts/packaging/tests/deb/install-bin-deb.sh @@ -8,6 +8,9 @@ DISTRO=$1 RELEASE=$2 DATADIR=${3:-} +# include apt-get function with retry +. scripts/packaging/tests/tests-common.inc.sh + # For the upgrade script in the CI, we do not want debconf to ask questions export DEBIAN_FRONTEND=noninteractive @@ -19,7 +22,7 @@ sudo curl "$REPO/$DISTRO/octez.asc" | sudo gpg --dearmor -o /etc/apt/trusted.gpg # [add next repository] repository="deb $REPO/$DISTRO $RELEASE main" echo "$repository" | sudo tee /etc/apt/sources.list.d/octez-next.list -sudo apt-get update +apt-get update # [ preeseed octez ] if [ -z "$PREFIX" ]; then @@ -43,7 +46,7 @@ EOF sudo debconf-get-selections | grep octez fi -sudo apt-get install -y octez-baker +apt-get install -y octez-baker if [ -n "$DATADIR" ]; then echo "Setup Custom data dir" @@ -54,36 +57,6 @@ if [ -n "$DATADIR" ]; then echo "DATADIR=/custom/.tezos-node" >> /etc/default/octez-node fi -sudo systemctl start octez-node.service -sudo systemctl status octez-node.service - -# give some time to the node to create the identity -# otherwise the octez-client call below will give an error -/usr/share/octez-baker/wait-for-node-up.sh - -sudo su tezos -c "octez-client gen keys alice" -key=$(sudo su tezos -c "octez-client show address alice" | grep Hash: | awk '{ print $2 }') -echo "BAKER_KEY=$key" >> /etc/default/octez-baker - -sudo systemctl enable octez-baker -sudo systemctl start octez-baker.service - -sudo systemctl status octez-baker.service - -sudo systemctl status octez-baker.service - -sudo su tezos -c "octez-node config show" - -echo "-----------------------" -cat /etc/default/octez-node - -echo "-----------------------" -cat /etc/default/octez-baker - -echo "-----------------------" -tail /var/log/tezos/node.log - -echo "-----------------------" -for logfile in /var/log/tezos/baker-P*.log; do - tail "$logfile" -done +# This file include the systemd tests and diagnistic common +# to both rpm and deb +. scripts/packaging/tests/tests-systemd-common.inc.sh diff --git a/scripts/packaging/tests/deb/upgrade-systemd-test.sh b/scripts/packaging/tests/deb/upgrade-systemd-test.sh index f63fe7d378c1e17effd48cb020fad157ae55f5eb..66313b13badb2f88147d50ad7f52389a27f2bbaa 100755 --- a/scripts/packaging/tests/deb/upgrade-systemd-test.sh +++ b/scripts/packaging/tests/deb/upgrade-systemd-test.sh @@ -8,6 +8,9 @@ REPOOLD="https://storage.googleapis.com/$GCP_LINUX_PACKAGES_BUCKET/old/$CI_COMMI DISTRO=$1 RELEASE=$2 +# include apt-get function with retry +. scripts/packaging/tests/tests-common.inc.sh + # For the upgrade script in the CI, we do not want debconf to ask questions export DEBIAN_FRONTEND=noninteractive @@ -22,12 +25,12 @@ sudo curl "$REPOOLD/$DISTRO/octez.asc" | sudo gpg --dearmor -o /etc/apt/trusted. reposityory="deb $REPOOLD/$DISTRO $RELEASE main" echo "$reposityory" | sudo tee /etc/apt/sources.list.d/octez-current.list -sudo apt-get update +apt-get update # [install octez] -sudo apt-get install -y octez-client -sudo apt-get install -y octez-node -sudo apt-get install -y octez-baker +apt-get install -y octez-client +apt-get install -y octez-node +apt-get install -y octez-baker dpkg -l octez-\* # [setup Octez node] @@ -60,25 +63,25 @@ sudo su tezos -c "octez-node config show" # [add next repository] repository="deb $REPO/$DISTRO $RELEASE main" echo "$repository" | sudo tee /etc/apt/sources.list.d/octez-next.list -sudo apt-get update +apt-get update # [upgrade octez] # --force-overwrite is necessary because legacy package shipped the zcash # parameters as part of the octez-node package. -sudo apt-get upgrade -y -o DPkg::options::="--force-overwrite" octez-baker +apt-get upgrade -y -o DPkg::options::="--force-overwrite" octez-baker cat /etc/default/octez-node cat /etc/default/octez-baker -sudo systemctl restart octez-node.service -sudo systemctl status octez-node.service +systemctl restart octez-node.service +systemctl status octez-node.service -sudo systemctl enable octez-baker -sudo systemctl restart octez-baker.service +systemctl enable octez-baker +systemctl restart octez-baker.service -sudo systemctl status octez-baker.service +systemctl status octez-baker.service -sudo systemctl status octez-baker.service +systemctl status octez-baker.service ERR=0 diff --git a/scripts/packaging/tests/rpm/rpm-install.sh b/scripts/packaging/tests/rpm/rpm-install.sh index f3a04668c6d282e8c576d14f2efea938b560b860..b7d4f7c8b400b133a0c0dc3a4511778a0b378d37 100755 --- a/scripts/packaging/tests/rpm/rpm-install.sh +++ b/scripts/packaging/tests/rpm/rpm-install.sh @@ -43,6 +43,9 @@ echo "SNAPSHOT_NO_CHECK=" >> /etc/default/octez-node #shellcheck disable=SC1091 . /etc/default/octez-node +echo "RUNTIME_OPTS=\"--keep-alive --dal-node http://127.0.0.1:10732\"" >> /etc/default/octez-baker +echo "LQVOTE=off" >> /etc/default/octez-baker + rm -f "$DATADIR/config.json" su tezos -c "/usr/bin/octez-node config init \ --data-dir=$DATADIR \ @@ -54,30 +57,8 @@ su tezos -c "/usr/bin/octez-node config init \ # if systemd is available we test the service scripts if [ "$(ps --no-headers -o comm 1)" = "systemd" ]; then - systemctl enable octez-node - systemctl start octez-node - - systemctl enable octez-baker - systemctl start octez-baker.service - - systemctl status octez-baker.service - - sudo su tezos -c "octez-node config show" - - echo "-----------------------" - cat /etc/default/octez-node - - echo "-----------------------" - cat /etc/default/octez-baker - - echo "-----------------------" - tail /var/log/tezos/node.log - - echo "-----------------------" - for logfile in /var/log/tezos/baker-P*.log; do - if [ -e "$logfile" ]; then - tail "$logfile" - fi - done + # This file include the systemd tests and diagnistic common + # to both rpm and deb + . scripts/packaging/tests/tests-systemd-common.inc.sh fi diff --git a/scripts/packaging/tests/tests-common.inc.sh b/scripts/packaging/tests/tests-common.inc.sh new file mode 100644 index 0000000000000000000000000000000000000000..a70ab48ce94fa463e56b42666d9865d06c2f4a0e --- /dev/null +++ b/scripts/packaging/tests/tests-common.inc.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +#shellcheck disable=SC2317 +# Function to run apt-get with retries and exponential backoff for a specific error +apt_get_with_retries() { + set +x + # Maximum retries + max_retries=5 + # Initial delay in seconds + delay=1 + + # Loop for retries + for i in $(seq 1 "$max_retries"); do + + set +e + # Run apt-get and capture the output and exit status + output=$(apt-get "$@" 2>&1) + status=$? + set -e + + # Check if apt-get succeeded + if [ "$status" -eq 0 ]; then + echo "$output" + set -x + return 0 + fi + + case "$output" in + *"Mirror sync in progress"*) + retry=1 + ;; + *"Unknown error executing apt-key"*) + retry=1 + ;; + *) + retry=0 + ;; + esac + + #shellcheck disable=SC2181 + if [ "$retry" -eq 1 ]; then + # If the specific error occurs, retry with exponential backoff + echo "-----------" + echo "Attempt $i of $max_retries..." + echo "Error detected. Retrying in $delay seconds..." + echo "$output" + echo "-----------" + sleep "$delay" + # Exponential backoff (doubling the delay) + # 1 + 3 + 9 + 27 + 81 = 31, so we wait 121s maximum + # in total with max_retries = 5. + delay=$((delay * 3)) + else + # If the error is not the one we are looking for, exit with failure + echo "apt-get failed with an unexpected error. Exiting." + echo "$output" + exit 1 + fi + done + + echo "apt-get failed after $max_retries attempts." + exit 1 +} + +# Replace apt-get with the new function +alias apt-get="apt_get_with_retries" diff --git a/scripts/packaging/tests/tests-systemd-common.inc.sh b/scripts/packaging/tests/tests-systemd-common.inc.sh new file mode 100644 index 0000000000000000000000000000000000000000..76dff7855d36b4e54caa6d1e4f0c080f48f6f222 --- /dev/null +++ b/scripts/packaging/tests/tests-systemd-common.inc.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +set -eu + +systemctl start octez-node.service + +# give some time to the node to create the identity +# otherwise the octez-client call below will give an error +/usr/share/octez-baker/wait-for-node-up.sh + +su tezos -c "octez-client gen keys alice" +key=$(su tezos -c "octez-client show address alice" | grep Hash: | awk '{ print $2 }') +echo "BAKER_KEY=$key" >> /etc/default/octez-baker + +systemctl start octez-baker.service + +su tezos -c "octez-node config show" + +echo "-----------------------" +cat /etc/default/octez-node + +echo "-----------------------" +cat /etc/default/octez-baker + +systemctl status octez-node.service +echo "Log: /var/log/tezos/node.log" +echo "-----------------------" +tail /var/log/tezos/node.log + +systemctl status octez-baker.service + +for logfile in /var/log/tezos/baker-P*.log; do + proto=$(basename "$logfile" | sed -E 's/baker-(P[^.]+).log/\1/') + systemctl status "octez-baker@$proto.service" + echo "Log: $logfile" + echo "-----------------------" + tail "$logfile" +done + +for logfile in /var/log/tezos/accuser-P*.log; do + proto=$(basename "$logfile" | sed -E 's/accuser-(P[^.]+).log/\1/') + systemctl status "octez-accuser@$proto.service" + echo "Log: $logfile" + echo "-----------------------" + tail "$logfile" +done