From 3c4a5dcd7661bc41185b56e55abf1d3f52335d8f Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Thu, 27 Feb 2025 11:24:36 +0100 Subject: [PATCH 1/5] packages: add one baker service to run them all --- .../octez/debian/octez-baker.service | 25 +++++++++++++++++++ scripts/packaging/octez/debian/rules | 1 + 2 files changed, 26 insertions(+) create mode 100644 scripts/packaging/octez/debian/octez-baker.service diff --git a/scripts/packaging/octez/debian/octez-baker.service b/scripts/packaging/octez/debian/octez-baker.service new file mode 100644 index 000000000000..ddbd8fe5a65f --- /dev/null +++ b/scripts/packaging/octez/debian/octez-baker.service @@ -0,0 +1,25 @@ +[Unit] +Description=Octez baker service +After=network.target +Requires=octez-baker-active.service octez-baker-next.service octez-accuser-active.service octez-accuser-next.service + +[Service] +Type=oneshot +ExecStart=/bin/true +RemainAfterExit=yes +Restart=on-failure +TimeoutStartSec=300 +TimeoutStopSec=300 + +ExecStartPre=systemctl start octez-baker-active.service +ExecStartPre=systemctl start octez-baker-next.service +ExecStartPre=systemctl start octez-accuser-active.service +ExecStartPre=systemctl start octez-accuser-next.service + +ExecStopPost=systemctl stop octez-baker-active.service +ExecStopPost=systemctl stop octez-baker-next.service +ExecStopPost=systemctl stop octez-accuser-active.service +ExecStopPost=systemctl stop octez-accuser-next.service + +[Install] +WantedBy=multi-user.target diff --git a/scripts/packaging/octez/debian/rules b/scripts/packaging/octez/debian/rules index 1ddf9c4ad525..209a950aa63a 100755 --- a/scripts/packaging/octez/debian/rules +++ b/scripts/packaging/octez/debian/rules @@ -38,6 +38,7 @@ override_dh_installsystemd: dh_installsystemd -p octez-baker --no-enable --no-start --name octez-baker-next dh_installsystemd -p octez-baker --no-enable --no-start --name octez-accuser-next dh_installsystemd -p octez-baker --no-enable --no-start --name octez-accuser-active + dh_installsystemd -p octez-baker --no-start override_dh_installlogrotate: dh_installlogrotate --package=octez-node -- GitLab From 422e1232fd05b6354c584aec05779b2514b72256 Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Thu, 27 Feb 2025 11:52:50 +0100 Subject: [PATCH 2/5] packages: remove user choice for active and next protocol --- .../packaging/octez/debian/octez-baker.config | 7 --- .../octez/debian/octez-baker.postinst | 50 ++++--------------- .../octez/debian/octez-baker.preinst | 7 --- .../octez/debian/octez-baker.templates | 18 ------- 4 files changed, 9 insertions(+), 73 deletions(-) diff --git a/scripts/packaging/octez/debian/octez-baker.config b/scripts/packaging/octez/debian/octez-baker.config index ccabb7b54c4b..7a5b94d938f4 100755 --- a/scripts/packaging/octez/debian/octez-baker.config +++ b/scripts/packaging/octez/debian/octez-baker.config @@ -18,13 +18,6 @@ case "$new" in . /etc/default/octez-baker-active db_set octez-baker/liquidity-vote "$LQVOTE" db_set octez-baker/baker-key "$BAKER_KEY" - db_set octez-baker/baker-active-protocol "$PROTOCOL" - fi - - if [ -e /etc/default/octez-baker-next ]; then - #shellcheck disable=SC1091 - . /etc/default/octez-baker-next - db_set octez-baker/baker-next-protocol "$PROTOCOL" fi ;; *) diff --git a/scripts/packaging/octez/debian/octez-baker.postinst b/scripts/packaging/octez/debian/octez-baker.postinst index 702b0b794234..2c88e05ceb5e 100755 --- a/scripts/packaging/octez/debian/octez-baker.postinst +++ b/scripts/packaging/octez/debian/octez-baker.postinst @@ -18,14 +18,13 @@ for file in /usr/bin/octez-baker-*; do if [ -z "$PROTO_CHOICES" ]; then PROTO_CHOICES="$suffix" else - PROTO_CHOICES="$PROTO_CHOICES, $suffix" + PROTO_CHOICES="$PROTO_CHOICES $suffix" fi done # we guess the active protocol -ACTIVE_PROTOCOL=$(echo "$PROTO_CHOICES" | tr ' ' '\n' | grep -v '^alpha$' | sort | head -n 1) -db_subst octez-baker/baker-active-protocol choices "$PROTO_CHOICES" -db_subst octez-baker/baker-next-protocol choices "none, $PROTO_CHOICES" +ACTIVE_PROTOCOL=$(echo "$PROTO_CHOICES" | tr ' ' '\n' | grep -v '^(alpha|next)$' | sort | head -n 1) +NEXT_PROTOCOL=$(echo "$PROTO_CHOICES" | tr ' ' '\n' | grep -v '^(alpha|next)$' | sort | head -n 2 | tail -n 1) case "${1}" in configure) @@ -39,27 +38,12 @@ configure) echo "LQVOTE=${RET}" > /etc/default/octez-baker-active echo "LQVOTE=${RET}" > /etc/default/octez-baker-next - db_input medium octez-baker/baker-active-protocol || true - # shellcheck disable=SC2119 - db_go || true - - db_input medium octez-baker/baker-next-protocol || true - # shellcheck disable=SC2119 - db_go || true - db_get octez-baker/baker-key echo "BAKER_KEY=${RET}" >> /etc/default/octez-baker-active echo "BAKER_KEY=${RET}" >> /etc/default/octez-baker-next - db_get octez-baker/baker-active-protocol - echo "PROTOCOL=${RET}" >> /etc/default/octez-baker-active - - db_get octez-baker/baker-next-protocol - if [ -n "${RET:-}" ]; then - echo "PROTOCOL=${RET}" >> /etc/default/octez-baker-next - else - echo "#PROTOCOL=${RET}" >> /etc/default/octez-baker-next - fi + echo "PROTOCOL=${ACTIVE_PROTOCOL}" >> /etc/default/octez-baker-active + echo "PROTOCOL=${NEXT_PROTOCOL}" >> /etc/default/octez-baker-next db_get octez-baker/dal-node DAL=${RET} @@ -91,26 +75,10 @@ configure) echoerr "Setting defaults in /etc/default/octez-baker-*" echoerr "Migrating values when possible" - db_set octez-baker/baker-active-protocol "$ACTIVE_PROTOCOL" - - db_input medium octez-baker/baker-active-protocol || true - # shellcheck disable=SC2119 - db_go || true - - db_input medium octez-baker/baker-next-protocol || true - # shellcheck disable=SC2119 - db_go || true - - db_get octez-baker/baker-active-protocol - echo "PROTOCOL=${RET}" >> /etc/default/octez-baker-active - - db_get octez-baker/baker-next-protocol - if [ -n "${RET:-}" ]; then - echo "PROTOCOL=${RET}" >> /etc/default/octez-baker-next - else - echo "#PROTOCOL=${RET}" >> /etc/default/octez-baker-next - fi - echoerr "PROTOCOL=${RET}" + echo "PROTOCOL=${ACTIVE_PROTOCOL}" >> /etc/default/octez-baker-active + echoerr "ACTIVE PROTO=${ACTIVE_PROTOCOL}" + echo "PROTOCOL=${NEXT_PROTOCOL}" >> /etc/default/octez-baker-next + echoerr "NEXT PROTO=${NEXT_PROTOCOL}" db_get octez-baker/liquidity-vote echo "LQVOTE=${RET}" >> /etc/default/octez-baker-active diff --git a/scripts/packaging/octez/debian/octez-baker.preinst b/scripts/packaging/octez/debian/octez-baker.preinst index 62191265368c..ee6ee6e44816 100755 --- a/scripts/packaging/octez/debian/octez-baker.preinst +++ b/scripts/packaging/octez/debian/octez-baker.preinst @@ -26,13 +26,6 @@ install | upgrade) . /etc/default/octez-baker-active db_set octez-baker/liquidity-vote "$LQVOTE" db_set octez-baker/baker-key "$BAKER_KEY" - db_set octez-baker/baker-active-protocol "$PROTOCOL" - fi - - if [ -e /etc/default/octez-baker-next ]; then - #shellcheck disable=SC1091 - . /etc/default/octez-baker-next - db_set octez-baker/baker-next-protocol "$PROTOCOL" fi ;; *) diff --git a/scripts/packaging/octez/debian/octez-baker.templates b/scripts/packaging/octez/debian/octez-baker.templates index fde89870f397..0cbd464f5e5f 100644 --- a/scripts/packaging/octez/debian/octez-baker.templates +++ b/scripts/packaging/octez/debian/octez-baker.templates @@ -15,24 +15,6 @@ Description: The baker key to associate to this baker: can also be added later while configuring the baker. Type: string -Template: octez-baker/baker-active-protocol -Description: The active protocol associated to the baker: - Bakers use the current protocol of mainnet/ghostnet for production/staging, respectively. -Type: select -Choices: ${choices} - -Template: octez-baker/baker-next-protocol -Description: The next protocol associated to the baker upon activation: - This is the next adopted mainnet protocol. Upon activation - both the baker for the active protocol and the next protocol must be running - at the same time. You can choose the value "none" if you don't know - what to choose now. - . - After activation you can re-configure the package to stop the baker for the - old protocol and mark the freshly activated protocol as active. -Type: select -Choices: ${choices} - Template: octez-baker/dal-node Type: boolean Default: true -- GitLab From 9357ec7dcdfc813a05f09110b0bc20e0fb320b64 Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Thu, 27 Feb 2025 12:56:27 +0100 Subject: [PATCH 3/5] packages: remove printout on config script --- scripts/packaging/octez/debian/octez-baker.config | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/packaging/octez/debian/octez-baker.config b/scripts/packaging/octez/debian/octez-baker.config index 7a5b94d938f4..f878aebccbf7 100755 --- a/scripts/packaging/octez/debian/octez-baker.config +++ b/scripts/packaging/octez/debian/octez-baker.config @@ -11,6 +11,10 @@ new=${2:-} db_version 2.0 case "$new" in +"") + # fresh install + : nop + ;; 1:*) echoerr "Upgrade from $new" if [ -e /etc/default/octez-baker-active ]; then @@ -21,8 +25,8 @@ case "$new" in fi ;; *) - echoerr "Legacy upgrade from $new" if [ -e /etc/octez/baker.conf ]; then + echoerr "Legacy upgrade from $new" echoerr "Updating baker configuration from old /etc/octez/baker.conf" # the values set here in debconf are going to be used in the # postinst script to write the /etc/default/ files for this -- GitLab From 29ae45bc63401f1c8b2de3fbf9ebc224cb958ba7 Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Thu, 27 Feb 2025 14:29:42 +0100 Subject: [PATCH 4/5] package: make sure to stop the octez-baker service --- .../packaging/octez/debian/octez-baker.postinst | 2 ++ scripts/packaging/octez/debian/octez-baker.prerm | 14 ++++++++++---- scripts/packaging/octez/debian/octez-node.postinst | 2 ++ scripts/packaging/octez/debian/octez-node.postrm | 3 ++- scripts/packaging/octez/debian/octez-node.prerm | 8 ++++++-- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/scripts/packaging/octez/debian/octez-baker.postinst b/scripts/packaging/octez/debian/octez-baker.postinst index 2c88e05ceb5e..a8dc1949a592 100755 --- a/scripts/packaging/octez/debian/octez-baker.postinst +++ b/scripts/packaging/octez/debian/octez-baker.postinst @@ -119,4 +119,6 @@ configure) ;; esac +systemctl daemon-reload || true + #DEBHELPER# diff --git a/scripts/packaging/octez/debian/octez-baker.prerm b/scripts/packaging/octez/debian/octez-baker.prerm index e5d9656d6a03..c359652643a0 100755 --- a/scripts/packaging/octez/debian/octez-baker.prerm +++ b/scripts/packaging/octez/debian/octez-baker.prerm @@ -5,21 +5,27 @@ set -e # shellcheck disable=SC1091 . /usr/share/debconf/confmodule +# systemctl should not be called directly. use this +# wrapper script if available +debsystemctl=$(command -v deb-systemd-invoke || echo systemctl) + for s in baker accuser; do # Check if the old daemon is active before stopping it - if systemctl is-active --quiet "octez-$s.service"; then + if $debsystemctl is-active --quiet "octez-$s.service"; then echo "Stopping old octez-$s" - sudo systemctl stop "octez-$s.service" + $debsystemctl stop "octez-$s.service" fi for p in active next; do # Check if the daemon is active before stopping it - if systemctl is-active --quiet "octez-$s-$p.service"; then + if $debsystemctl is-active --quiet "octez-$s-$p.service"; then # Set a flag in a temporary file to indicate the daemon was running touch "/run/octez-baker/$s-$p-daemon_was_running" echo "Stopping octez-$s-$p" - sudo systemctl stop "octez-$s-$p.service" + $debsystemctl stop "octez-$s-$p.service" fi done + + $debsystemctl stop "octez-baker.service" || true done diff --git a/scripts/packaging/octez/debian/octez-node.postinst b/scripts/packaging/octez/debian/octez-node.postinst index 8320d4868ac6..201f4749b3c5 100755 --- a/scripts/packaging/octez/debian/octez-node.postinst +++ b/scripts/packaging/octez/debian/octez-node.postinst @@ -114,4 +114,6 @@ if [ -f /var/lib/octez-node/daemon_was_running ] && rm /var/lib/octez-node/daemon_was_running fi +systemctl daemon-reload || true + #DEBHELPER# diff --git a/scripts/packaging/octez/debian/octez-node.postrm b/scripts/packaging/octez/debian/octez-node.postrm index fe5e6dfa25bc..5857451f5c81 100755 --- a/scripts/packaging/octez/debian/octez-node.postrm +++ b/scripts/packaging/octez/debian/octez-node.postrm @@ -26,6 +26,7 @@ purge) db_get octez-node/purge_warning || true case "$RET" in true) + $debsystemctl stop octez-node.service || true echo "Removing data and tezos user" rm -Rf "$DATADIR" deluser --quiet tezos || true @@ -33,8 +34,8 @@ purge) rm -Rf /var/log/tezos ;; *) + $debsystemctl stop octez-node.service || true echo "Keep user and datadir while $1" - echo "User said $RET" ;; esac rm -Rf /run/octez-node diff --git a/scripts/packaging/octez/debian/octez-node.prerm b/scripts/packaging/octez/debian/octez-node.prerm index 005a234cad93..31c81fc060d9 100755 --- a/scripts/packaging/octez/debian/octez-node.prerm +++ b/scripts/packaging/octez/debian/octez-node.prerm @@ -5,6 +5,10 @@ set -e # shellcheck disable=SC1091 . /usr/share/debconf/confmodule +# systemctl should not be called directly. use this +# wrapper script if available +debsystemctl=$(command -v deb-systemd-invoke || echo systemctl) + case "$1" in remove) # display a warning before proceding @@ -20,11 +24,11 @@ upgrade | deconfigure | failed-upgrade) ;; esac # Check if the daemon is active before stopping it -if systemctl is-active --quiet octez-node.service; then +if $debsystemctl is-active --quiet octez-node.service; then # Set a flag in a temporary file to indicate the daemon was running touch /run/octez-node/daemon_was_running echo "Stopping octez-node" - sudo systemctl stop octez-node.service + $debsystemctl stop octez-node.service fi #DEBHELPER# -- GitLab From 4407b168ed543ad7516d4315bafbf013852c3dc9 Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Thu, 27 Feb 2025 15:16:10 +0100 Subject: [PATCH 5/5] packages: adapt test to start the octez-baker service --- scripts/packaging/tests/deb/install-bin-deb.sh | 7 +++++-- scripts/packaging/tests/deb/upgrade-systemd-test.sh | 10 ++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/packaging/tests/deb/install-bin-deb.sh b/scripts/packaging/tests/deb/install-bin-deb.sh index a082a44ebe56..8e2d87996f48 100755 --- a/scripts/packaging/tests/deb/install-bin-deb.sh +++ b/scripts/packaging/tests/deb/install-bin-deb.sh @@ -54,7 +54,6 @@ if [ -n "$DATADIR" ]; then echo "DATADIR=/custom/.tezos-node" >> /etc/default/octez-node fi -sudo systemctl enable octez-node sudo systemctl start octez-node.service sudo systemctl status octez-node.service @@ -67,8 +66,12 @@ key=$(sudo su tezos -c "octez-client show address alice" | grep Hash: | awk '{ p echo "BAKER_KEY=$key" >> /etc/default/octez-baker-active sudo systemctl enable octez-baker-active -sudo systemctl start octez-baker-active.service +sudo systemctl start octez-baker.service + +sudo systemctl status octez-baker.service + sudo systemctl status octez-baker-active.service +sudo systemctl status octez-baker-next.service sudo su tezos -c "octez-node config show" diff --git a/scripts/packaging/tests/deb/upgrade-systemd-test.sh b/scripts/packaging/tests/deb/upgrade-systemd-test.sh index 9bf19877c4a2..c9f5539b585d 100755 --- a/scripts/packaging/tests/deb/upgrade-systemd-test.sh +++ b/scripts/packaging/tests/deb/upgrade-systemd-test.sh @@ -67,17 +67,19 @@ sudo apt-get update # parameters as part of the octez-node package. sudo apt-get upgrade -y -o DPkg::options::="--force-overwrite" octez-baker -sudo systemctl enable octez-node -sudo systemctl enable octez-baker-active - cat /etc/default/octez-node cat /etc/default/octez-baker-active sudo systemctl restart octez-node.service sudo systemctl status octez-node.service -sudo systemctl restart octez-baker-active.service +sudo systemctl enable octez-baker-active +sudo systemctl restart octez-baker.service + +sudo systemctl status octez-baker.service + sudo systemctl status octez-baker-active.service +sudo systemctl status octez-baker-next.service ERR=0 -- GitLab