New example of a service: examples/var_service/zcip_if
No binary (build failed)
—
(log yok)
| @@ -0,0 +1,5 @@ | |
| + | The real README file is one directory up. |
| + | |
| + | This directory's run script can have useful comments. |
| + | If it doesn't but you feel it should, please send a patch |
| + | to busybox's mailing list. |
| @@ -0,0 +1,22 @@ | |
| + | #!/bin/sh |
| + | # convert: |
| + | |
| + | #interface=eth1 |
| + | #ip=169.254.x.y |
| + | |
| + | #let cfg=cfg+1 |
| + | #if[$cfg]=...; ip[$cfg]=...; ipmask[$cfg]=.../...; gw[$cfg]=...; net[$cfg]=... dns[$cfg]=... |
| + | |
| + | exec >/dev/null |
| + | #exec >"$0.out" # debug |
| + | exec 2>&1 |
| + | |
| + | test "$interface" || exit 1 |
| + | test "$ip" || exit 1 |
| + | |
| + | { |
| + | echo "let cfg=cfg+1" |
| + | test "$interface" && echo "if[\$cfg]='$interface'" |
| + | test "$ip" && echo "ip[\$cfg]='$ip'" |
| + | test "$ip" && echo "ipmask[\$cfg]='$ip/16'" |
| + | } >"$1" |
| @@ -0,0 +1,21 @@ | |
| + | #!/bin/sh |
| + | |
| + | user=logger |
| + | |
| + | logdir="/var/log/service/`(cd ..;basename $PWD)`" |
| + | mkdir -p "$logdir" 2>/dev/null |
| + | chown -R "$user": "$logdir" |
| + | chmod -R go-rwxst,u+rwX "$logdir" |
| + | rm logdir |
| + | ln -s "$logdir" logdir |
| + | |
| + | # make this dir accessible to logger |
| + | chmod a+rX . |
| + | |
| + | exec >/dev/null |
| + | exec 2>&1 |
| + | exec \ |
| + | env - PATH="$PATH" \ |
| + | softlimit \ |
| + | setuidgid "$user" \ |
| + | svlogd -tt "$logdir" |
| @@ -0,0 +1,4 @@ | |
| + | #!/bin/sh |
| + | |
| + | cd log/logdir || exit 1 |
| + | cat @* current | $PAGER |
| @@ -0,0 +1,20 @@ | |
| + | #!/bin/sh |
| + | |
| + | exec 2>&1 |
| + | exec </dev/null |
| + | |
| + | pwd="$PWD" |
| + | |
| + | if="${PWD##*/zcip_}" |
| + | |
| + | echo "* Upping iface $if" |
| + | ip link set dev "$if" up |
| + | |
| + | echo "* Starting zcip" |
| + | exec \ |
| + | env - PATH="$PATH" \ |
| + | softlimit \ |
| + | setuidgid root \ |
| + | zcip -fvv \ |
| + | "$if" \ |
| + | "$pwd/zcip_handler" |
| @@ -0,0 +1,4 @@ | |
| + | #!/bin/sh |
| + | |
| + | cd log/logdir || exit 1 |
| + | watch -n2 'w=`ttysize w`; h=`ttysize h`; tail -$((h-3)) current 2>&1 | cut -b1-$((w-2))' |
| @@ -0,0 +1,46 @@ | |
| + | #!/bin/sh |
| + | # executed by zcip |
| + | # parameters: $1 and environment |
| + | # $1 is: |
| + | # |
| + | # init: zcip starts. Environment: |
| + | # interface=eth0 |
| + | # |
| + | # config: Address is obtained. |
| + | # interface=eth0 |
| + | # ip=169.254.a.b |
| + | # |
| + | # deconfig: Conflict or link went down. |
| + | # interface=eth0 |
| + | |
| + | service=${PWD##*/} |
| + | file_ipconf="$service.ipconf" |
| + | dir_ipconf="/var/run/service/fw" |
| + | |
| + | exec >/dev/null |
| + | #exec >>"$0.out" #debug |
| + | exec 2>&1 |
| + | |
| + | echo "`date`: Params: $*" |
| + | |
| + | if test x"$1" != x"config"; then |
| + | # Reconfigure network with this interface disabled |
| + | echo "Deconfiguring" |
| + | rm "$file_ipconf" |
| + | rm "$dir_ipconf/$file_ipconf" |
| + | sv u /var/service/fw |
| + | exit |
| + | fi |
| + | |
| + | # "config": we've got the address |
| + | #env # debug |
| + | |
| + | ./convert2ipconf "$file_ipconf" |
| + | # Reconfigure routing and firewall if needed |
| + | diff --brief "$file_ipconf" "$dir_ipconf/$file_ipconf" >/dev/null 2>&1 |
| + | if test $? != 0; then |
| + | echo "Reconfiguring fw" |
| + | mkdir -p "$dir_ipconf" 2>/dev/null |
| + | cp "$file_ipconf" "$dir_ipconf/$file_ipconf" |
| + | sv u /var/service/fw |
| + | fi |