services-up 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. if rtime=`printcontenv S6_SERVICES_READYTIME` && s6-test "$rtime" =~ '^[[:digit:]]+$' ; then : ; else
  36. rtime=5
  37. fi
  38. # Increase if necessary. Unavoidable race condition, use s6-rc instead!
  39. s6-sleep -m "$rtime"
  40. r=false
  41. if test -n "$notifno" && ! s6-svwait -u -t "$maxtime" -- $notifno ; then
  42. r=true
  43. fi
  44. if test -n "$notifyes" && ! s6-svwait -U -t "$maxtime" -- $notifyes ; then
  45. r=true
  46. fi
  47. if $r && b=`printcontenv S6_BEHAVIOUR_IF_STAGE2_FAILS` && s6-test "$b" =~ '^[[:digit:]]+$' -a "$b" -gt 0 ; then
  48. echo 'services-up: warning: some legacy longruns failed to start' 1>&2
  49. if test "$b" -ge 2 ; then
  50. exit 1
  51. fi
  52. fi
  53. fi