network 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/sh
  2. # Begin $RC_BASE/init.d/network
  3. ### BEGIN INIT INFO
  4. # Provides: $network
  5. # Required-Start: $local_fs swap localnet
  6. # Should-Start: $syslog
  7. # Required-Stop: $local_fs swap localnet
  8. # Should-Stop: $syslog
  9. # Default-Start: 3 4 5
  10. # Default-Stop: 0 1 2 6
  11. # Short-Description: Starts and configures network interfaces.
  12. # Description: Starts and configures network interfaces.
  13. # X-LFS-Provided-By: LFS
  14. ### END INIT INFO
  15. . /lib/lsb/init-functions
  16. case "${1}" in
  17. start)
  18. # Start all network interfaces
  19. for dir in ${NETWORK_DEVICES}/ifconfig.*
  20. do
  21. interface=${dir##*/ifconfig.}
  22. # skip if $dir is * (because nothing was found)
  23. if [ "${interface}" = "*" ]; then
  24. continue
  25. fi
  26. # Process individual configuration files
  27. for file in "${dir}"/* ; do
  28. ONBOOT=`grep "ONBOOT" "${file}" | sed 's@^ONBOOT=@@'`
  29. case "${ONBOOT}" in
  30. Y* | y* | 0)
  31. /sbin/ifup -c "${file}" "${interface}"
  32. ;;
  33. esac
  34. done
  35. done
  36. ;;
  37. stop)
  38. # Reverse list
  39. DIRS=""
  40. for dir in /run/network/ifconfig.*
  41. do
  42. DIRS="${dir} ${DIRS}"
  43. done
  44. # Stop all network interfaces
  45. for dir in ${DIRS}; do
  46. interface=${dir##*/ifconfig.}
  47. # skip if $dir is * (because nothing was found)
  48. if [ "${interface}" = "*" ]; then
  49. continue
  50. fi
  51. # Process individual configuration files
  52. for file in "${dir}"/* ; do
  53. # No checking necessary if it is in /run/network
  54. /sbin/ifdown -c "${file}" "${interface}"
  55. done
  56. link_status=`/sbin/ip link show "${interface}" | \
  57. grep -o "state DOWN"`
  58. if [ "${link_status}" != "state DOWN" ]; then
  59. message="Shutting down the ${interface} interface..."
  60. /sbin/ip addr flush "${interface}" &&
  61. /sbin/ip link set "${interface}" down
  62. evaluate_retval standard
  63. fi
  64. done
  65. ;;
  66. restart)
  67. ${0} stop
  68. sleep 1
  69. ${0} start
  70. ;;
  71. *)
  72. echo "Usage: ${0} {start|stop|restart}"
  73. exit 1
  74. ;;
  75. esac
  76. # End $RC_BASE/init.d/network