samba.init 998 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh
  2. #PKG samba
  3. #INIT 80
  4. . /etc/rc.conf
  5. check_mount() {
  6. sed -n -e '/^#/d' -e '/path/s/^.*=//p' \
  7. /etc/samba/smb.conf | while read path; do
  8. grep -v '^#' /etc/fstab | fgrep -q "$path" || continue
  9. count=0
  10. while :; do
  11. if fgrep -q "$path" /proc/mounts; then
  12. logger -t smb "Device mounted, starting samba"
  13. break
  14. fi
  15. if test $count -eq 9; then
  16. logger -s "required filesystem missing"
  17. exit 1
  18. fi
  19. sleep 1
  20. count=$(($count+1))
  21. done
  22. done
  23. }
  24. case $1 in
  25. autostop) ;;
  26. autostart)
  27. test x"${samba:-NO}" = x"NO" && exit 0
  28. test x"$samba" = x"DAEMON" && test -x /bin/mksh && exec mksh -T- $0 start
  29. exec sh $0 start
  30. ;;
  31. start)
  32. check_mount
  33. [ -d /var/run/samba ] || mkdir -p /var/run/samba
  34. [ -d /var/log/samba ] || mkdir -p /var/log/samba
  35. /usr/sbin/nmbd -D
  36. /usr/sbin/smbd -D
  37. ;;
  38. stop)
  39. kill $(pgrep -f /usr/sbin/nmbd)
  40. kill $(pgrep -f /usr/sbin/smbd)
  41. ;;
  42. restart)
  43. sh $0 stop
  44. sh $0 start
  45. ;;
  46. *)
  47. echo "usage: $0 {start | stop | restart}"
  48. exit 1
  49. esac
  50. exit $?