respawn-throttling.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # GNU Shepherd --- Test respawn throttling.
  2. # Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
  3. #
  4. # This file is part of the GNU Shepherd.
  5. #
  6. # The GNU Shepherd is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or (at
  9. # your option) any later version.
  10. #
  11. # The GNU Shepherd is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with the GNU Shepherd. If not, see <http://www.gnu.org/licenses/>.
  18. shepherd --version
  19. herd --version
  20. socket="t-socket-$$"
  21. conf="t-conf-$$"
  22. log="t-log-$$"
  23. pid="t-pid-$$"
  24. herd="herd -s $socket"
  25. trap "cat $log || true ;
  26. rm -f $socket $conf $log ;
  27. test -f $pid && kill \`cat $pid\` || true ; rm -f $pid" EXIT
  28. cat > "$conf"<<EOF
  29. (register-services
  30. (make <service>
  31. #:provides '(keeps-respawning)
  32. #:start (make-forkexec-constructor '("false"))
  33. #:stop (make-kill-destructor)
  34. #:respawn? #t))
  35. EOF
  36. rm -f "$pid"
  37. shepherd -I -s "$socket" -c "$conf" -l "$log" --pid="$pid" &
  38. # Wait till it's ready.
  39. while ! test -f "$pid" ; do sleep 0.3 ; done
  40. shepherd_pid="`cat $pid`"
  41. kill -0 $shepherd_pid
  42. test -S "$socket"
  43. $herd start keeps-respawning
  44. # Maximum number of seconds to wait. XXX: It takes a while because SIGCHLD
  45. # handling is deferred until we leave the accept(2) call in (shepherd).
  46. count=15
  47. while [ $count -gt 0 ]
  48. do
  49. sleep 1
  50. if $herd status keeps-respawning | grep disabled
  51. then
  52. # The service is now disabled: success!
  53. break
  54. else
  55. count=`expr $count - 1`
  56. test $count -ge 0
  57. fi
  58. done
  59. # Make sure the service is indeed stopped and disabled.
  60. $herd status keeps-respawning | grep stopped
  61. $herd status keeps-respawning | grep disabled
  62. if $herd start keeps-respawning
  63. then false; else true; fi
  64. $herd status keeps-respawning | grep -i "last respawned"
  65. grep -i "respawning too fast" "$log"