diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-03-30 20:49:16 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-03-30 20:49:16 +0200 |
commit | df65dc89b428c8f66ee2203f4a14eb2592d89ee0 (patch) | |
tree | 30fe6378dbeb4f594099b2fc26e3037729d4dfeb | |
parent | d9503224c8a93a30b0c8627084b2744d3ee6f403 (diff) | |
download | busybox-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/README | 10 | ||||
-rw-r--r-- | examples/var_service/dnsmasq/dnsmasq.conf | 76 | ||||
-rwxr-xr-x | examples/var_service/dnsmasq/log/run | 21 | ||||
-rwxr-xr-x | examples/var_service/dnsmasq/p_log | 4 | ||||
-rwxr-xr-x | examples/var_service/dnsmasq/run | 12 | ||||
-rwxr-xr-x | examples/var_service/dnsmasq/w_log | 4 | ||||
-rw-r--r-- | examples/var_service/fw/etc/dnsmasq_servers.conf | 38 |
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 @@ | |||
1 | Local DNS cache service. | ||
2 | |||
3 | This service is useful if you have more than 3 DNS servers, | ||
4 | or if you need a finer-grained control of which servers | ||
5 | can serve which domain. | ||
6 | |||
7 | To make programs use local DNS server, make sure | ||
8 | /etc/resolv.conf says: | ||
9 | |||
10 | nameserver 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 @@ | |||
1 | keep-in-foreground | ||
2 | |||
3 | # "-" is stderr: | ||
4 | log-facility=- | ||
5 | |||
6 | # May also try log-queries=extra | ||
7 | log-queries | ||
8 | |||
9 | # No param = pidfile disabled: | ||
10 | pid-file | ||
11 | |||
12 | interface=lo | ||
13 | listen-address=127.0.0.1 | ||
14 | bind-interfaces | ||
15 | |||
16 | cache-size=999 | ||
17 | |||
18 | servers-file=/etc/dnsmasq_servers.conf | ||
19 | |||
20 | # Don’t read /etc/resolv.conf and /etc/hosts: | ||
21 | no-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. | ||
40 | local-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. | ||
55 | neg-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. | ||
72 | min-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 | |||
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 -rf 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/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 | |||
3 | cd log/logdir || exit 1 | ||
4 | cat @* 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 | ||
4 | exec 2>&1 | ||
5 | exec </dev/null | ||
6 | |||
7 | echo "* Starting dnsmasq" | ||
8 | exec \ | ||
9 | env - PATH="$PATH" \ | ||
10 | softlimit \ | ||
11 | setuidgid root \ | ||
12 | dnsmasq -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 | |||
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/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 | |||
3 | empty=true | ||
4 | |||
5 | prio=0 | ||
6 | i=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]}" | ||
10 | let i++; done | ||
11 | |||
12 | i=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++; | ||
31 | done | ||
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 | ||
38 | sv h dnsmasq | ||