56dhclient 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/sh
  2. # If we are running dhclient, shutdown running instances cleanly and
  3. # bring them back up on resume.
  4. . "${PM_FUNCTIONS}"
  5. PM_DHCLIENT_RUNDIR="${PM_UTILS_RUNDIR}/network"
  6. PM_DHCLIENT_SUSPEND="${PM_DHCLIENT_RUNDIR}/dhclient.suspend"
  7. suspend_dhclient() {
  8. [ ! -d /etc/sysconfig/network-scripts ] && return
  9. [ ! -x /sbin/ifdown ] && return
  10. [ ! -d ${PM_DHCLIENT_RUNDIR} ] && /bin/mkdir -p ${PM_DHCLIENT_RUNDIR}
  11. [ -f ${PM_DHCLIENT_SUSPEND} ] && /bin/rm -f ${PM_DHCLIENT_SUSPEND}
  12. cd /etc/sysconfig/network-scripts
  13. for ifcfg in ifcfg-* ; do
  14. # Clear relevant parameters set by previous interface
  15. # (lo doesn't set them)
  16. NM_CONTROLLED=
  17. BOOTPROTO=
  18. . ./${ifcfg}
  19. if [ "${NM_CONTROLLED}" = "no" ] || [ "${NM_CONTROLLED}" = "n" ] || [ "${NM_CONTROLLED}" = "false" ]; then
  20. if [ "${BOOTPROTO}" = "bootp" ] || [ "${BOOTPROTO}" = "dhcp" ] || [ -z "${BOOTPROTO}" ]; then
  21. # device is not NetworkManager controlled and uses dhcp,
  22. # now see if it's actually up at the moment
  23. /sbin/ip link show ${DEVICE} | /bin/grep -qE "state (UP|UNKNOWN)" >/dev/null 2>&1
  24. if [ $? -eq 0 ]; then
  25. echo "${DEVICE}" >> ${PM_DHCLIENT_SUSPEND}
  26. /sbin/ifdown ${DEVICE}
  27. fi
  28. fi
  29. fi
  30. done
  31. }
  32. resume_dhclient() {
  33. [ ! -f ${PM_DHCLIENT_SUSPEND} ] && return
  34. [ ! -x /sbin/ifup ] && return
  35. cd /etc/sysconfig/network-scripts
  36. while read device ; do
  37. /sbin/ifup ${device}
  38. done < ${PM_DHCLIENT_SUSPEND}
  39. /bin/rm -f ${PM_DHCLIENT_SUSPEND}
  40. }
  41. case "$1" in
  42. hibernate|suspend)
  43. suspend_dhclient
  44. ;;
  45. thaw|resume)
  46. resume_dhclient
  47. ;;
  48. *) exit $NA
  49. ;;
  50. esac