localnet 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/sh
  2. # Begin /etc/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-Default-Start: S80
  15. # X-LFS-Default-Stop: S90
  16. # X-LFS-Provided-By: LFS
  17. ### END INIT INFO
  18. . /lib/lsb/init-functions
  19. . /etc/sysconfig/network
  20. case "${1}" in
  21. start)
  22. ip addr add 127.0.0.1/8 label lo dev lo
  23. ip link set lo up
  24. if [ "${?}" = "0" ]
  25. then
  26. log_success_msg "Bringing up the loopback interface..."
  27. else
  28. log_failure_msg "Bringing up the loopback interface..."
  29. fi
  30. hostname "${HOSTNAME}"
  31. if [ "${?}" = "0" ]
  32. then
  33. log_success_msg "Setting hostname to ${HOSTNAME}..."
  34. else
  35. log_failure_msg "Setting hostname to ${HOSTNAME}..."
  36. fi
  37. ;;
  38. stop)
  39. ip link set lo down
  40. if [ "${?}" = "0" ]
  41. then
  42. log_success_msg "Bringing down the loopback interface..."
  43. else
  44. log_failure_msg "Bringing down the loopback interface..."
  45. fi
  46. ;;
  47. restart)
  48. ip link set lo down
  49. retval="${?}"
  50. sleep 1
  51. ip addr add 127.0.0.1/8 label lo dev lo
  52. retval=$(( "${retval}" + "${?}" ))
  53. ip link set lo up
  54. retval=$(( "${retval}" + "${?}" ))
  55. hostname "${HOSTNAME}"
  56. retval=$(( "${retval}" + "${?}" ))
  57. if [ "${retval}" = "0" ]
  58. then
  59. log_success_msg "Restarting local network..."
  60. else
  61. log_failure_msg "Restarting local network..."
  62. fi
  63. ;;
  64. status)
  65. log_success_msg "Hostname is: ${INFO}$(hostname)${NORMAL}"
  66. ip link show lo
  67. ;;
  68. *)
  69. echo "Usage: ${0} {start|stop|restart|status}"
  70. exit 1
  71. ;;
  72. esac
  73. # End /etc/init.d/localnet