rc.init 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/sh -e
  2. top="$1" ; shift
  3. if test -d /run/s6/container_environment ; then
  4. s6-chmod 0755 /run/s6/container_environment
  5. fi
  6. if profile=`printcontenv S6_RUNTIME_PROFILE` ; then
  7. etc="/etc/cont-profile.d/$profile"
  8. else
  9. etc=/etc
  10. fi
  11. s6-rc-compile -v1 /run/s6/db "$etc/s6-overlay/s6-rc.d" /package/admin/s6-overlay-@VERSION@/etc/s6-rc/sources
  12. s6-rc-init -c /run/s6/db /run/service
  13. if timeout=`printcontenv S6_CMD_WAIT_FOR_SERVICES_MAXTIME` && test "$timeout" -ge 0 ; then : ; else
  14. timeout=5000
  15. fi
  16. set +e
  17. s6-rc -v2 -u -t "$timeout" -- change "$top"
  18. r=$?
  19. set -e
  20. if test "$r" -ne 0 && b=0`printcontenv S6_BEHAVIOUR_IF_STAGE2_FAILS` && test "$b" -ne 0 ; then
  21. echo '/run/s6/basedir/scripts/rc.init: warning: s6-rc failed to properly bring all the services up! Check your logs (in /run/uncaught-logs/current if you have in-container logging) for more information.' 1>&2
  22. if test "$b" -ge 2 ; then
  23. echo '/run/s6/basedir/scripts/rc.init: fatal: stopping the container.' 1>&2
  24. echo "$r" > /run/s6-linux-init-container-results/exitcode
  25. exec /run/s6/basedir/bin/halt
  26. fi
  27. fi
  28. if test "$#" -ne 0 ; then
  29. cd `s6-cat < /run/s6/workdir`
  30. set +e
  31. arg0=`printcontenv S6_CMD_ARG0`
  32. $arg0 "$@"
  33. echo "$?" > /run/s6-linux-init-container-results/exitcode
  34. set -e
  35. exec /run/s6/basedir/bin/halt
  36. fi