generator: Ensure mount units are started at boot 03/298403/1
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 5 Sep 2023 22:32:56 +0000 (00:32 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 6 Sep 2023 10:04:33 +0000 (12:04 +0200)
User session units can not depend on .mount units, so system
units have to start these even if it will be used much later.

Change-Id: I54c26a1e8eb57cbf6cbe0ea73c742630b9d0bdbf

packaging/isu.spec
src/systemd_generator/isu-generator

index 2b17c79..77f069c 100644 (file)
@@ -1,6 +1,6 @@
 Summary: Individual Service Upgrade support
 Name:    isu
-Version: 8.0.2
+Version: 8.0.3
 Release: 1
 Source0: %{name}-%{version}.tar.gz
 License: MIT
index 5db6da1..24e7455 100755 (executable)
@@ -48,12 +48,24 @@ install_units()
        local mount_unit="run-isu-$(systemd-escape ${isu_pkg_name})-rootfs.mount"
        local confd="${new_srv_path}.d"
        mkdir -p "${confd}"
-       cat <<EOF >> "$confd/isu.conf.tmp" || return 1
 
+       if [ "$INSTANCE" = "system" ]; then
+               cat <<EOF >> "$confd/isu.conf.tmp" || return 1
+# Automatically generated by $0
 [Unit]
 After=${mount_unit}
 BindsTo=${mount_unit}
 EOF
+       else
+# User session unit can not depend on system session units, thus we can't really use After=/etc. here.
+# However, given that we guarantee that isu .mount units are mounted in local-fs.target, which is part
+# of basic.target, it should be enough to depend on the DefaultDependencies logic.
+               cat <<EOF >> "$confd/isu.conf.tmp" || return 1
+# Automatically generated by $0
+[Unit]
+DefaultDependencies=yes
+EOF
+       fi
 
        # make new unit visible
        mv "${confd}/isu.conf.tmp" "${confd}/isu.conf" || return 1
@@ -80,17 +92,18 @@ install_mount_unit()
                # install_mount_unit() invocation - for the same ISU package, but different
                # .service file
                cat <<EOF >> "$UNITDIR/$mount_unit" || return 1
-# This unit file has been automatically generated by isu-generator.
-#
-# Do not edit this file as it will be re-created at next generator run.
-
+# Automatically generated by $0
 [Unit]
 DefaultDependencies=no
+Before=local-fs.target
 
 [Mount]
 What=${PKGDIR}/${isu_pkg_name}/rootfs.img
 Where=${RUNDIR}/${isu_pkg_name}/rootfs
 EOF
+       mkdir -p "$UNITDIR/local-fs.target.wants"
+       ln -s "../$mount_unit" "$UNITDIR/local-fs.target.wants/"
+
        fi
 
        return 0