tweak service examples a bit (less verbose comment in dhcp_if)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2009-11-09 11:04:54 +01:00
parent 391dd92ce2
commit 002bdc3e2a
2 changed files with 34 additions and 37 deletions

View File

@ -1,31 +1,12 @@
#!/bin/sh #!/bin/sh
# executed by udhcpc # executed by udhcpc
# parameters: $1 and environment # parameters: $1 and environment
#
# $1 is: # $1 is:
# deconfig: This argument is used when udhcpc starts, and
# when a leases is lost. The script should put the interface in an
# up, but deconfigured state, ie: ifconfig $interface 0.0.0.0.
# #
# bound: This argument is used when udhcpc moves from an # deconfig: udhcpc starts, or lease is lost.
# unbound, to a bound state. All of the paramaters are set in # Environment example: interface=eth0
# enviromental variables, The script should configure the interface,
# and set any other relavent parameters (default gateway, dns server,
# etc).
# #
# renew: This argument is used when a DHCP lease is renewed. All of # bound: lease is obtained. Environment example:
# the paramaters are set in enviromental variables. This argument is
# used when the interface is already configured, so the IP address,
# will not change, however, the other DHCP paramaters, such as the
# default gateway, subnet mask, and dns server may change.
#
# nak: This argument is used with udhcpc receives a NAK message.
# The script with the deconfig argument will be called directly
# afterwards, so no changes to the network interface are neccessary.
# This hook is provided for purely informational purposes (the
# message option may contain a reason for the NAK).
#
# env shows something like:
# dhcptype=5 # dhcptype=5
# serverid=172.16.42.102 # serverid=172.16.42.102
# lease=97200 # lease=97200
@ -38,9 +19,18 @@
# dns=10.34.32.125 10.32.63.5 10.34.255.7 10.11.255.27 # dns=10.34.32.125 10.32.63.5 10.34.255.7 10.11.255.27
# domain=lab.example.com example.com # domain=lab.example.com example.com
# ntpsrv=10.34.32.125 10.34.255.7 # ntpsrv=10.34.32.125 10.34.255.7
#
# renew: lease is renewed. Environment is similar to "bound".
# The IP address does not not change, however, the other DHCP paramaters,
# such as the default gateway, subnet mask, and dns server may change.
#
# nak: udhcpc received a NAK message.
# Environment example: interface=eth0
#
# leasefail: udhcpc cannot obtain a lease (DHCP server not responding, etc).
# Environment example: interface=eth0
# TODO: put domain into /etc/resolv.conf (thru /var/service/fw) # TODO: put $domain into /etc/resolv.conf (thru /var/service/fw)
# TODO: feed ntp IPs to /var/service/ntp
service=${PWD##*/} service=${PWD##*/}
file_ipconf="$service.ipconf" file_ipconf="$service.ipconf"
@ -69,23 +59,25 @@ fi
# Bound: we've got the lease # Bound: we've got the lease
#env >"$service.out" # debug #env >"$service.out" # debug
./convert2ipconf "$file_ipconf" ./convert2ipconf "$file_ipconf"
# Reconfigure routing and firewall if needed # Reconfigure routing and firewall if needed
diff --brief "$file_ipconf" "$dir_ipconf/$file_ipconf" >/dev/null 2>&1 diff --brief "$file_ipconf" "$dir_ipconf/$file_ipconf" >/dev/null 2>&1
if test "$?" != "0"; then if test $? != 0; then
echo "Reconfiguring fw" echo "Reconfiguring fw"
mkdir -p "$dir_ipconf" 2>/dev/null mkdir -p "$dir_ipconf" 2>/dev/null
cp "$file_ipconf" "$dir_ipconf/$file_ipconf" cp "$file_ipconf" "$dir_ipconf/$file_ipconf"
sv u /var/service/fw sv u /var/service/fw
fi fi
./convert2ntpconf "$file_ntpconf" if test -d /var/service/ntp; then
# Reconfigure ntp server addresses if needed ./convert2ntpconf "$file_ntpconf"
diff --brief "$file_ntpconf" "$dir_ntpconf/$file_ntpconf" >/dev/null 2>&1 # Reconfigure ntp server addresses if needed
if test "$?" != "0"; then diff --brief "$file_ntpconf" "$dir_ntpconf/$file_ntpconf" >/dev/null 2>&1
echo "Reconfiguring ntp" if test $? != 0; then
mkdir -p "$dir_ntpconf" 2>/dev/null echo "Reconfiguring ntp"
cp "$file_ntpconf" "$dir_ntpconf/$file_ntpconf" mkdir -p "$dir_ntpconf" 2>/dev/null
sv t /var/service/ntp cp "$file_ntpconf" "$dir_ntpconf/$file_ntpconf"
sv u /var/service/ntp sv t /var/service/ntp
sv u /var/service/ntp
fi
fi fi

View File

@ -1,5 +1,6 @@
#!/bin/sh #!/bin/sh
#exec >/dev/null
exec 2>&1 exec 2>&1
exec </dev/null exec </dev/null
@ -12,9 +13,13 @@ exec \
env - PATH="$PATH" \ env - PATH="$PATH" \
softlimit \ softlimit \
setuidgid root \ setuidgid root \
ifplugd -apqns -t3 -u9 -d9 -i "$if" -r "$pwd/ifplugd_handler" ifplugd -apqns -t3 -u8 -d8 -i "$if" -r "$pwd/ifplugd_handler"
# we use -t3 to wake ifplugd up less often # We use -t3 to wake ifplugd up less often.
# If after three tests (3*3=9 > 8) link state seen to be different,
# the handler will be called.
# IOW: short link losses will be ignored, longer ones
# will trigger DHCP reconfiguration and such (see handler code).
#-a Do not up interface automatically #-a Do not up interface automatically
#-p Dont run script on daemon startup #-p Dont run script on daemon startup