author | Jiri Sasek <Jiri.Sasek@Oracle.COM> |
Wed, 06 Nov 2013 04:08:10 -0800 | |
changeset 1538 | 9babd0ede872 |
parent 432 | 4eda6f0a3346 |
child 4486 | 8a12763ec19a |
permissions | -rw-r--r-- |
172
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
1 |
#!/sbin/sh |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
2 |
# |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
3 |
# CDDL HEADER START |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
4 |
# |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
5 |
# The contents of this file are subject to the terms of the |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
6 |
# Common Development and Distribution License (the "License"). |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
7 |
# You may not use this file except in compliance with the License. |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
8 |
# |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
9 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
10 |
# or http://www.opensolaris.org/os/licensing. |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
11 |
# See the License for the specific language governing permissions |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
12 |
# and limitations under the License. |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
13 |
# |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
14 |
# When distributing Covered Code, include this CDDL HEADER in each |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
15 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
16 |
# If applicable, add the following below this CDDL HEADER, with the |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
17 |
# fields enclosed by brackets "[]" replaced with your own identifying |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
18 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
19 |
# |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
20 |
# CDDL HEADER END |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
21 |
# |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
22 |
|
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
23 |
# |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
24 |
# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
25 |
# |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
26 |
|
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
27 |
# Standard prolog |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
28 |
# |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
29 |
. /lib/svc/share/smf_include.sh |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
30 |
|
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
31 |
if [ -z $SMF_FMRI ]; then |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
32 |
echo "SMF framework variables are not initialized." |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
33 |
exit $SMF_EXIT_ERR |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
34 |
fi |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
35 |
|
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
36 |
# |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
37 |
# Is NTP configured? |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
38 |
# |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
39 |
if [ ! -f /etc/inet/ntp.conf ]; then |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
40 |
echo "Error: Configuration file '/etc/inet/ntp.conf' not found." \ |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
41 |
" See ntpd(1M)." |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
42 |
exit $SMF_EXIT_ERR_CONFIG |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
43 |
fi |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
44 |
|
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
45 |
# Disable globbing to prevent privilege escalations by users authorized |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
46 |
# to set property values for the NTP service. |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
47 |
set -f |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
48 |
|
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
49 |
# |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
50 |
# Build the command line flags |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
51 |
# |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
52 |
shift $# |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
53 |
set -- -p /var/run/ntp.pid |
432
4eda6f0a3346
6902531 ntp start method checks for global zone which should not be a requirement
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
172
diff
changeset
|
54 |
# We allow a step larger than the panic value of 17 minutes only |
172
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
55 |
# once when ntpd starts up. If always_all_large_step is true, |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
56 |
# then we allow this each time ntpd starts. Otherwise, we allow |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
57 |
# it only the very first time ntpd starts after a boot. We |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
58 |
# check that by making ntpd write its pid to a file in /var/run. |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
59 |
|
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
60 |
val=`svcprop -c -p config/always_allow_large_step $SMF_FMRI` |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
61 |
if [ "$val" = "true" ] || \ |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
62 |
[ ! -f /var/run/ntp.pid ]; then |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
63 |
set -- "$@" -g |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
64 |
fi |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
65 |
|
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
66 |
# Auth was off by default in xntpd now the default is on. Better have a way |
432
4eda6f0a3346
6902531 ntp start method checks for global zone which should not be a requirement
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
172
diff
changeset
|
67 |
# to turn it off again. Also check for the obsolete "authentication" keyword. |
172
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
68 |
val=`svcprop -c -p config/no_auth_required $SMF_FMRI` |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
69 |
if [ ! "$val" = "true" ]; then |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
70 |
val=`/usr/bin/nawk '/^[ \t]*#/{next} |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
71 |
/^[ \t]*authentication[ \t]+no/ { |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
72 |
printf("true", $2) |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
73 |
next } ' /etc/inet/ntp.conf` |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
74 |
fi |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
75 |
[ "$val" = "true" ] && set -- "$@" --authnoreq |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
76 |
|
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
77 |
# Set up logging if requested. |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
78 |
logfile=`svcprop -c -p config/logfile $SMF_FMRI` |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
79 |
val=`svcprop -c -p config/verbose_logging $SMF_FMRI` |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
80 |
[ "$val" = "true" ] && [ -n "$logfile" ] && set -- "$@" -l $logfile |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
81 |
|
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
82 |
# Register with mDNS. |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
83 |
val=`svcprop -c -p config/mdnsregister $SMF_FMRI` |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
84 |
mdns=`svcprop -c -p general/enabled svc:/network/dns/multicast:default` |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
85 |
[ "$val" = "true" ] && [ "$mdns" = "true" ] && set -- "$@" -m |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
86 |
|
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
87 |
# We used to support the slewalways keyword, but that was a Sun thing |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
88 |
# and not in V4. Look for "slewalways yes" and set the new slew option. |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
89 |
val=`svcprop -c -p config/slew_always $SMF_FMRI` |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
90 |
if [ ! "$val" = "true" ]; then |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
91 |
val=`/usr/bin/nawk '/^[ \t]*#/{next} |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
92 |
/^[ \t]*slewalways[ \t]+yes/ { |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
93 |
printf("true", $2) |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
94 |
next } ' /etc/inet/ntp.conf` |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
95 |
fi |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
96 |
[ "$val" = "true" ] && set -- "$@" --slew |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
97 |
|
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
98 |
# Set up debugging. |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
99 |
deb=`svcprop -c -p config/debuglevel $SMF_FMRI` |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
100 |
|
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
101 |
# Start the daemon. If debugging is requested, put it in the background, |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
102 |
# since it won't do it on it's own. |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
103 |
if [ "$deb" -gt 0 ]; then |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
104 |
/usr/lib/inet/ntpd "$@" --set-debug-level=$deb >/var/ntp/ntp.debug & |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
105 |
else |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
106 |
/usr/lib/inet/ntpd "$@" |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
107 |
fi |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
108 |
|
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
109 |
# Now, wait for the first sync, if requested. |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
110 |
val=`svcprop -c -p config/wait_for_sync $SMF_FMRI` |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
111 |
[ "$val" = "true" ] && /usr/lib/inet/ntp-wait |
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
112 |
|
093198acf7d4
7018272 Move NTP to userland
Brian Utterback <Brian.Utterback@Oracle.COM>
parents:
diff
changeset
|
113 |
exit $SMF_EXIT_OK |