diff options
author | Bjoern Buerger <b.buerger@pengutronix.de> | 2007-03-13 16:49:19 +0000 |
---|---|---|
committer | Bjoern Buerger <b.buerger@pengutronix.de> | 2007-03-13 16:49:19 +0000 |
commit | c411ae70feff21b67015dee7e1507fe61fb02a58 (patch) | |
tree | e60b7b0647d0cce4f2e25966491f17ad56243eed /generic | |
parent | 3fd560f93b3973b85a26bd68293d65c96803f9fe (diff) | |
download | ptxdist-c411ae70feff21b67015dee7e1507fe61fb02a58.tar.gz ptxdist-c411ae70feff21b67015dee7e1507fe61fb02a58.tar.xz |
* added chrony default config, tools, menu entries
git-svn-id: https://svn.pengutronix.de/svn/ptxdist/trunks/ptxdist-trunk@7060 33e552b5-05e3-0310-8538-816dae2090ed
Diffstat (limited to 'generic')
-rw-r--r-- | generic/etc/chrony/chrony.conf | 97 | ||||
-rw-r--r-- | generic/etc/chrony/chrony.keys | 4 | ||||
-rwxr-xr-x | generic/etc/init.d/chrony | 167 | ||||
-rwxr-xr-x | generic/usr/bin/chrony_command | 27 |
4 files changed, 295 insertions, 0 deletions
diff --git a/generic/etc/chrony/chrony.conf b/generic/etc/chrony/chrony.conf new file mode 100644 index 000000000..f2d594978 --- /dev/null +++ b/generic/etc/chrony/chrony.conf @@ -0,0 +1,97 @@ +# ---------------------------------------------------------------------- +# chrony client configuration for Comsoft AG NTP Client +# ---------------------------------------------------------------------- +# Author: Bjørn Bürger <b.buerger@pengutronix.de> +# Last Change: Tue Mar 6 15:12:41 UTC 2007 +# +# Hints: +# ---------------------------------------------------------------------- +# a comment +! a comment +# ---------------------------------------------------------------------- +# Specify your own NTP Servers: + +server @UNCONFIGURED_CHRONY_SERVER_IP@ auto_offline minpoll 5 maxpoll 10 + +# other servers may be referenced here, but they will only be requested, +# if set online by /etc/init.d/chrony online +! server 0.pool.ntp.org offline minpoll 8 +! server 1.pool.ntp.org offline minpoll 8 +! server 2.pool.ntp.org offline minpoll 8 + +# To avoid changes being made to your computer's gain/loss compensation +# when the measurement history is too erratic, you might want to enable +# one of the following lines. The first seems good for dial-up (or +# other high-latency connections like slow leased lines), the second +# seems OK for a LAN environment. +! maxupdateskew 100 +! maxupdateskew 5 +maxupdateskew 20 + +# rtc +rtcdevice /dev/rtc +rtcfile /var/run/chrony.rtc +rtconutc + +# driftfile +driftfile /var/run/chrony.drift + +# pidfile +pidfile /var/run/chronyd.pid + +# keyfile for chronyc +keyfile /etc/chrony/chrony.keys +commandkey 1 + +# chronyd can save the measurement history for the servers to files when +# it it exits. However, this will affect the lifetime of you flash +# medium, if this is not used on a ramdisk. Be careful. +dumponexit +dumpdir /var/run/chrony + +# INITIAL CLOCK CORRECTION +# This option is only useful if your NTP servers are visible at +# start-time of chrony. The value '10' means that if the error is less +# than 10 seconds, it will be gradually removed by speeding up or +# slowing down your computer's clock until it is correct. If the error +# is above 10 seconds, an immediate time jump will be applied to correct +# it. +# +# Get Time from your configured NTP Server +# +initstepslew 10 @UNCONFIGURED_CHRONY_SERVER_IP@ + +# Logging +# Comment this line out to turn off logging. +! log measurements statistics tracking rtc +logdir /var/run/chrony + +# Access Rules +! allow 10.0.0.0/8 +! allow 192.168.0.0/16 + +# Send Broadcast every 60 Seconds +! broadcast 60 10.255.255.255 + +# Let computer be a server when it is unsynchronised. +# set local straum below 15, even if unsynced +# this will circumwent long delays when starting clients +local stratum 10 + +# we dont need an accesslog. +noclientlog + +# The next option causes a message to be written to syslog when chronyd +# has to correct an error above 0.5 seconds (you can use any amount you +# like). +! logchange 0.5 + +# This directive defines an email address to which mail should be sent +# if chronyd applies a correction exceeding a particular threshold to the +# system clock. +! mailonchange root@localhost 0.5 + +# Allow command access +! cmdallow 10/8 +! cmdallow 192.168/16 +cmdallow 127.0.0.1 diff --git a/generic/etc/chrony/chrony.keys b/generic/etc/chrony/chrony.keys new file mode 100644 index 000000000..25e507188 --- /dev/null +++ b/generic/etc/chrony/chrony.keys @@ -0,0 +1,4 @@ +# Key File for chronyc +# this is needed, to access chronyd from chronyc client +# +1 @UNCONFIGURED_CHRONY_ACCESS_KEY@ diff --git a/generic/etc/init.d/chrony b/generic/etc/init.d/chrony new file mode 100755 index 000000000..e7e937ae3 --- /dev/null +++ b/generic/etc/init.d/chrony @@ -0,0 +1,167 @@ +#!/bin/sh +# +# This is a chrony init.d script which ist called by init(1) +# with [start|stop] as argument. This version does not +# need an additional start-stop daemon. +# +# Last change: Bjørn Bürger <b.buerger@pengutronix.de> +# Date: Tue Mar 6 16:00:30 UTC 2007 + +PATH=/sbin:/bin:/usr/bin:/usr/sbin +BINARY="/usr/sbin/chronyd" +CONFIG="/etc/chrony/chrony.conf" +PREFIX="chrony: " +# This system doesn´t have full rtc ioctl support for +# chrony statistic functions +RTC_IOCTL="incomplete" + +# some chronyc commands need prior autentication: extract keys from config +KEY=$(awk '$1 ~ /^commandkey$/ { print $2; exit}' /etc/chrony/chrony.conf) +PASSWORD=`awk '$1 ~ /^'$KEY'$/ {print $2; exit}' /etc/chrony/chrony.keys` + +# convenience functions +message(){ + echo "${PREFIX}$*" >&2 +} + +message_n(){ + echo -n "${PREFIX}$*" >&2 +} + +bailout(){ + echo "${PREFIX}ERROR --- $*" >&2 + exit 1 +} + +usage(){ + echo "Usage: $0 {start|stop|restart|force-reload|online|offline|set-rtc|status|statistics}" +} + +killproc() { + killall $1 +} + +# main functions +start_proc() { + message_n "Reading system time from RealTimeClock ..." + /sbin/hwclock --hctosys || message_n " ### FAILED ### " + message "DONE" + message_n "Starting NTP server: chronyd ..." + [ -e "$CONFIG" ] || bailout "Configfile $CONFIG not found, PANIC!" + $BINARY -f $CONFIG + message "DONE" +} + +stop_proc() { + message_n "Stopping NTP server: chronyd ..." + killproc chronyd + message "DONE" + message_n "Writing system time to RealTimeClock ..." + /sbin/hwclock --systohc || message_n " ### FAILED ### " + message "DONE" +} + +set_online(){ + message_n "Setting NTP server ONLINE ... " + /bin/pidof chronyd > /dev/null || bailout " chronyd is not running " + /usr/bin/chronyc <<-EOF + password $PASSWORD + online + burst 5/10 + quit + EOF + message "DONE" + exit 0 +} + +set_offline(){ + message_n "Setting NTP server OFFLINE ... " + /bin/pidof chronyd > /dev/null || bailout " chronyd is not running " + /usr/bin/chronyc <<-EOF + password $PASSWORD + offline + EOF + message "DONE" + exit 0 +} + +set_rtc(){ + /bin/pidof chronyd > /dev/null || bailout " chronyd is not running " + if [ "$RTC_IOCTL" == "incomplete" ] ; then + # We are running on a system with limited rtc support, + # so we cannot let the ntp client do the job. + stop_proc + sleep 1 + start_proc + exit 0 + else + # This requires enhanced rtc support + message_n "Setting NTP time to RTC ... " + cat <<-EOF | /usr/bin/chronyc + password $PASSWORD + trimrtc + writertc + dump + EOF + message "DONE" + exit 0 + fi +} + +status(){ + /bin/pidof chronyd > /dev/null || bailout " chronyd is not running " + cat <<-EOF | /usr/bin/chronyc + password $PASSWORD + tracking + sources + EOF +} + +statistics(){ + /bin/pidof chronyd > /dev/null || bailout " chronyd is not running " + cat <<-EOF | /usr/bin/chronyc + password $PASSWORD + sourcestats + EOF +} + +case "$1" in + start) + start_proc + ;; + stop) + stop_proc + ;; + restart|force-reload) + message "Restarting NTP server: chronyd ... " + stop_proc + sleep 1 + start_proc + ;; + reload) + message "Reload is not supported" + exit 1 + ;; + online) + set_online + ;; + offline) + set_offline + ;; + set-rtc) + set_rtc + ;; + status) + status + ;; + statistics) + statistics + ;; + *) + usage + exit 1 + ;; +esac + +exit 0 + diff --git a/generic/usr/bin/chrony_command b/generic/usr/bin/chrony_command new file mode 100755 index 000000000..ed492935f --- /dev/null +++ b/generic/usr/bin/chrony_command @@ -0,0 +1,27 @@ +#!/bin/sh +# This is a generic chrony command script which +# extracts the chrony access key from /etc/chrony/chrony.key +# and executes one given command +# some chronyc commands need prior autentication: extract keys from config +PREFIX="chrony command helper: " +command=$1 +if [ -n "$command" ] ; then + echo "Usage: $0 <command>" + exit 0 +fi +[ "$command" -eq "--help" ] && command="help" + +bailout(){ + echo "${PREFIX}ERROR --- $*" >&2 + exit 1 +} + +KEY=$(awk '$1 ~ /^commandkey$/ { print $2; exit}' /etc/chrony/chrony.conf) +PASSWORD=`awk '$1 ~ /^'$KEY'$/ {print $2; exit}' /etc/chrony/chrony.keys` + +/bin/pidof chronyd > /dev/null || bailout " chronyd is not running " +/usr/bin/chronyc <<-EOF +password $PASSWORD +$command +EOF + |