xref: /freebsd/libexec/rc/rc.d/ntpdate (revision 61b07f8aa52844b21637ac264ea134c1aef48cb7)
1#!/bin/sh
2#
3#
4
5# PROVIDE: ntpdate
6# REQUIRE: NETWORKING syslogd
7# KEYWORD: nojail
8
9. /etc/rc.subr
10
11name="ntpdate"
12desc="Set the date and time via NTP"
13rcvar="ntpdate_enable"
14stop_cmd=":"
15start_cmd="ntpdate_start"
16
17ntpdate_start()
18{
19	if [ -z "$ntpdate_hosts" -a -f "$ntpdate_config" ]; then
20		ntpdate_hosts=`awk '
21			/^server[ \t]*127.127/      {next}
22			/^(server|peer|pool)/       {
23			    if ($2 ~/^-/)           {print $3}
24			    else                    {print $2}}
25		' < "$ntpdate_config"`
26	fi
27	if [ -n "$ntpdate_hosts" -o -n "$rc_flags" ]; then
28		echo "Setting date via ntp."
29		${ntpdate_program:-ntpdate} $rc_flags $ntpdate_hosts
30	fi
31}
32
33load_rc_config $name
34
35# doesn't make sense to run in a svcj: privileged operations
36ntpdate_svcj="NO"
37
38run_rc_command "$1"
39