aboutsummaryrefslogtreecommitdiff
path: root/examples/var_service/ntpd
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-01-13 22:07:34 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-01-13 22:07:34 +0100
commit4fc82e0067db4b54ee05d56feaa4fb981d380e5f (patch)
tree9b43ce7590e327e87010f54708640b6ff9ee385b /examples/var_service/ntpd
parentc041e239dbc02b99ee9a5a86bed6dc859ff956db (diff)
downloadbusybox-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-xexamples/var_service/ntpd/log/run21
-rwxr-xr-xexamples/var_service/ntpd/ntp.script29
-rwxr-xr-xexamples/var_service/ntpd/p_log4
-rwxr-xr-xexamples/var_service/ntpd/run60
-rwxr-xr-xexamples/var_service/ntpd/w_log4
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
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 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/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
3exec 2>/dev/null
4echo "`tail -n 99 "$0.log"`" >"$0.log"
5
6exec >>"$0.log"
7exec 2>&1
8
9dt=`date '+%Y-%m-%d %H:%M:%S'`
10
11if 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
23fi
24
25echo "$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
3cd log/logdir || exit 1
4cat @* 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
5exec 2>&1
6exec </dev/null
7
8user=root
9pool="us.pool.ntp.org" # replace "us" with your country code
10
11service="${PWD##*/}"
12rundir="/var/run/service/$service"
13default_p_opt="-p 0.$pool -p 1.$pool -p 2.$pool -p 3.$pool"
14
15
16# Make sure rundir/ exists
17mkdir -p "$rundir" 2>/dev/null
18chown -R "$user:" "$rundir"
19chmod -R a=rX "$rundir"
20rm -rf rundir 2>/dev/null
21ln -s "$rundir" rundir
22
23
24echo "* Checking network"
25test -f /var/run/service/fw/up || exec sleep 7
26sleep 5 # to let it settle
27
28# Grab config from dhcp
29cfg=-1
30for f in rundir/*.ntpconf; do
31 test -f "$f" || continue
32 . "$f"
33done
34
35# Select peers
36p_opt=""
37cfg=0
38while test x"${ntpip[$cfg]}" != x""; do
39 p_opt="$p_opt -p ${ntpip[$cfg]}"
40 let cfg=cfg+1
41done
42test x"$p_opt" == x"" && p_opt="$default_p_opt"
43
44if test x"$p_opt" == x""; then
45 echo "* No NTP peers configured, stopping"
46 sv o .
47 exec sleep 1
48fi
49
50
51# Let others know that we are up
52date '+%Y-%m-%d %H:%M:%S %Z' >rundir/up
53
54# Go go go
55echo "* Starting ntpd[$$]"
56exec \
57env - PATH="$PATH" \
58softlimit \
59setuidgid "$user" \
60ntpd -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
3cd log/logdir || exit 1
4watch -n2 'w=`ttysize w`; h=`ttysize h`; tail -$((h-3)) current 2>&1 | cut -b0-$((w-2))'