diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-13 22:07:34 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-13 22:07:34 +0100 |
commit | 4fc82e0067db4b54ee05d56feaa4fb981d380e5f (patch) | |
tree | 9b43ce7590e327e87010f54708640b6ff9ee385b /examples/var_service/ntpd | |
parent | c041e239dbc02b99ee9a5a86bed6dc859ff956db (diff) | |
download | busybox-w32-4fc82e0067db4b54ee05d56feaa4fb981d380e5f.tar.gz busybox-w32-4fc82e0067db4b54ee05d56feaa4fb981d380e5f.tar.bz2 busybox-w32-4fc82e0067db4b54ee05d56feaa4fb981d380e5f.zip |
examples: add example ntpd service
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'examples/var_service/ntpd')
-rwxr-xr-x | examples/var_service/ntpd/log/run | 21 | ||||
-rwxr-xr-x | examples/var_service/ntpd/ntp.script | 29 | ||||
-rwxr-xr-x | examples/var_service/ntpd/p_log | 4 | ||||
-rwxr-xr-x | examples/var_service/ntpd/run | 60 | ||||
-rwxr-xr-x | examples/var_service/ntpd/w_log | 4 |
5 files changed, 118 insertions, 0 deletions
diff --git a/examples/var_service/ntpd/log/run b/examples/var_service/ntpd/log/run new file mode 100755 index 000000000..560d1b19f --- /dev/null +++ b/examples/var_service/ntpd/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/ntpd/ntp.script b/examples/var_service/ntpd/ntp.script new file mode 100755 index 000000000..90299ae8e --- /dev/null +++ b/examples/var_service/ntpd/ntp.script | |||
@@ -0,0 +1,29 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | exec 2>/dev/null | ||
4 | echo "`tail -n 99 "$0.log"`" >"$0.log" | ||
5 | |||
6 | exec >>"$0.log" | ||
7 | exec 2>&1 | ||
8 | |||
9 | dt=`date '+%Y-%m-%d %H:%M:%S'` | ||
10 | |||
11 | if test x"$stratum" != x"" \ | ||
12 | && test x"$poll_interval" != x"" \ | ||
13 | && test 4 -ge "$stratum" \ | ||
14 | && test 128 -le "$poll_interval" \ | ||
15 | ; then | ||
16 | echo "$dt: $1"\ | ||
17 | "freq_drift_ppm=$freq_drift_ppm"\ | ||
18 | "offset=$offset"\ | ||
19 | "stratum=$stratum"\ | ||
20 | "poll_interval=$poll_interval,"\ | ||
21 | "setting hardware clock" | ||
22 | exec hwclock --systohc | ||
23 | fi | ||
24 | |||
25 | echo "$dt: $1"\ | ||
26 | "freq_drift_ppm=$freq_drift_ppm"\ | ||
27 | "offset=$offset"\ | ||
28 | "stratum=$stratum"\ | ||
29 | "poll_interval=$poll_interval"\ | ||
diff --git a/examples/var_service/ntpd/p_log b/examples/var_service/ntpd/p_log new file mode 100755 index 000000000..a2521be05 --- /dev/null +++ b/examples/var_service/ntpd/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/ntpd/run b/examples/var_service/ntpd/run new file mode 100755 index 000000000..581d231a3 --- /dev/null +++ b/examples/var_service/ntpd/run | |||
@@ -0,0 +1,60 @@ | |||
1 | #!/bin/bash | ||
2 | # (using bashism (arrays) in dhcp config) | ||
3 | |||
4 | #exec >/dev/null | ||
5 | exec 2>&1 | ||
6 | exec </dev/null | ||
7 | |||
8 | user=root | ||
9 | pool="us.pool.ntp.org" # replace "us" with your country code | ||
10 | |||
11 | service="${PWD##*/}" | ||
12 | rundir="/var/run/service/$service" | ||
13 | default_p_opt="-p 0.$pool -p 1.$pool -p 2.$pool -p 3.$pool" | ||
14 | |||
15 | |||
16 | # Make sure rundir/ exists | ||
17 | mkdir -p "$rundir" 2>/dev/null | ||
18 | chown -R "$user:" "$rundir" | ||
19 | chmod -R a=rX "$rundir" | ||
20 | rm -rf rundir 2>/dev/null | ||
21 | ln -s "$rundir" rundir | ||
22 | |||
23 | |||
24 | echo "* Checking network" | ||
25 | test -f /var/run/service/fw/up || exec sleep 7 | ||
26 | sleep 5 # to let it settle | ||
27 | |||
28 | # Grab config from dhcp | ||
29 | cfg=-1 | ||
30 | for f in rundir/*.ntpconf; do | ||
31 | test -f "$f" || continue | ||
32 | . "$f" | ||
33 | done | ||
34 | |||
35 | # Select peers | ||
36 | p_opt="" | ||
37 | cfg=0 | ||
38 | while test x"${ntpip[$cfg]}" != x""; do | ||
39 | p_opt="$p_opt -p ${ntpip[$cfg]}" | ||
40 | let cfg=cfg+1 | ||
41 | done | ||
42 | test x"$p_opt" == x"" && p_opt="$default_p_opt" | ||
43 | |||
44 | if test x"$p_opt" == x""; then | ||
45 | echo "* No NTP peers configured, stopping" | ||
46 | sv o . | ||
47 | exec sleep 1 | ||
48 | fi | ||
49 | |||
50 | |||
51 | # Let others know that we are up | ||
52 | date '+%Y-%m-%d %H:%M:%S %Z' >rundir/up | ||
53 | |||
54 | # Go go go | ||
55 | echo "* Starting ntpd[$$]" | ||
56 | exec \ | ||
57 | env - PATH="$PATH" \ | ||
58 | softlimit \ | ||
59 | setuidgid "$user" \ | ||
60 | ntpd -ddnNl -S ./ntp.script $p_opt | ||
diff --git a/examples/var_service/ntpd/w_log b/examples/var_service/ntpd/w_log new file mode 100755 index 000000000..34b19b373 --- /dev/null +++ b/examples/var_service/ntpd/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 -b0-$((w-2))' | ||