summaryrefslogtreecommitdiff
path: root/examples/var_service/ntpd/run (plain)
blob: 6f2a681883ad081ae889ad97d3a0224e9b425dd7
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
61