Guest User

Untitled

a guest
Aug 14th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: nfs-kernel-server
  4. # Required-Start: $remote_fs $portmap hwclock
  5. # Required-Stop: $remote_fs $portmap hwclock
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Kernel NFS server support
  9. # Description: NFS is a popular protocol for file sharing across
  10. # TCP/IP networks. This service provides NFS server
  11. # functionality, which is configured via the
  12. # /etc/exports file.
  13. ### END INIT INFO
  14. #
  15. # Startup script for nfs-utils
  16. #
  17. #
  18. # The environment variable NFS_SERVERS may be set in /etc/default/nfsd
  19. # Other control variables may be overridden here too
  20. test -r /etc/default/nfsd && . /etc/default/nfsd
  21. #
  22. # Location of executables:
  23. test -x "$NFS_MOUNTD" || NFS_MOUNTD=/usr/sbin/rpc.mountd
  24. test -x "$NFS_NFSD" || NFS_NFSD=/usr/sbin/rpc.nfsd
  25. test -x "$NFS_STATD" || NFS_STATD=/usr/sbin/rpc.statd
  26. #
  27. # The user mode program must also exist (it just starts the kernel
  28. # threads using the kernel module code).
  29. test -x "$NFS_MOUNTD" || exit 0
  30. test -x "$NFS_NFSD" || exit 0
  31. #
  32. # Default is 8 threads, value is settable between 1 and the truely
  33. # ridiculous 99
  34. test "$NFS_SERVERS" != "" && test "$NFS_SERVERS" -gt 0 && test "$NFS_SERVERS" -lt 100 || NFS_SERVERS=8
  35. #
  36. # The default state directory is /var/lib/nfs
  37. test -n "$NFS_STATEDIR" || NFS_STATEDIR=/var/lib/nfs
  38. #
  39. #----------------------------------------------------------------------
  40. # Startup and shutdown functions.
  41. # Actual startup/shutdown is at the end of this file.
  42. #directories
  43. create_directories(){
  44. echo -n 'creating NFS state directory: '
  45. mkdir -p "$NFS_STATEDIR"
  46. ( cd "$NFS_STATEDIR"
  47. umask 077
  48. mkdir -p sm sm.bak
  49. test -w sm/state || {
  50. rm -f sm/state
  51. :>sm/state
  52. }
  53. umask 022
  54. for file in xtab etab smtab rmtab
  55. do
  56. test -w "$file" || {
  57. rm -f "$file"
  58. :>"$file"
  59. }
  60. done
  61. )
  62. echo done
  63. }
  64. #mountd
  65. start_mountd(){
  66. echo -n 'starting mountd: '
  67. start-stop-daemon --start --exec "$NFS_MOUNTD" -- "-f /etc/exports $@"
  68. echo done
  69. }
  70. stop_mountd(){
  71. echo -n 'stopping mountd: '
  72. start-stop-daemon --stop --quiet --exec "$NFS_MOUNTD"
  73. echo done
  74. }
  75. #
  76. #nfsd
  77. start_nfsd(){
  78. echo -n "starting $1 nfsd kernel threads: "
  79. start-stop-daemon --start --exec "$NFS_NFSD" -- "$@"
  80. echo done
  81. }
  82. delay_nfsd(){
  83. for delay in 0 1 2 3 4 5 6 7 8 9
  84. do
  85. if pidof nfsd >/dev/null
  86. then
  87. echo -n .
  88. sleep 1
  89. else
  90. return 0
  91. fi
  92. done
  93. return 1
  94. }
  95. stop_nfsd(){
  96. # WARNING: this kills any process with the executable
  97. # name 'nfsd'.
  98. echo -n 'stopping nfsd: '
  99. start-stop-daemon --stop --quiet --signal 1 --name nfsd
  100. if delay_nfsd || {
  101. echo failed
  102. echo ' using signal 9: '
  103. start-stop-daemon --stop --quiet --signal 9 --name nfsd
  104. delay_nfsd
  105. }
  106. then
  107. echo done
  108. else
  109. echo failed
  110. fi
  111. }
  112.  
  113. #statd
  114. start_statd(){
  115. echo -n "starting statd: "
  116. start-stop-daemon --start --exec "$NFS_STATD"
  117. echo done
  118. }
  119. stop_statd(){
  120. # WARNING: this kills any process with the executable
  121. # name 'statd'.
  122. echo -n 'stopping statd: '
  123. start-stop-daemon --stop --quiet --signal 1 --name statd
  124. echo done
  125. }
  126. #----------------------------------------------------------------------
  127. #
  128. # supported options:
  129. # start
  130. # stop
  131. # reload: reloads the exports file
  132. # restart: stops and starts mountd
  133. #FIXME: need to create the /var/lib/nfs/... directories
  134. case "$1" in
  135. start) create_directories
  136. start_nfsd "$NFS_SERVERS"
  137. start_mountd
  138. start_statd
  139. test -r /etc/exports && exportfs -a;;
  140. stop) exportfs -ua
  141. stop_statd
  142. stop_mountd
  143. stop_nfsd;;
  144. reload) test -r /etc/exports && exportfs -r;;
  145. restart)exportfs -ua
  146. stop_mountd
  147. stop_statd
  148. # restart does not restart the kernel threads,
  149. # only the user mode processes
  150. start_mountd
  151. start_statd
  152. test -r /etc/exports && exportfs -a;;
  153. esac
Add Comment
Please, Sign In to add comment