preinit 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/sh -e
  2. # This script is spawned by s6-overlay-suexec, as the
  3. # first thing in the userland boot process.
  4. # It is run as root even with a USER directive present.
  5. # If USER, then UID and GID hold the uid and gid of the user
  6. # (this is used by s6-chown -U).
  7. prog=/package/admin/s6-overlay/libexec/preinit
  8. # Ensure /run is writable and /var/run is a symlink to it.
  9. if test "0$S6_READ_ONLY_ROOT" -ne 0 ; then
  10. echo "$prog: info: read-only root" 1>&2
  11. if ! test -d /run ; then
  12. echo "$prog: fatal: /run is missing or not a directory" 1>&2
  13. exit 100
  14. fi
  15. if : > '/run/test of writability' 2>/dev/null ; then
  16. echo "$prog: info: writable /run. Remounting exec just in case." 1>&2
  17. s6-rmrf '/run/test of writability'
  18. s6-mount -o remount,rw,exec tmpfs /run || :
  19. else
  20. echo "$prog: info: creating a tmpfs on /run" 1>&2
  21. s6-mount -wt tmpfs -o exec,mode=0755 tmpfs /run
  22. fi
  23. else
  24. s6-mkdir -p -m 0755 /run
  25. fi
  26. if test -L /var/run && test "`/command/s6-linkname -f /var/run`" = /run ; then : ; else
  27. echo "$prog: notice: /var/run is not a symlink to /run, fixing it" 1>&2
  28. s6-rmrf /var/run
  29. s6-ln -s /run /var/run
  30. fi
  31. # /run/s6 is recreated every time and belongs to the USER.
  32. s6-rmrf /run/s6
  33. s6-mkdir -m 0755 /run/s6
  34. if test "0$UID" -ne 0 ; then
  35. s6-chown -U -- /run/s6
  36. fi