netfs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin netfs
  4. #
  5. # Description : Mount network filesystems
  6. #
  7. # Author : Nathan Coulson - conathan@conet.dyndns.org
  8. # DJ Lucas - dj@linuxfromscratch.org
  9. #
  10. # Version : LFS 7.0
  11. #
  12. ########################################################################
  13. ### BEGIN INIT INFO
  14. # Provides: $remote_fs
  15. # Required-Start: $network
  16. # Should-Start: nfs-client nfs-server
  17. # Required-Stop: $network
  18. # Should-Stop: nfs-server nfs-client
  19. # Default-Start: 3 4 5
  20. # Default-Stop: 0 1 2 6
  21. # Short-Description: Mounts network volumes.
  22. # Description: Mounts anything marked as _netdev, and umounts and mounted
  23. # _netfs, smbfs, ncpfd, coda, or nfs volumes
  24. # X-LFS-Provided-By: BLFS / LFS 7.0
  25. ### END INIT INFO
  26. . /lib/lsb/init-functions
  27. #$LastChangedBy: bdubbs $
  28. #$Date: 2012-04-18 16:56:10 -0500 (Wed, 18 Apr 2012) $
  29. case "$1" in
  30. start)
  31. # The following line mounts all entries in fstab that
  32. # have the _netdev option. This is required for network
  33. # filesystems to be mounted at boot time.
  34. log_info_msg "Mounting network volumes..."
  35. /bin/mount -a -O _netdev
  36. evaluate_retval
  37. ;;
  38. stop)
  39. log_info_msg "Unmounting network volumes..."
  40. # The following line obtains a list from the output of
  41. # mount for all netfs types and anything that was
  42. # mounted with the _netdev option.
  43. NETMOUNTS=`/bin/mount \
  44. | /bin/grep '_netdev\|smbfs\|ncpfs\|coda\|nfs\|cifs' \
  45. | /usr/bin/cut -d " " -f 3 | /bin/sed ':a;$!N;s/\n/ /;ta'`
  46. # Check to see if anything was listed from above
  47. # (see if anything is actually needs to be unmounted)
  48. if [ x"$NETMOUNTS" != x ]; then
  49. # There is something mounted
  50. # Try and stop processes the nice way
  51. # (probably won't work in most cases)
  52. /bin/fuser -SIGTERM -km $NETMOUNTS > /dev/null
  53. # Check and see if it found anything. If it
  54. # did, then give 3 seconds for things to exit
  55. # the nice way before killing them off.
  56. # This one will work all of the time!
  57. if [ $? = 0 ]; then
  58. /bin/sleep ${KILLDELAY:-3} # Default is 3, not minus 3
  59. /bin/fuser -km $NETMOUNTS > /dev/null
  60. fi
  61. # We now need to unmount all network filesystems.
  62. # We will do this with two umount commands to allow
  63. # for broken behavior of smbmount, and also to make
  64. # certain that netmounts without the _netdev option
  65. # will still get unmounted.
  66. /bin/umount -af -O _netdev
  67. # Save the return value
  68. NERRVAL=$?
  69. # Now catch the rest of the network filesystems
  70. # by fstype. This list can be extended later as
  71. # more network filesystems are supported by mount.
  72. /bin/umount -af -t coda,ncpfs,nfs,smbfs,nfsd,cifs
  73. if [ $? = 0 -a $NERRVAL = 0 ]; then
  74. (exit 0)
  75. else
  76. (exit 1)
  77. fi
  78. evaluate_retval
  79. else
  80. # There is nothing mounted
  81. log_success_msg2 "No network volumes mounted!"
  82. fi
  83. ;;
  84. *)
  85. echo "Usage: $0 {start|stop}"
  86. exit 1
  87. ;;
  88. esac
  89. # End /etc/init.d/netfs