diff options
Diffstat (limited to 'examples/var_service')
-rw-r--r-- | examples/var_service/zcip_if/README | 5 | ||||
-rwxr-xr-x | examples/var_service/zcip_if/convert2ipconf | 22 | ||||
-rwxr-xr-x | examples/var_service/zcip_if/log/run | 21 | ||||
-rwxr-xr-x | examples/var_service/zcip_if/p_log | 4 | ||||
-rwxr-xr-x | examples/var_service/zcip_if/run | 20 | ||||
-rwxr-xr-x | examples/var_service/zcip_if/w_log | 4 | ||||
-rwxr-xr-x | examples/var_service/zcip_if/zcip_handler | 46 |
7 files changed, 122 insertions, 0 deletions
diff --git a/examples/var_service/zcip_if/README b/examples/var_service/zcip_if/README new file mode 100644 index 0000000..4ddccb2 --- /dev/null +++ b/examples/var_service/zcip_if/README @@ -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. diff --git a/examples/var_service/zcip_if/convert2ipconf b/examples/var_service/zcip_if/convert2ipconf new file mode 100755 index 0000000..aa133d8 --- /dev/null +++ b/examples/var_service/zcip_if/convert2ipconf @@ -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" diff --git a/examples/var_service/zcip_if/log/run b/examples/var_service/zcip_if/log/run new file mode 100755 index 0000000..560d1b1 --- /dev/null +++ b/examples/var_service/zcip_if/log/run @@ -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" diff --git a/examples/var_service/zcip_if/p_log b/examples/var_service/zcip_if/p_log new file mode 100755 index 0000000..a2521be --- /dev/null +++ b/examples/var_service/zcip_if/p_log @@ -0,0 +1,4 @@ +#!/bin/sh + +cd log/logdir || exit 1 +cat @* current | $PAGER diff --git a/examples/var_service/zcip_if/run b/examples/var_service/zcip_if/run new file mode 100755 index 0000000..94a8754 --- /dev/null +++ b/examples/var_service/zcip_if/run @@ -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" diff --git a/examples/var_service/zcip_if/w_log b/examples/var_service/zcip_if/w_log new file mode 100755 index 0000000..aa36ef1 --- /dev/null +++ b/examples/var_service/zcip_if/w_log @@ -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))' diff --git a/examples/var_service/zcip_if/zcip_handler b/examples/var_service/zcip_if/zcip_handler new file mode 100755 index 0000000..13010db --- /dev/null +++ b/examples/var_service/zcip_if/zcip_handler @@ -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 |