restart.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # GNU Shepherd --- Test restarting services.
  2. # Copyright © 2013, 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. log="t-log-$$"
  24. pid="t-pid-$$"
  25. herd="herd -s $socket"
  26. trap "cat $log || true ;
  27. rm -f $socket $conf $log;
  28. test -f $pid && kill \`cat $pid\` || true ; rm -f $pid" EXIT
  29. cat > "$conf"<<EOF
  30. (register-services
  31. (make <service>
  32. #:provides '(test1)
  33. #:start (const #t)
  34. #:stop (const #t))
  35. (make <service>
  36. #:provides '(test2)
  37. #:requires '(test1)
  38. #:start (const #t)
  39. #:stop (const #t))
  40. (make <service>
  41. #:provides '(test3)
  42. #:requires '(test2)
  43. #:start (const #t)
  44. #:stop (const #t)))
  45. EOF
  46. rm -f "$pid"
  47. shepherd -I -s "$socket" -c "$conf" -l "$log" --pid="$pid" &
  48. while ! test -f "$pid" ; do sleep 0.3 ; done
  49. # Start some test services, and make sure they behave how we expect
  50. $herd start test1
  51. $herd start test2
  52. $herd status test1 | grep started
  53. $herd status test2 | grep started
  54. # Restart test1 and make sure that both services are still running (ie. that
  55. # test2 hasn't been stopped)
  56. $herd restart test1
  57. $herd status test1 | grep started
  58. $herd status test2 | grep started
  59. # Now let's test with a transitive dependency
  60. $herd start test3
  61. $herd status test3 | grep started
  62. # After restarting test1 we want test3 to still be running
  63. $herd restart test1
  64. $herd status test1 | grep started
  65. $herd status test2 | grep started
  66. $herd status test3 | grep started