diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-24 05:30:58 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-24 05:30:58 +0200 |
commit | d32a1a4054444d8193736ee4c5f515fa90dbb24f (patch) | |
tree | 4c0864109b27817fdfa78198c529f941555b5b23 | |
parent | 9a512176686d5f1548dc1e1c610af440a3ee0d73 (diff) | |
download | busybox-w32-d32a1a4054444d8193736ee4c5f515fa90dbb24f.tar.gz busybox-w32-d32a1a4054444d8193736ee4c5f515fa90dbb24f.tar.bz2 busybox-w32-d32a1a4054444d8193736ee4c5f515fa90dbb24f.zip |
New example of a service: examples/var_service/zcip_if
Zeroconf for IPv4
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-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 000000000..4ddccb22d --- /dev/null +++ b/examples/var_service/zcip_if/README | |||
@@ -0,0 +1,5 @@ | |||
1 | The real README file is one directory up. | ||
2 | |||
3 | This directory's run script can have useful comments. | ||
4 | If it doesn't but you feel it should, please send a patch | ||
5 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | # convert: | ||
3 | |||
4 | #interface=eth1 | ||
5 | #ip=169.254.x.y | ||
6 | |||
7 | #let cfg=cfg+1 | ||
8 | #if[$cfg]=...; ip[$cfg]=...; ipmask[$cfg]=.../...; gw[$cfg]=...; net[$cfg]=... dns[$cfg]=... | ||
9 | |||
10 | exec >/dev/null | ||
11 | #exec >"$0.out" # debug | ||
12 | exec 2>&1 | ||
13 | |||
14 | test "$interface" || exit 1 | ||
15 | test "$ip" || exit 1 | ||
16 | |||
17 | { | ||
18 | echo "let cfg=cfg+1" | ||
19 | test "$interface" && echo "if[\$cfg]='$interface'" | ||
20 | test "$ip" && echo "ip[\$cfg]='$ip'" | ||
21 | test "$ip" && echo "ipmask[\$cfg]='$ip/16'" | ||
22 | } >"$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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | user=logger | ||
4 | |||
5 | logdir="/var/log/service/`(cd ..;basename $PWD)`" | ||
6 | mkdir -p "$logdir" 2>/dev/null | ||
7 | chown -R "$user": "$logdir" | ||
8 | chmod -R go-rwxst,u+rwX "$logdir" | ||
9 | rm logdir | ||
10 | ln -s "$logdir" logdir | ||
11 | |||
12 | # make this dir accessible to logger | ||
13 | chmod a+rX . | ||
14 | |||
15 | exec >/dev/null | ||
16 | exec 2>&1 | ||
17 | exec \ | ||
18 | env - PATH="$PATH" \ | ||
19 | softlimit \ | ||
20 | setuidgid "$user" \ | ||
21 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd log/logdir || exit 1 | ||
4 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | exec 2>&1 | ||
4 | exec </dev/null | ||
5 | |||
6 | pwd="$PWD" | ||
7 | |||
8 | if="${PWD##*/zcip_}" | ||
9 | |||
10 | echo "* Upping iface $if" | ||
11 | ip link set dev "$if" up | ||
12 | |||
13 | echo "* Starting zcip" | ||
14 | exec \ | ||
15 | env - PATH="$PATH" \ | ||
16 | softlimit \ | ||
17 | setuidgid root \ | ||
18 | zcip -fvv \ | ||
19 | "$if" \ | ||
20 | "$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 000000000..aa36ef13b --- /dev/null +++ b/examples/var_service/zcip_if/w_log | |||
@@ -0,0 +1,4 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd log/logdir || exit 1 | ||
4 | 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 000000000..13010db27 --- /dev/null +++ b/examples/var_service/zcip_if/zcip_handler | |||
@@ -0,0 +1,46 @@ | |||
1 | #!/bin/sh | ||
2 | # executed by zcip | ||
3 | # parameters: $1 and environment | ||
4 | # $1 is: | ||
5 | # | ||
6 | # init: zcip starts. Environment: | ||
7 | # interface=eth0 | ||
8 | # | ||
9 | # config: Address is obtained. | ||
10 | # interface=eth0 | ||
11 | # ip=169.254.a.b | ||
12 | # | ||
13 | # deconfig: Conflict or link went down. | ||
14 | # interface=eth0 | ||
15 | |||
16 | service=${PWD##*/} | ||
17 | file_ipconf="$service.ipconf" | ||
18 | dir_ipconf="/var/run/service/fw" | ||
19 | |||
20 | exec >/dev/null | ||
21 | #exec >>"$0.out" #debug | ||
22 | exec 2>&1 | ||
23 | |||
24 | echo "`date`: Params: $*" | ||
25 | |||
26 | if test x"$1" != x"config"; then | ||
27 | # Reconfigure network with this interface disabled | ||
28 | echo "Deconfiguring" | ||
29 | rm "$file_ipconf" | ||
30 | rm "$dir_ipconf/$file_ipconf" | ||
31 | sv u /var/service/fw | ||
32 | exit | ||
33 | fi | ||
34 | |||
35 | # "config": we've got the address | ||
36 | #env # debug | ||
37 | |||
38 | ./convert2ipconf "$file_ipconf" | ||
39 | # Reconfigure routing and firewall if needed | ||
40 | diff --brief "$file_ipconf" "$dir_ipconf/$file_ipconf" >/dev/null 2>&1 | ||
41 | if test $? != 0; then | ||
42 | echo "Reconfiguring fw" | ||
43 | mkdir -p "$dir_ipconf" 2>/dev/null | ||
44 | cp "$file_ipconf" "$dir_ipconf/$file_ipconf" | ||
45 | sv u /var/service/fw | ||
46 | fi | ||