nfs.initd 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/usr/bin/openrc-run
  2. # Copyright 1999-2014 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. extra_started_commands="reload"
  5. exportfs=/usr/bin/exportfs
  6. mountd=/usr/bin/rpc.mountd
  7. nfsd=/usr/bin/rpc.nfsd
  8. smnotify=/usr/bin/sm-notify
  9. depend() {
  10. local myneed=""
  11. myneed="${myneed} $(
  12. awk '!/^[[:space:]]*#/ {
  13. # clear the path to avoid spurious matches
  14. $1 = "";
  15. if ($0 ~ /[(][^)]*sec=(krb|spkm)[^)]*[)]/) {
  16. print "rpc.svcgssd"
  17. exit 0
  18. }
  19. }' /etc/exports /etc/exports.d/*.exports 2>/dev/null
  20. )"
  21. config /etc/exports /etc/exports.d/*.exports
  22. need portmap rpc.statd ${myneed} ${NFS_NEEDED_SERVICES}
  23. use ypbind net dns rpc.rquotad rpc.idmapd rpc.svcgssd
  24. after quota
  25. }
  26. mkdir_nfsdirs() {
  27. local d
  28. for d in v4recovery v4root ; do
  29. d="/var/lib/nfs/${d}"
  30. [ ! -d "${d}" ] && mkdir -p "${d}"
  31. done
  32. }
  33. waitfor_exportfs() {
  34. local pid=$1
  35. ( sleep ${EXPORTFS_TIMEOUT:-30}; kill -9 ${pid} 2>/dev/null ) &
  36. wait $1
  37. }
  38. mount_nfsd() {
  39. if [ -e /proc/modules ] ; then
  40. if ! grep -qs nfsd /proc/filesystems ; then
  41. modprobe -q nfsd
  42. fi
  43. if grep -qs nfsd /proc/modules ; then
  44. killall -q -HUP rpc.idmapd
  45. fi
  46. fi
  47. if grep -qs nfsd /proc/filesystems ; then
  48. if ! mountinfo -q /proc/fs/nfsd ; then
  49. ebegin "Mounting nfsd filesystem in /proc"
  50. mount -t nfsd -o nodev,noexec,nosuid nfsd /proc/fs/nfsd
  51. eend $?
  52. fi
  53. local o
  54. for o in ${OPTS_NFSD} ; do
  55. echo "${o#*=}" > "/proc/fs/nfsd/${o%%=*}"
  56. done
  57. fi
  58. }
  59. start_it() {
  60. ebegin "Starting NFS $1"
  61. shift
  62. "$@"
  63. eend $?
  64. ret=$((ret + $?))
  65. }
  66. start() {
  67. mount_nfsd
  68. mkdir_nfsdirs
  69. if grep -qs '^[[:space:]]*"\?/' /etc/exports /etc/exports.d/*.exports ; then
  70. ebegin "Exporting NFS directories"
  71. ${exportfs} -r &
  72. waitfor_exportfs $!
  73. eend $?
  74. fi
  75. local ret=0
  76. start_it mountd ${mountd} ${OPTS_RPC_MOUNTD}
  77. start_it daemon ${nfsd} ${OPTS_RPC_NFSD}
  78. [ -x "${smnotify}" ] && start_it smnotify ${smnotify} ${OPTS_SMNOTIFY}
  79. return ${ret}
  80. }
  81. stop() {
  82. local ret=0
  83. ebegin "Stopping NFS mountd"
  84. start-stop-daemon --stop --exec ${mountd}
  85. eend $?
  86. ret=$((ret + $?))
  87. ebegin "Stopping NFS daemon"
  88. start-stop-daemon --stop --name nfsd --user root --signal 2
  89. eend $?
  90. ret=$((ret + $?))
  91. rpc.nfsd 0
  92. if [ "${RC_CMD}" != "restart" ] ; then
  93. ebegin "Unexporting NFS directories"
  94. ${exportfs} -ua &
  95. waitfor_exportfs $!
  96. eend $?
  97. fi
  98. return ${ret}
  99. }
  100. reload() {
  101. ebegin "Reloading /etc/exports"
  102. ${exportfs} -r 1>&2 &
  103. waitfor_exportfs $!
  104. eend $?
  105. }
  106. restart() {
  107. svc_stop
  108. svc_start
  109. }