From d32a1a4054444d8193736ee4c5f515fa90dbb24f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 24 Oct 2015 05:30:58 +0200 Subject: New example of a service: examples/var_service/zcip_if Zeroconf for IPv4 Signed-off-by: Denys Vlasenko --- examples/var_service/zcip_if/README | 5 ++++ examples/var_service/zcip_if/convert2ipconf | 22 ++++++++++++++ examples/var_service/zcip_if/log/run | 21 +++++++++++++ examples/var_service/zcip_if/p_log | 4 +++ examples/var_service/zcip_if/run | 20 +++++++++++++ examples/var_service/zcip_if/w_log | 4 +++ examples/var_service/zcip_if/zcip_handler | 46 +++++++++++++++++++++++++++++ 7 files changed, 122 insertions(+) create mode 100644 examples/var_service/zcip_if/README create mode 100755 examples/var_service/zcip_if/convert2ipconf create mode 100755 examples/var_service/zcip_if/log/run create mode 100755 examples/var_service/zcip_if/p_log create mode 100755 examples/var_service/zcip_if/run create mode 100755 examples/var_service/zcip_if/w_log create mode 100755 examples/var_service/zcip_if/zcip_handler diff --git a/examples/var_service/zcip_if/README b/examples/var_service/zcip_if/README new file mode 100644 index 000000000..4ddccb22d --- /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 000000000..aa133d815 --- /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 000000000..560d1b19f --- /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 000000000..a2521be05 --- /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 000000000..94a875465 --- /dev/null +++ b/examples/var_service/zcip_if/run @@ -0,0 +1,20 @@ +#!/bin/sh + +exec 2>&1 +exec &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 000000000..13010db27 --- /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 -- cgit v1.2.3