aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-03-30 20:49:16 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-03-30 20:49:16 +0200
commitdf65dc89b428c8f66ee2203f4a14eb2592d89ee0 (patch)
tree30fe6378dbeb4f594099b2fc26e3037729d4dfeb
parentd9503224c8a93a30b0c8627084b2744d3ee6f403 (diff)
downloadbusybox-w32-df65dc89b428c8f66ee2203f4a14eb2592d89ee0.tar.gz
busybox-w32-df65dc89b428c8f66ee2203f4a14eb2592d89ee0.tar.bz2
busybox-w32-df65dc89b428c8f66ee2203f4a14eb2592d89ee0.zip
examples/var_service: new example: dnsmasq service
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--examples/var_service/dnsmasq/README10
-rw-r--r--examples/var_service/dnsmasq/dnsmasq.conf76
-rwxr-xr-xexamples/var_service/dnsmasq/log/run21
-rwxr-xr-xexamples/var_service/dnsmasq/p_log4
-rwxr-xr-xexamples/var_service/dnsmasq/run12
-rwxr-xr-xexamples/var_service/dnsmasq/w_log4
-rw-r--r--examples/var_service/fw/etc/dnsmasq_servers.conf38
7 files changed, 165 insertions, 0 deletions
diff --git a/examples/var_service/dnsmasq/README b/examples/var_service/dnsmasq/README
new file mode 100644
index 000000000..a20740d6e
--- /dev/null
+++ b/examples/var_service/dnsmasq/README
@@ -0,0 +1,10 @@
1Local DNS cache service.
2
3This service is useful if you have more than 3 DNS servers,
4or if you need a finer-grained control of which servers
5can serve which domain.
6
7To make programs use local DNS server, make sure
8/etc/resolv.conf says:
9
10nameserver 127.0.0.1
diff --git a/examples/var_service/dnsmasq/dnsmasq.conf b/examples/var_service/dnsmasq/dnsmasq.conf
new file mode 100644
index 000000000..2cfb0fe81
--- /dev/null
+++ b/examples/var_service/dnsmasq/dnsmasq.conf
@@ -0,0 +1,76 @@
1keep-in-foreground
2
3# "-" is stderr:
4log-facility=-
5
6# May also try log-queries=extra
7log-queries
8
9# No param = pidfile disabled:
10pid-file
11
12interface=lo
13listen-address=127.0.0.1
14bind-interfaces
15
16cache-size=999
17
18servers-file=/etc/dnsmasq_servers.conf
19
20# Don’t read /etc/resolv.conf and /etc/hosts:
21no-resolv
22#no-hosts
23
24# All reverse lookups for private IP ranges (ie 192.168.x.x, etc)
25# which are not found in /etc/hosts or the DHCP leases file are
26# answered with "no such domain" rather than being forwarded
27# upstream. The set of prefixes affected is the list given in
28# RFC6303.
29#bogus-priv
30
31#−T, --local-ttl=<time>
32# When replying with information from /etc/hosts or configuration
33# or the DHCP leases file dnsmasq by default sets the time-to-live
34# field to zero, meaning that the requester should not itself
35# cache the information. This is the correct thing to do in almost
36# all situations. This option allows a time-to-live (in seconds)
37# to be given for these replies. This will reduce the load on the
38# server at the expense of clients using stale data under some
39# circumstances.
40local-ttl=67
41
42#--dhcp-ttl=<time>
43# As for --local-ttl, but affects only replies with information
44# from DHCP leases. If both are given, --dhcp-ttl applies for DHCP
45# information, and --local-ttl for others. Setting this to zero
46# eliminates the effect of --local-ttl for DHCP.
47#
48#--neg-ttl=<time>
49# Negative replies from upstream servers normally contain time-to-
50# live information in SOA records which dnsmasq uses for caching.
51# If the replies from upstream servers omit this information, dns-
52# masq does not cache the reply. This option gives a default value
53# for time-to-live (in seconds) which dnsmasq uses to cache nega-
54# tive replies even in the absence of an SOA record.
55neg-ttl=67
56
57#--max-ttl=<time>
58# Set a maximum TTL value that will be handed out to clients. The
59# specified maximum TTL will be given to clients instead of the
60# true TTL value if it is lower. The true TTL value is however
61# kept in the cache to avoid flooding the upstream DNS servers.
62#
63#--max-cache-ttl=<time>
64# Set a maximum TTL value for entries in the cache.
65#
66#--min-cache-ttl=<time>
67# Extend short TTL values to the time given when caching them.
68# Note that artificially extending TTL values is in general a bad
69# idea, do not do it unless you have a good reason, and understand
70# what you are doing. Dnsmasq limits the value of this option to
71# one hour, unless recompiled.
72min-cache-ttl=67
73
74#--auth-ttl=<time>
75# Set the TTL value returned in answers from the authoritative
76# server.
diff --git a/examples/var_service/dnsmasq/log/run b/examples/var_service/dnsmasq/log/run
new file mode 100755
index 000000000..69d74b73f
--- /dev/null
+++ b/examples/var_service/dnsmasq/log/run
@@ -0,0 +1,21 @@
1#!/bin/sh
2
3user=logger
4
5logdir="/var/log/service/`(cd ..;basename $PWD)`"
6mkdir -p "$logdir" 2>/dev/null
7chown -R "$user": "$logdir"
8chmod -R go-rwxst,u+rwX "$logdir"
9rm -rf logdir
10ln -s "$logdir" logdir
11
12# make this dir accessible to logger
13chmod a+rX .
14
15exec >/dev/null
16exec 2>&1
17exec \
18env - PATH="$PATH" \
19softlimit \
20setuidgid "$user" \
21svlogd -tt "$logdir"
diff --git a/examples/var_service/dnsmasq/p_log b/examples/var_service/dnsmasq/p_log
new file mode 100755
index 000000000..a2521be05
--- /dev/null
+++ b/examples/var_service/dnsmasq/p_log
@@ -0,0 +1,4 @@
1#!/bin/sh
2
3cd log/logdir || exit 1
4cat @* current | $PAGER
diff --git a/examples/var_service/dnsmasq/run b/examples/var_service/dnsmasq/run
new file mode 100755
index 000000000..2ac94282f
--- /dev/null
+++ b/examples/var_service/dnsmasq/run
@@ -0,0 +1,12 @@
1#!/bin/sh
2
3#exec >/dev/null
4exec 2>&1
5exec </dev/null
6
7echo "* Starting dnsmasq"
8exec \
9env - PATH="$PATH" \
10softlimit \
11setuidgid root \
12dnsmasq -C dnsmasq.conf
diff --git a/examples/var_service/dnsmasq/w_log b/examples/var_service/dnsmasq/w_log
new file mode 100755
index 000000000..aa36ef13b
--- /dev/null
+++ b/examples/var_service/dnsmasq/w_log
@@ -0,0 +1,4 @@
1#!/bin/sh
2
3cd log/logdir || exit 1
4watch -n2 'w=`ttysize w`; h=`ttysize h`; tail -$((h-3)) current 2>&1 | cut -b1-$((w-2))'
diff --git a/examples/var_service/fw/etc/dnsmasq_servers.conf b/examples/var_service/fw/etc/dnsmasq_servers.conf
new file mode 100644
index 000000000..68313605f
--- /dev/null
+++ b/examples/var_service/fw/etc/dnsmasq_servers.conf
@@ -0,0 +1,38 @@
1#!/bin/bash
2
3empty=true
4
5prio=0
6i=0; while test "${if[$i]}"; do
7 test x"${dns_prio[$i]}" != x"" \
8 && test "${dns_prio[$i]}" -gt "$prio" \
9 && prio="${dns_prio[$i]}"
10let i++; done
11
12i=0; while test "${if[$i]}"; do
13 if test "${dnsmasq[$i]}"; then
14 for d in ${dnsmasq[$i]}; do
15 echo "$d"
16 empty=false
17 done
18 let i++;
19 continue
20 fi
21 # This iface has no dnsmasq-extended config.
22 # Use simple DNS names instead, if those exist.
23 for d in ${dns[$i]}; do
24 p="${dns_prio[$i]}"
25 test x"$p" == x"" && p=0
26 test x"$p" == x"$prio" || continue
27 echo "server=$d"
28 empty=false
29 done
30 let i++;
31done
32
33# Use Google DNS servers if nothing else is configured
34$empty && echo "server=8.8.8.8"
35$empty && echo "server=8.8.4.4"
36
37# SIGHUP: make dnsmasq reload config
38sv h dnsmasq