run_nfs.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # Copyright 2015 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. function start()
  16. {
  17. # prepare /etc/exports
  18. for i in "$@"; do
  19. # fsid=0: needed for NFSv4
  20. echo "$i *(rw,fsid=0,insecure,no_root_squash)" >> /etc/exports
  21. # move index.html to here
  22. /bin/cp /tmp/index.html $i/
  23. chmod 644 $i/index.html
  24. echo "Serving $i"
  25. done
  26. # start rpcbind if it is not started yet
  27. /usr/sbin/rpcinfo 127.0.0.1 > /dev/null; s=$?
  28. if [ $s -ne 0 ]; then
  29. echo "Starting rpcbind"
  30. /usr/sbin/rpcbind -w
  31. fi
  32. mount -t nfsd nfds /proc/fs/nfsd
  33. # -N 4.x: disable NFSv4
  34. # -V 3: enable NFSv3
  35. /usr/sbin/rpc.mountd -N 2 -V 3 -N 4 -N 4.1
  36. /usr/sbin/exportfs -r
  37. # -G 10 to reduce grace time to 10 seconds (the lowest allowed)
  38. /usr/sbin/rpc.nfsd -G 10 -N 2 -V 3 -N 4 -N 4.1 2
  39. /usr/sbin/rpc.statd --no-notify
  40. echo "NFS started"
  41. }
  42. function stop()
  43. {
  44. echo "Stopping NFS"
  45. /usr/sbin/rpc.nfsd 0
  46. /usr/sbin/exportfs -au
  47. /usr/sbin/exportfs -f
  48. kill $( pidof rpc.mountd )
  49. umount /proc/fs/nfsd
  50. echo > /etc/exports
  51. exit 0
  52. }
  53. trap stop TERM
  54. start "$@"
  55. # Ugly hack to do nothing and wait for SIGTERM
  56. while true; do
  57. sleep 5
  58. done