k8s.io/kubernetes@v1.29.3/test/images/volume/nfs/run_nfs.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2015 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 function start() 18 { 19 20 unset gid 21 # accept "-G gid" option 22 while getopts "G:" opt; do 23 case ${opt} in 24 G) gid=${OPTARG};; 25 *):;; 26 esac 27 done 28 shift $((OPTIND - 1)) 29 30 # prepare /etc/exports 31 for i in "$@"; do 32 # fsid=0: needed for NFSv4 33 echo "$i *(rw,fsid=0,insecure,no_root_squash)" >> /etc/exports 34 if [ -v gid ] ; then 35 chmod 070 "$i" 36 chgrp "$gid" "$i" 37 fi 38 # move index.html to here 39 /bin/cp /tmp/index.html "$i/" 40 chmod 644 "$i/index.html" 41 echo "Serving $i" 42 done 43 44 # start rpcbind if it is not started yet 45 /usr/sbin/rpcinfo 127.0.0.1 > /dev/null; s=$? 46 if [ $s -ne 0 ]; then 47 echo "Starting rpcbind" 48 /usr/sbin/rpcbind -w 49 fi 50 51 mount -t nfsd nfsd /proc/fs/nfsd 52 53 # -V 3: enable NFSv3 54 /usr/sbin/rpc.mountd -N 2 -V 3 55 56 /usr/sbin/exportfs -r 57 # -G 10 to reduce grace time to 10 seconds (the lowest allowed) 58 /usr/sbin/rpc.nfsd -G 10 -N 2 -V 3 59 /usr/sbin/rpc.statd --no-notify 60 echo "NFS started" 61 } 62 63 function stop() 64 { 65 echo "Stopping NFS" 66 67 /usr/sbin/rpc.nfsd 0 68 /usr/sbin/exportfs -au 69 /usr/sbin/exportfs -f 70 71 kill "$( pidof rpc.mountd )" 72 umount /proc/fs/nfsd 73 echo > /etc/exports 74 exit 0 75 } 76 77 78 trap stop TERM 79 80 start "$@" 81 82 # Ugly hack to do nothing and wait for SIGTERM 83 while true; do 84 sleep 5 85 done