1
0

localnet 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/sh
  2. # Begin $RC_BASE/init.d/localnet
  3. ### BEGIN INIT INFO
  4. # Provides: localnet
  5. # Required-Start: $local_fs
  6. # Should-Start:
  7. # Required-Stop:
  8. # Should-Stop:
  9. # Default-Start: S
  10. # Default-Stop: 0 6
  11. # Short-Description: Starts the local network.
  12. # Description: Sets the hostname of the machine and starts the
  13. # loopback interface.
  14. # X-LFS-Provided-By: LFS
  15. ### END INIT INFO
  16. . /lib/lsb/init-functions
  17. case "${1}" in
  18. start)
  19. ip addr add 127.0.0.1/8 label lo dev lo
  20. ip link set lo up
  21. if [ "${?}" -eq "0" ]
  22. then
  23. log_success_msg "Bringing up the loopback interface..."
  24. else
  25. log_failure_msg "Bringing up the loopback interface..."
  26. fi
  27. hostname "${HOSTNAME}"
  28. if [ "${?}" -eq "0" ]
  29. then
  30. log_success_msg "Setting hostname to ${HOSTNAME}..."
  31. else
  32. log_failure_msg "Setting hostname to ${HOSTNAME}..."
  33. fi
  34. ;;
  35. stop)
  36. ip link set lo down
  37. if [ "${?}" -eq "0" ]
  38. then
  39. log_success_msg "Bringing down the loopback interface..."
  40. else
  41. log_failure_msg "Bringing down the loopback interface..."
  42. fi
  43. ;;
  44. restart)
  45. ip link set lo down
  46. retval="${?}"
  47. sleep 1
  48. ip addr add 127.0.0.1/8 label lo dev lo
  49. retval=$(( "${retval}" + "${?}" ))
  50. ip link set lo up
  51. retval=$(( "${retval}" + "${?}" ))
  52. hostname "${HOSTNAME}"
  53. retval=$(( "${retval}" + "${?}" ))
  54. if [ "${retval}" -eq "0" ]
  55. then
  56. log_success_msg "Restarting local network..."
  57. else
  58. log_failure_msg "Restarting local network..."
  59. fi
  60. ;;
  61. status)
  62. log_success_msg "Hostname is: ${INFO}$(hostname)${NORMAL}"
  63. ip link show lo
  64. ;;
  65. *)
  66. echo "Usage: ${0} {start|stop|restart|status}"
  67. exit 1
  68. ;;
  69. esac
  70. # End $RC_BASE/init.d/localnet