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

Stanislav Kinsburskiy skinsbursky at virtuozzo.com
Wed Apr 6 03:09:00 PDT 2016


This script restarts systemd autofs services to workaround a problem, when
systemd doesn't consider autofs mount as own after restore (alien device ID
problem)

v2:
1) Added different checks: for process with pid, active service, systemd based
container.

Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
---
 scripts/systemd-autofs-restart.sh |   58 +++++++++++++++++++++++++++++++++++++
 1 file changed, 58 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..0bdbb33
--- /dev/null
+++ b/scripts/systemd-autofs-restart.sh
@@ -0,0 +1,58 @@
+#!/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
+
+if [ ! -d "/proc/$NS_PID" ]; then
+	echo "Process with NS_PID=$NS_PID doesn't exist"
+	exit 1
+fi
+
+NS_ENTER=/usr/nsenter
+[ ! -x $NSENTER ] || NS_ENTER=/usr/bin/nsenter
+
+if [ ! -x $NS_ENTER ]; then
+	echo "$NS_ENTER binary not found"
+	exit 2
+fi
+
+JOIN_CT="$NS_ENTER -t $NS_PID -m -u"
+
+# Skip container, if it's not systemd based
+[ $($JOIN_CT basename -- $(readlink /proc/1/exe)) == "systemd" ] || exit 0
+
+AUTOFS_SERVICES="proc-sys-fs-binfmt_misc.automount"
+
+for service in $AUTOFS_SERVICES; do
+	status=$($JOIN_CT systemctl is-active $service)
+	if [ $status == "active" ]; then
+		$JOIN_CT systemctl restart $service
+		if [ $? -ne 0 ]; then
+			echo "Failed to restart $service service"
+			exit 2
+		fi
+		echo "$service restarted"
+	else
+		echo "$service skipped ($status)"
+	fi
+done
+
+exit 0



More information about the CRIU mailing list