[CRIU] [PATCH 2/3] scripts: systemd-autofs-restart.sh added

Stanislav Kinsburskiy skinsbursky at virtuozzo.com
Wed Apr 6 02:01:54 PDT 2016


Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
---
 scripts/systemd-autofs-restart.sh |   42 +++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100755 scripts/systemd-autofs-restart.sh

diff --git a/scripts/systemd-autofs-restart.sh b/scripts/systemd-autofs-restart.sh
new file mode 100755
index 0000000..ec75421
--- /dev/null
+++ b/scripts/systemd-autofs-restart.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+#
+# This script can be used as a workaround for systemd autofs mount migration.
+# The problem is that systemd is a clever guy: before mounting of actual file
+# system on top of autofs mount, it first checks that device number of autofs
+# mount is equal to the one, stored in sytemd internals. If they do not match,
+# systemd ignores kernel request.
+# The problem happens each time autofs is restored (new device number for
+# autofs superblock) and can't be properly solved without some kind of "device
+# namespaces", where device number can be preseved.
+# But some of systemd services can be painlessly restarted. Like
+# proc-sys-fs-binfmt_misc.
+#
+# Usage:
+# criu restore <options> --action-script $(pwd)/scripts/systemd-autofs-restart.sh
+#
+[ "$CRTOOLS_SCRIPT_ACTION" == "post-resume" ] || exit 0
+
+if [ ! -n "$NS_PID" ]; then
+	echo "NS_PID environment variable is not set"
+	exit 1
+fi
+
+NS_ENTER=/usr/bin/nsenter
+
+if [ ! -x $NS_ENTER ]; then
+	echo "$NS_ENTER binary not found"
+	exit 2
+fi
+
+SYSTEMD_SERVICES="proc-sys-fs-binfmt_misc.automount"
+
+for service in $SYSTEMD_SERVICES; do
+	$NS_ENTER -t $NS_PID -m -u systemctl restart $service
+	if [ $? -ne 0 ]; then
+		echo "Failed to restart $service service"
+		exit 2
+	fi
+	echo "$service restarted"
+done
+
+exit 0



More information about the CRIU mailing list