diff --git a/scripts/packaging/octez/debian/octez-baker.config b/scripts/packaging/octez/debian/octez-baker.config index ccabb7b54c4b201d0d17df8aaf534935176baf36..f878aebccbf7b833197926371851fdac54e8b775 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 @@ -18,18 +22,11 @@ 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 ;; *) - 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 diff --git a/scripts/packaging/octez/debian/octez-baker.postinst b/scripts/packaging/octez/debian/octez-baker.postinst index 702b0b7942343e58ab00631c7c28ebd467abfc78..a8dc1949a592ea3d84371f8c2aa119134e181f91 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 @@ -151,4 +119,6 @@ configure) ;; esac +systemctl daemon-reload || true + #DEBHELPER# diff --git a/scripts/packaging/octez/debian/octez-baker.preinst b/scripts/packaging/octez/debian/octez-baker.preinst index 62191265368c51739942ac9b48373db7cf0f50cf..ee6ee6e448161f31a2bfb48271919ed1928f64ac 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.prerm b/scripts/packaging/octez/debian/octez-baker.prerm index e5d9656d6a03207eec7f83d920e374e05c93609b..c359652643a0b5041ed17419517c6efd73fff3c4 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-baker.service b/scripts/packaging/octez/debian/octez-baker.service new file mode 100644 index 0000000000000000000000000000000000000000..ddbd8fe5a65fed57316d19abeff9683c04d7e146 --- /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/octez-baker.templates b/scripts/packaging/octez/debian/octez-baker.templates index fde89870f39716473004c6213f8280b7eb5c1081..0cbd464f5e5ff3c1c8f5768b1a7abe97b5146d1c 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 diff --git a/scripts/packaging/octez/debian/octez-node.postinst b/scripts/packaging/octez/debian/octez-node.postinst index 8320d4868ac64f302e542269f827437492414263..201f4749b3c53465d51d0edc93456449fe68c038 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 fe5e6dfa25bc331fcc6912d6bf381c3754c053e7..5857451f5c816e2c31252f5c110fd7ea4d0a1073 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 005a234cad937f4b3365f378e0d821ede0f438ad..31c81fc060d9ab2c18cf7bd4ddffe0d3d51656e0 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# diff --git a/scripts/packaging/octez/debian/rules b/scripts/packaging/octez/debian/rules index 1ddf9c4ad5253a60a052736aa3d7b64f15416c60..209a950aa63aa1ddf95933a2516bd8d7b698481c 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 diff --git a/scripts/packaging/tests/deb/install-bin-deb.sh b/scripts/packaging/tests/deb/install-bin-deb.sh index a082a44ebe56e57ff8356a6e027e7d03650d3148..8e2d87996f484532430ebfb35f61cd378b0d35cc 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 9bf19877c4a21fcbb1d48ed90c63158fc93ffb54..c9f5539b585d70a21352a26eefe071a1de107dd3 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