summaryrefslogtreecommitdiff
path: root/examples/var_service
diff options
context:
space:
mode:
authorDenys Vlasenko2016-10-03 23:43:44 +0200
committerDenys Vlasenko2016-10-03 23:43:44 +0200
commit095ddf7669a05b52839ccbfd2c324de718241747 (patch)
tree61fe4384e08985b5a217f9d4456da3e51875f606 /examples/var_service
parent7f0ebbc69ed14b2f35e8bc62b03612b94e270955 (diff)
downloadbusybox-095ddf7669a05b52839ccbfd2c324de718241747.zip
busybox-095ddf7669a05b52839ccbfd2c324de718241747.tar.gz
examples: add example of a DHCP server
As usual, by multiplying directories - "dhcpd_eth0", "dhcpd_wlan1" you can run many servers on different interfaces. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'examples/var_service')
-rw-r--r--examples/var_service/dhcpd_if/README5
-rwxr-xr-xexamples/var_service/dhcpd_if/log/run21
-rwxr-xr-xexamples/var_service/dhcpd_if/p_log4
-rwxr-xr-xexamples/var_service/dhcpd_if/run23
-rw-r--r--examples/var_service/dhcpd_if/udhcpc.conf28
-rwxr-xr-xexamples/var_service/dhcpd_if/w_dumpleases3
-rwxr-xr-xexamples/var_service/dhcpd_if/w_dumpleases_countdown3
-rwxr-xr-xexamples/var_service/dhcpd_if/w_log4
8 files changed, 91 insertions, 0 deletions
diff --git a/examples/var_service/dhcpd_if/README b/examples/var_service/dhcpd_if/README
new file mode 100644
index 0000000..4ddccb2
--- /dev/null
+++ b/examples/var_service/dhcpd_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/dhcpd_if/log/run b/examples/var_service/dhcpd_if/log/run
new file mode 100755
index 0000000..69d74b7
--- /dev/null
+++ b/examples/var_service/dhcpd_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 -rf 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/dhcpd_if/p_log b/examples/var_service/dhcpd_if/p_log
new file mode 100755
index 0000000..a2521be
--- /dev/null
+++ b/examples/var_service/dhcpd_if/p_log
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+cd log/logdir || exit 1
+cat @* current | $PAGER
diff --git a/examples/var_service/dhcpd_if/run b/examples/var_service/dhcpd_if/run
new file mode 100755
index 0000000..de85dec
--- /dev/null
+++ b/examples/var_service/dhcpd_if/run
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+exec 2>&1
+exec </dev/null
+
+pwd="$PWD"
+
+if="${PWD##*/dhcpd_}"
+
+echo "* Upping iface $if"
+ip link set dev $if up
+
+>>udhcpd.leases
+sed 's/^interface.*$/interface '"$if/" -i udhcpc.conf
+
+echo "* Starting udhcpd"
+exec \
+env - PATH="$PATH" \
+softlimit \
+setuidgid root \
+udhcpd -f -vv udhcpc.conf
+
+exit $?
diff --git a/examples/var_service/dhcpd_if/udhcpc.conf b/examples/var_service/dhcpd_if/udhcpc.conf
new file mode 100644
index 0000000..a819259
--- /dev/null
+++ b/examples/var_service/dhcpd_if/udhcpc.conf
@@ -0,0 +1,28 @@
+# Directives with defaults:
+# start 192.168.0.20
+# end 192.168.0.254
+# interface eth0
+# max_leases 235
+# auto_time 7200
+# decline_time 3600
+# conflict_time 3600
+# offer_time 60
+# min_lease 60
+# lease_file /var/lib/misc/udhcpd.leases
+# pidfile /var/run/udhcpd.pid
+# siaddr 0.0.0.0
+#
+# Directives with no defaults (or with empty defaults):
+# option/opt NAME VALUE
+# notify_file /path/to/script_to_run_after_leasefile_is_written
+# (it is run with $1 = lease_file_name)
+# sname dhcp_packet_sname_field_contents
+# boot_file dhcp_packet_bootfile_field_contents
+# static_lease XX:XX:XX:XX:XX:XX IP.ADD.RE.SS
+
+interface if
+pidfile /dev/null
+lease_file udhcpd.leases
+option subnet 255.255.255.0
+option lease 3600
+#option router 192.168.0.1
diff --git a/examples/var_service/dhcpd_if/w_dumpleases b/examples/var_service/dhcpd_if/w_dumpleases
new file mode 100755
index 0000000..ff77205
--- /dev/null
+++ b/examples/var_service/dhcpd_if/w_dumpleases
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+watch -n1 'dumpleases -af udhcpd.leases'
diff --git a/examples/var_service/dhcpd_if/w_dumpleases_countdown b/examples/var_service/dhcpd_if/w_dumpleases_countdown
new file mode 100755
index 0000000..7fcd960
--- /dev/null
+++ b/examples/var_service/dhcpd_if/w_dumpleases_countdown
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+watch -n1 'dumpleases -f udhcpd.leases'
diff --git a/examples/var_service/dhcpd_if/w_log b/examples/var_service/dhcpd_if/w_log
new file mode 100755
index 0000000..dba76c6
--- /dev/null
+++ b/examples/var_service/dhcpd_if/w_log
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+cd log/logdir
+watch -n1 'w=`ttysize w`; h=`ttysize h`; tail -$((h-3)) current 2>&1 | cut -b0-$((w-2))'