services-up 1.9 KB

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