portable: add 'reattach' verb and DBUS interface
Add 'reattach' verb to portablectl, and corresponding DBUS interface to systemd-portabled. Takes the same parameters as 'attach', but it will do a 'detach' (and it will refuse to proceed if it cannot be done) first, matching on the unversioned prefix of the new image. Eg: portablectl reattach /tmp/foo_2.raw will cause foo_1.raw to be detached, and foo_2.raw to be attached. The key difference with a manual 'detach old' plus 'attach new' is that the running units are not disturbed until after the attach completed, and if --now is passed they are then restarted. A 'detach' is not allowed normally if the units are running. By using a restart-after-deploy method, 'reattach' allows for minimal interruption of service and also for features that only work on restart (eg: file descriptor store) to work as intended. The DBUS interface returns two lists: first the removals from the detach that were not immediately re-added in the attach, so that the caller can stop the relevant units, and then the list of additions that are either new or updates, so that the caller can restart/enable the relevant units. portablectl already implements this with the existing --now/--enable switches.
This commit is contained in:
Symlink
+1
@@ -0,0 +1 @@
|
||||
../TEST-01-BASIC/Makefile
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
|
||||
# ex: ts=8 sw=4 sts=4 et filetype=sh
|
||||
set -e
|
||||
TEST_DESCRIPTION="test systemd-portabled"
|
||||
IMAGE_NAME="portabled"
|
||||
TEST_NO_NSPAWN=1
|
||||
TEST_INSTALL_VERITY_MINIMAL=1
|
||||
|
||||
. $TEST_BASE_DIR/test-functions
|
||||
|
||||
# Need loop devices for mounting images
|
||||
test_append_files() {
|
||||
(
|
||||
instmods loop =block
|
||||
instmods squashfs =squashfs
|
||||
instmods dm_verity =md
|
||||
install_dmevent
|
||||
generate_module_dependencies
|
||||
inst_binary losetup
|
||||
inst_binary mksquashfs
|
||||
inst_binary unsquashfs
|
||||
install_verity_minimal
|
||||
)
|
||||
}
|
||||
|
||||
do_test "$@" 58
|
||||
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=TEST-58-PORTABLE
|
||||
|
||||
[Service]
|
||||
ExecStartPre=rm -f /failed /testok
|
||||
ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
|
||||
Type=oneshot
|
||||
Executable
+68
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env bash
|
||||
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
|
||||
# ex: ts=8 sw=4 sts=4 et filetype=sh
|
||||
set -ex
|
||||
set -o pipefail
|
||||
|
||||
export SYSTEMD_LOG_LEVEL=debug
|
||||
|
||||
portablectl attach --now --runtime /usr/share/minimal_0.raw app0
|
||||
|
||||
systemctl is-active app0.service
|
||||
systemctl is-active app0-foo.service
|
||||
set +o pipefail
|
||||
set +e
|
||||
systemctl is-active app0-bar.service && exit 1
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
portablectl reattach --now --runtime /usr/share/minimal_1.raw app0
|
||||
|
||||
systemctl is-active app0.service
|
||||
systemctl is-active app0-bar.service
|
||||
set +o pipefail
|
||||
set +e
|
||||
systemctl is-active app0-foo.service && exit 1
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
portablectl list | grep -q -F "minimal_1"
|
||||
|
||||
portablectl detach --now --runtime /usr/share/minimal_1.raw app0
|
||||
|
||||
portablectl list | grep -q -F "No images."
|
||||
|
||||
# portablectl also works with directory paths rather than images
|
||||
|
||||
unsquashfs -dest /tmp/minimal_0 /usr/share/minimal_0.raw
|
||||
unsquashfs -dest /tmp/minimal_1 /usr/share/minimal_1.raw
|
||||
|
||||
portablectl attach --copy=symlink --now --runtime /tmp/minimal_0 app0
|
||||
|
||||
systemctl is-active app0.service
|
||||
systemctl is-active app0-foo.service
|
||||
set +o pipefail
|
||||
set +e
|
||||
systemctl is-active app0-bar.service && exit 1
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
portablectl reattach --now --enable --runtime /tmp/minimal_1 app0
|
||||
|
||||
systemctl is-active app0.service
|
||||
systemctl is-active app0-bar.service
|
||||
set +o pipefail
|
||||
set +e
|
||||
systemctl is-active app0-foo.service && exit 1
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
portablectl list | grep -q -F "minimal_1"
|
||||
|
||||
portablectl detach --now --enable --runtime /tmp/minimal_1 app0
|
||||
|
||||
portablectl list | grep -q -F "No images."
|
||||
|
||||
echo OK > /testok
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user