diff options
author | Denys Vlasenko | 2010-01-13 22:07:34 +0100 |
---|---|---|
committer | Denys Vlasenko | 2010-01-13 22:07:34 +0100 |
commit | 4fc82e0067db4b54ee05d56feaa4fb981d380e5f (patch) | |
tree | 9b43ce7590e327e87010f54708640b6ff9ee385b /examples/var_service/ntpd/run | |
parent | c041e239dbc02b99ee9a5a86bed6dc859ff956db (diff) | |
download | busybox-4fc82e0067db4b54ee05d56feaa4fb981d380e5f.zip busybox-4fc82e0067db4b54ee05d56feaa4fb981d380e5f.tar.gz |
examples: add example ntpd service
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'examples/var_service/ntpd/run')
-rwxr-xr-x | examples/var_service/ntpd/run | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/examples/var_service/ntpd/run b/examples/var_service/ntpd/run new file mode 100755 index 0000000..581d231 --- /dev/null +++ b/examples/var_service/ntpd/run @@ -0,0 +1,60 @@ +#!/bin/bash +# (using bashism (arrays) in dhcp config) + +#exec >/dev/null +exec 2>&1 +exec </dev/null + +user=root +pool="us.pool.ntp.org" # replace "us" with your country code + +service="${PWD##*/}" +rundir="/var/run/service/$service" +default_p_opt="-p 0.$pool -p 1.$pool -p 2.$pool -p 3.$pool" + + +# Make sure rundir/ exists +mkdir -p "$rundir" 2>/dev/null +chown -R "$user:" "$rundir" +chmod -R a=rX "$rundir" +rm -rf rundir 2>/dev/null +ln -s "$rundir" rundir + + +echo "* Checking network" +test -f /var/run/service/fw/up || exec sleep 7 +sleep 5 # to let it settle + +# Grab config from dhcp +cfg=-1 +for f in rundir/*.ntpconf; do + test -f "$f" || continue + . "$f" +done + +# Select peers +p_opt="" +cfg=0 +while test x"${ntpip[$cfg]}" != x""; do + p_opt="$p_opt -p ${ntpip[$cfg]}" + let cfg=cfg+1 +done +test x"$p_opt" == x"" && p_opt="$default_p_opt" + +if test x"$p_opt" == x""; then + echo "* No NTP peers configured, stopping" + sv o . + exec sleep 1 +fi + + +# Let others know that we are up +date '+%Y-%m-%d %H:%M:%S %Z' >rundir/up + +# Go go go +echo "* Starting ntpd[$$]" +exec \ +env - PATH="$PATH" \ +softlimit \ +setuidgid "$user" \ +ntpd -ddnNl -S ./ntp.script $p_opt |