replacement.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # GNU Shepherd --- Ensure replacing services works properly
  2. # Copyright © 2014, 2016 Ludovic Courtès <ludo@gnu.org>
  3. # Copyright © 2018 Carlo Zancanaro <carlo@zancanaro.id.au>
  4. #
  5. # This file is part of the GNU Shepherd.
  6. #
  7. # The GNU Shepherd is free software; you can redistribute it and/or modify it
  8. # under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 3 of the License, or (at
  10. # your option) any later version.
  11. #
  12. # The GNU Shepherd is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with the GNU Shepherd. If not, see <http://www.gnu.org/licenses/>.
  19. shepherd --version
  20. herd --version
  21. socket="t-socket-$$"
  22. conf="t-conf-$$"
  23. rconf="t-rconf-$$"
  24. log="t-log-$$"
  25. stamp="t-stamp-$$"
  26. pid="t-pid-$$"
  27. herd="herd -s $socket"
  28. trap "rm -f $socket $conf $rconf $stamp $log;
  29. test -f $pid && kill \`cat $pid\` || true; rm -f $pid" EXIT
  30. cat > "$conf"<<EOF
  31. (use-modules (srfi srfi-26))
  32. (register-services
  33. (make <service>
  34. #:provides '(test)
  35. #:start (const #t)
  36. #:actions (make-actions
  37. (say-hello (lambda _
  38. (call-with-output-file "$stamp"
  39. (lambda (port)
  40. (display "Hello" port))))))
  41. #:respawn? #f))
  42. EOF
  43. rm -f "$pid" "$stamp" "$socket"
  44. shepherd -I -s "$socket" -c "$conf" --pid="$pid" --log="$log" &
  45. while ! test -f "$pid"; do sleep 0.5 ; done
  46. $herd start test
  47. if ! $herd say-hello test; then
  48. echo "say-hello failed"
  49. exit 1
  50. fi
  51. cat > "$rconf"<<EOF
  52. (register-services
  53. (make <service>
  54. #:provides '(test)
  55. #:start (const #t)
  56. #:actions (make-actions
  57. (say-goodbye (lambda _
  58. (call-with-output-file "$stamp"
  59. (lambda (port)
  60. (display "Goodbye" port))))))
  61. #:respawn? #f))
  62. EOF
  63. $herd load root "$rconf"
  64. if ! $herd say-hello test; then
  65. echo "say-hello failed after setting replacement"
  66. exit 1
  67. fi
  68. if test "`cat $stamp`" != "Hello"; then
  69. echo "Output file had the wrong contents! Was:"
  70. cat $stamp
  71. exit 1
  72. fi
  73. $herd stop test
  74. $herd start test
  75. if $herd say-hello test; then
  76. echo "say-hello should have failed after stop/start"
  77. exit 1
  78. fi
  79. if ! $herd say-goodbye test; then
  80. echo "say-goodbye failed after replacement"
  81. exit 1
  82. fi
  83. if test "`cat $stamp`" != "Goodbye"; then
  84. echo "Output file had the wrong contents! Was:"
  85. cat $stamp
  86. exit 1
  87. fi