aboutsummaryrefslogtreecommitdiff
path: root/examples/var_service
diff options
context:
space:
mode:
Diffstat (limited to 'examples/var_service')
-rw-r--r--examples/var_service/zcip_if/README5
-rwxr-xr-xexamples/var_service/zcip_if/convert2ipconf22
-rwxr-xr-xexamples/var_service/zcip_if/log/run21
-rwxr-xr-xexamples/var_service/zcip_if/p_log4
-rwxr-xr-xexamples/var_service/zcip_if/run20
-rwxr-xr-xexamples/var_service/zcip_if/w_log4
-rwxr-xr-xexamples/var_service/zcip_if/zcip_handler46
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 @@
+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 </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 000000000..aa36ef13b
--- /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 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