Trans:GentooX86Handbook4-5

Gentoo Korea Wiki
둘러보기로 가기 검색하러 가기

기능 추가

표준 함수 훅

/etc/conf.d/net에 start/stop 함수 주변에서 호출 되는 네가지 함수를 정의할 수 있습니다. 이 함수들은 인터페이스 이름을 통해 먼저 호출되어 하나의 함수가 여러 개의 어댑터를 제어할 수 있습니다.

preup()predown() 함수의 반환 값은 인터페이스의 설정이나 설정 해제를 계속할 수 있음을 표시하기 위해 0(성공)이 되어야 합니다. preup()의 반환 값이 0이 아니면 인터페이스 설정이 중지됩니다 predown()의 반환 값이 0이 아니면, 인터페이스의 설정을 더 이상 해제할 수 없게 됩니다.

postup()postdown()함수의 반환 값은 위에서 명시한 함수들이 실패했음을 나타낼 경우 더 이상 아무 것도 하지 않으므로 무시됩니다.

${IFACE} 는 인터페이스를 올리고 내릴 때 설정합니다. ${IFVAR}${IFACE}를 배시에서 허용하는 변수 이름으로 변환한 값입니다.


코드 예제 1.1: /etc/confi.d/net pre/post up/down 함수 예제
preup() {
  # Test for link on the interface prior to bringing it up. This
  # only works on some network adapters and requires the ethtool
  # package to be installed.

  if ethtool ${IFACE} | grep -q 'Link detected: no'; then
    ewarn "No link on ${IFACE}, aborting configuration"
    return 1
  fi

  # Remember to return 0 on success

  return 0
}

predown() {
  # The default in the script is to test for NFS root and disallow
  # downing interfaces in that case. Note that if you specify a
  # predown() function you will override that logic. Here it is, in
  # case you still want it...

  if is_net_fs /; then
    eerror "root filesystem is network mounted -- can't stop ${IFACE}"
    return 1
  fi

  # Remember to return 0 on success
  return 0
}

postup() {
  # This function could be used, for example, to register with a
  # dynamic DNS service. Another possibility would be to
  # send/receive mail once the interface is brought up.

    return 0
}

postdown() {
  # This function is mostly here for completeness... I haven't
  # thought of anything nifty to do with it yet ;-)

    return 0
}