/init.d/networking

http://github.com/brinkman83/bashrc · Shell · 100 lines · 73 code · 16 blank · 11 comment · 13 complexity · db7e515f04f04f54708b5ea862585c31 MD5 · raw file

  1. #!/bin/sh -e
  2. ### BEGIN INIT INFO
  3. # Provides: networking
  4. # Required-Start:
  5. # Required-Stop: $local_fs
  6. # Default-Start:
  7. # Default-Stop: 0 6
  8. # Short-Description: Raise network interfaces.
  9. ### END INIT INFO
  10. PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
  11. [ -x /sbin/ifup ] || exit 0
  12. . /lib/lsb/init-functions
  13. # helper function to set the usplash timeout. https://launchpad.net/bugs/21617
  14. usplash_timeout () {
  15. TIMEOUT=$1
  16. if [ -x /sbin/usplash_write ]; then
  17. /sbin/usplash_write "TIMEOUT $TIMEOUT" || true
  18. fi
  19. }
  20. process_options() {
  21. [ -e /etc/network/options ] || return 0
  22. log_warning_msg "/etc/network/options still exists and it will be IGNORED! Read README.Debian of netbase."
  23. }
  24. check_network_file_systems() {
  25. [ -e /proc/mounts ] || return 0
  26. if [ -e /etc/iscsi/iscsi.initramfs ]; then
  27. # probably root on iSCSI
  28. log_warning_msg "not deconfiguring network interfaces: root filesystem appears to be on iSCSI."
  29. exit 0
  30. fi
  31. exec 9<&0 < /proc/mounts
  32. while read DEV MTPT FSTYPE REST; do
  33. case $DEV in
  34. /dev/nbd*|/dev/nd[a-z]*|/dev/etherd/e*)
  35. log_warning_msg "not deconfiguring network interfaces: network devices still mounted."
  36. exit 0
  37. ;;
  38. esac
  39. case $FSTYPE in
  40. nfs|nfs4|smbfs|ncp|ncpfs|cifs|coda|ocfs2|gfs|pvfs|pvfs2|fuse.httpfs|fuse.curlftpfs)
  41. log_warning_msg "not deconfiguring network interfaces: network file systems still mounted."
  42. exit 0
  43. ;;
  44. esac
  45. done
  46. exec 0<&9 9<&-
  47. }
  48. case "$1" in
  49. start)
  50. /lib/init/upstart-job networking start
  51. ;;
  52. stop)
  53. check_network_file_systems
  54. log_action_begin_msg "Deconfiguring network interfaces"
  55. if [ "$VERBOSE" != no ]; then
  56. if ifdown -a --exclude=lo; then
  57. log_action_end_msg $?
  58. else
  59. log_action_end_msg $?
  60. fi
  61. else
  62. if ifdown -a --exclude=lo >/dev/null 2>/dev/null; then
  63. log_action_end_msg $?
  64. else
  65. log_action_end_msg $?
  66. fi
  67. fi
  68. ;;
  69. force-reload|restart)
  70. process_options
  71. log_action_begin_msg "Reconfiguring network interfaces"
  72. ifdown -a --exclude=lo || true
  73. if ifup -a --exclude=lo; then
  74. log_action_end_msg $?
  75. else
  76. log_action_end_msg $?
  77. fi
  78. ;;
  79. *)
  80. echo "Usage: /etc/init.d/networking {start|stop|restart|force-reload}"
  81. exit 1
  82. ;;
  83. esac
  84. exit 0