services-up 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/sh -e
  2. if profile=`printcontenv S6_RUNTIME_PROFILE` ; then
  3. etc="/etc/cont-profile.d/$profile"
  4. else
  5. etc=/etc
  6. fi
  7. dir=/run/s6/legacy-services
  8. s6-rmrf "$dir"
  9. s6-mkdir -p -m 0755 "$dir"
  10. list=
  11. notifno=
  12. notifyes=
  13. for i in `s6-ls "$etc/services.d" 2>/dev/null | s6-sort` ; do
  14. if test -d "$etc/services.d/$i" ; then
  15. list="$list $i"
  16. s6-echo -n -- "services-up: info: copying legacy longrun $i" 1>&2
  17. if test -r "$dir/$i/notification-fd" ; then
  18. notifyes="$notifyes $dir/$i"
  19. echo 1>&2
  20. else
  21. notifno="$notifno $dir/$i"
  22. echo ' (no readiness notification)' 1>&2
  23. fi
  24. s6-hiercopy "$etc/services.d/$i" "$dir/$i"
  25. fi
  26. done
  27. for file in $list ; do
  28. s6-ln -nsf "$dir/$file" "/run/service/$file"
  29. done
  30. s6-svscanctl -a /run/service
  31. if dowait=`printcontenv S6_CMD_WAIT_FOR_SERVICES` && s6-test "$dowait" =~ '^[[:digit:]]+$' -a "$dowait" -gt 0 ; then
  32. if maxtime=`printcontenv S6_CMD_WAIT_FOR_SERVICES_MAXTIME` && s6-test "$maxtime" =~ '^[[:digit:]]+$' ; then : ; else
  33. maxtime=0
  34. fi
  35. # Increase if necessary. Unavoidable race condition, use s6-rc instead!
  36. s6-sleep -m 5
  37. r=false
  38. if test -n "$notifno" && ! s6-svwait -u -t "$maxtime" -- $notifno ; then
  39. r=true
  40. fi
  41. if test -n "$notifyes" && ! s6-svwait -U -t "$maxtime" -- $notifyes ; then
  42. r=true
  43. fi
  44. if $r && b=`printcontenv S6_BEHAVIOUR_IF_STAGE2_FAILS` && s6-test "$b" =~ '^[[:digit:]]+$' -a "$b" -gt 0 ; then
  45. echo 'services-up: warning: some legacy longruns failed to start' 1>&2
  46. if test "$b" -ge 2 ; then
  47. exit 1
  48. fi
  49. fi
  50. fi