autofs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #!/bin/bash
  2. ########################################################################
  3. # Begin autofs
  4. #
  5. # Description : Start daemon for automounting file systems
  6. #
  7. # Author : Bruce Dubbs - bdubbs@linuxfromscratch.org
  8. #
  9. # Version : LFS 7.2
  10. #
  11. # Notes : Updates to autofs distributed start script to make
  12. # compatible with BLFS
  13. #
  14. ########################################################################
  15. ### BEGIN INIT INFO
  16. # Provides: autofs
  17. # Required-Start: $network ypbind
  18. # Required-Stop: $network ypbind
  19. # Default-Start: 3 4 5
  20. # Default-Stop: 0 1 2 6
  21. # Short-Description: Automounts filesystems on demand
  22. # Description: Automounts filesystems on demand
  23. ### END INIT INFO
  24. #
  25. # Location of the automount daemon and the init directory
  26. #
  27. DAEMON=/sbin/automount
  28. prog=`basename $DAEMON`
  29. MODULE="autofs4"
  30. DEVICE="autofs"
  31. confdir=/etc/sysconfig
  32. test -e $DAEMON || exit 0
  33. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  34. export PATH
  35. #
  36. # load customized configuation settings
  37. #
  38. if [ -r $confdir/autofs ]; then
  39. . $confdir/autofs
  40. fi
  41. . /lib/lsb/init-functions
  42. function start() {
  43. log_info_msg "Starting $prog: "
  44. # Make sure autofs4 module is loaded
  45. if ! grep -q autofs /proc/filesystems
  46. then
  47. # Try load the autofs4 module fail if we can't
  48. modprobe $MODULE >/dev/null 2>&1
  49. if [ $? -eq 1 ]
  50. then
  51. log_failure_msg "Error: failed to load autofs4 module."
  52. return 1
  53. fi
  54. elif ([ -f /proc/modules ] && lsmod) | grep -q autofs[^4]
  55. then
  56. # wrong autofs filesystem module loaded
  57. log_failure_msg "Error: autofs kernel module is loaded, autofs4 required"
  58. return 1
  59. fi
  60. # Check misc device
  61. if [ -n "$USE_MISC_DEVICE" -a "x$USE_MISC_DEVICE" = "xyes" ]; then
  62. sleep 1
  63. if [ -e "/proc/misc" ]; then
  64. MINOR=`awk "/$DEVICE/ {print \\$1}" /proc/misc`
  65. if [ -n "$MINOR" -a ! -c "/dev/$DEVICE" ]; then
  66. mknod -m 0600 /dev/$DEVICE c 10 $MINOR
  67. fi
  68. fi
  69. if [ -x /sbin/restorecon -a -c /dev/$DEVICE ]; then
  70. /sbin/restorecon /dev/$DEVICE
  71. fi
  72. else
  73. if [ -c /dev/$DEVICE ]; then
  74. rm /dev/$DEVICE
  75. fi
  76. fi
  77. $prog $OPTIONS
  78. evaluate_retval
  79. }
  80. function stop() {
  81. log_info_msg $"Stopping $prog: "
  82. count=0
  83. while [ -n "`pidof $prog`" -a $count -lt 15 ] ; do
  84. killall -TERM $prog >& /dev/null
  85. RETVAL=$?
  86. [ $RETVAL = 0 -a -z "`pidof $prog`" ] || sleep 3
  87. count=`expr $count + 1`
  88. done
  89. if [ -z "`pidof $prog`" ] ; then
  90. log_success_msg2
  91. else
  92. log_failure_msg2
  93. fi
  94. return $RETVAL
  95. }
  96. function restart() {
  97. stop
  98. start
  99. }
  100. function reload() {
  101. pid=`pidof $prog`
  102. if [ -z $pid ]; then
  103. log_failure_msg2 $"$prog not running"
  104. RETVAL=1
  105. else
  106. kill -HUP $pid 2> /dev/null
  107. log_success_msg2 $"Reloading maps"
  108. RETVAL=0
  109. fi
  110. return $RETVAL
  111. }
  112. RETVAL=0
  113. case "$1" in
  114. start)
  115. start
  116. ;;
  117. forcestart)
  118. OPTIONS="$OPTIONS --force"
  119. start
  120. ;;
  121. stop)
  122. stop
  123. ;;
  124. restart)
  125. restart
  126. ;;
  127. forcerestart)
  128. OPTIONS="$OPTIONS --force"
  129. restart
  130. ;;
  131. reload)
  132. reload
  133. ;;
  134. *)
  135. echo $"Usage: $0 {start|forcestart|stop|restart|forcerestart|reload}"
  136. exit 1;
  137. ;;
  138. esac
  139. exit $?