preinit 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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
  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 "0$UID" -ne 0 ; then
  27. s6-chown -U -- /run
  28. fi
  29. # Ensure /var/run is a symlink to /run
  30. if test -L /var/run && test "`s6-linkname -f /var/run`" = /run ; then : ; else
  31. echo "$prog: notice: /var/run is not a symlink to /run, fixing it" 1>&2
  32. s6-rmrf /var/run
  33. s6-ln -s /run /var/run
  34. fi
  35. # Clean up in case /run hasn't been wiped or USER has changed
  36. s6-rmrf /run/s6 /run/service /run/uncaught-logs /run/s6-rc*
  37. s6-mkdir -m 0755 /run/s6 /run/service
  38. if test "0$UID" -ne 0 ; then
  39. s6-chown -U -- /run/s6
  40. s6-chown -U -- /run/service
  41. fi