volatile-binds.bb 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. SUMMARY = "Volatile bind mount setup and configuration for read-only-rootfs"
  2. DESCRIPTION = "${SUMMARY}"
  3. LICENSE = "MIT"
  4. LIC_FILES_CHKSUM = "file://COPYING.MIT;md5=5750f3aa4ea2b00c2bf21b2b2a7b714d"
  5. SRC_URI = "\
  6. file://mount-copybind \
  7. file://COPYING.MIT \
  8. file://volatile-binds.service.in \
  9. "
  10. S = "${WORKDIR}"
  11. inherit allarch systemd features_check
  12. REQUIRED_DISTRO_FEATURES = "systemd"
  13. VOLATILE_BINDS ?= "\
  14. /var/volatile/lib /var/lib\n\
  15. /var/volatile/cache /var/cache\n\
  16. /var/volatile/spool /var/spool\n\
  17. /var/volatile/srv /srv\n\
  18. "
  19. VOLATILE_BINDS[type] = "list"
  20. VOLATILE_BINDS[separator] = "\n"
  21. def volatile_systemd_services(d):
  22. services = []
  23. for line in oe.data.typed_value("VOLATILE_BINDS", d):
  24. if not line:
  25. continue
  26. what, where = line.split(None, 1)
  27. services.append("%s.service" % what[1:].replace("/", "-"))
  28. return " ".join(services)
  29. SYSTEMD_SERVICE_${PN} = "${@volatile_systemd_services(d)}"
  30. FILES_${PN} += "${systemd_unitdir}/system/*.service"
  31. do_compile () {
  32. while read spec mountpoint; do
  33. if [ -z "$spec" ]; then
  34. continue
  35. fi
  36. servicefile="${spec#/}"
  37. servicefile="$(echo "$servicefile" | tr / -).service"
  38. sed -e "s#@what@#$spec#g; s#@where@#$mountpoint#g" \
  39. -e "s#@whatparent@#${spec%/*}#g; s#@whereparent@#${mountpoint%/*}#g" \
  40. volatile-binds.service.in >$servicefile
  41. done <<END
  42. ${@d.getVar('VOLATILE_BINDS').replace("\\n", "\n")}
  43. END
  44. if [ -e var-volatile-lib.service ]; then
  45. # As the seed is stored under /var/lib, ensure that this service runs
  46. # after the volatile /var/lib is mounted.
  47. sed -i -e "/^Before=/s/\$/ systemd-random-seed.service/" \
  48. -e "/^WantedBy=/s/\$/ systemd-random-seed.service/" \
  49. var-volatile-lib.service
  50. fi
  51. }
  52. do_compile[dirs] = "${WORKDIR}"
  53. do_install () {
  54. install -d ${D}${base_sbindir}
  55. install -m 0755 mount-copybind ${D}${base_sbindir}/
  56. install -d ${D}${systemd_unitdir}/system
  57. for service in ${SYSTEMD_SERVICE_${PN}}; do
  58. install -m 0644 $service ${D}${systemd_unitdir}/system/
  59. done
  60. # Suppress attempts to process some tmpfiles that are not temporary.
  61. #
  62. install -d ${D}${sysconfdir}/tmpfiles.d ${D}/var/cache
  63. ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/etc.conf
  64. ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/home.conf
  65. }
  66. do_install[dirs] = "${WORKDIR}"