diff options
-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 | ||||
-rw-r--r-- | rules/chrony.in | 101 | ||||
-rw-r--r-- | rules/chrony.make | 86 | ||||
-rw-r--r-- | rules/rootfs_rc_d_links.in | 10 |
7 files changed, 486 insertions, 6 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 + diff --git a/rules/chrony.in b/rules/chrony.in index da6528586..09e28998d 100644 --- a/rules/chrony.in +++ b/rules/chrony.in @@ -1,7 +1,8 @@ -config CHRONY - bool +# chrony configuration + +menuconfig CHRONY + bool "Chrony " select READLINE - prompt "Chrony " help FIXME: remove READLINE select when 1.21 works again. @@ -16,3 +17,97 @@ config CHRONY various settings. See http://chrony.sunsite.dk/ for details + +comment "install options ---" + depends on CHRONY + +config CHRONY_INSTALL_CHRONY_COMMAND + depends on CHRONY + bool + default n + prompt "Install chrony command helper" + help + Install a command helper in /usr/bin/chrony_command, + which extracts the command access key from + /etc/chrony/chrony.keys and uses it to run + one given command. Note: The user needs access to + the chrony.keys file. + +menuconfig CHRONY_INSTALL_CONFIG + depends on CHRONY + bool + default y + prompt "Install chrony config files" + help + Install /etc/chrony/chrony.conf and /etc/chrony/chony.keys + from a selectable source. + + choice + prompt "Kind of chrony config" + depends on CHRONY_INSTALL_CONFIG + default CHRONY_DEFAULTCONFIG + + config CHRONY_DEFAULTCONFIG + bool + prompt "Use generic" + help + Install generic chrony config files. + See <ptxdist-install>/generic/etc/chrony/ + + config CHRONY_USERCONFIG + bool + prompt "User defined" + help + This uses a user defined chrony config. + PTXdist uses files projectroot/chrony/ + in your local project + endchoice + +config CHRONY_DEFAULT_ACCESS_KEY + depends on CHRONY + string + prompt "setup default access key for chronyc" + default "undefined" + help + This will install a default access key with the + given content to the chrony.keys file. This is + used by /etc/init.d/chrony to access status + data, etc. + +config CHRONY_DEFAULT_NTP_SERVER + depends on CHRONY + string + prompt "setup default ntp peer" + default "10.1.1.2" + help + This will set the ntp server for simple + configurations. + +menuconfig ROOTFS_ETC_INITD_CHRONY + depends on CHRONY + bool + default y + prompt "Install startup script" + help + The /etc/init.d/chrony script lets you control the chronyd daemon. + + choice + prompt "Kind of startup script" + depends on ROOTFS_ETC_INITD_CHRONY + default ROOTFS_ETC_INITD_CHRONY_DEFAULT + + config ROOTFS_ETC_INITD_CHRONY_DEFAULT + bool + prompt "Use generic" + help + Install a generic /etc/init.d/chrony file. + See <ptxdist-install>/generic/etc/init.d/chrony + + config ROOTFS_ETC_INITD_CHRONY_USER + bool + prompt "User defined" + help + This uses a user defined httpd startup script. PTXdist + uses file projectroot/etc/init.d/chrony in your local + project + endchoice diff --git a/rules/chrony.make b/rules/chrony.make index 695d98bbd..a6818d5bf 100644 --- a/rules/chrony.make +++ b/rules/chrony.make @@ -111,12 +111,92 @@ $(STATEDIR)/chrony.targetinstall: $(chrony_targetinstall_deps_default) @$(call install_fixup, chrony,PRIORITY,optional) @$(call install_fixup, chrony,VERSION,$(CHRONY_VERSION)) @$(call install_fixup, chrony,SECTION,base) - @$(call install_fixup, chrony,AUTHOR,"Robert Schwebel <r.schwebel\@pengutronix.de>") + @$(call install_fixup, chrony,AUTHOR,"PTXdist Base Package <ptxdist\@pengutronix.de>") @$(call install_fixup, chrony,DEPENDS,) @$(call install_fixup, chrony,DESCRIPTION,missing) - @$(call install_copy, chrony, 0, 0, 0755, $(CHRONY_DIR)/chronyd, /usr/sbin/chronyd) - @$(call install_copy, chrony, 0, 0, 0755, $(CHRONY_DIR)/chronyc, /usr/bin/chronyc) +# --------------------------- +# install chrony binaries +# + @$(call install_copy, chrony, 0, 0, 0755, \ + $(CHRONY_DIR)/chronyd, \ + /usr/sbin/chronyd) + @$(call install_copy, chrony, 0, 0, 0755, \ + $(CHRONY_DIR)/chronyc, \ + /usr/bin/chronyc) + +# --------------------------- +# install chrony command helper script on demand +# +ifdef PTXCONF_CHRONY_INSTALL_CHRONY_COMMAND + @$(call install_copy, chrony, 0, 0, 0755, \ + $(PTXDIST_TOPDIR)/generic/usr/bin/chrony_command, \ + /usr/bin/chrony_command, n) +endif + +# --------------------------- +# generate a config file +# +ifdef PTXCONF_CHRONY_INSTALL_CONFIG +ifdef PTXCONF_CHRONY_DEFAULTCONFIG +# use generic one + @$(call install_copy, chrony, 0, 0, 0644, \ + $(PTXDIST_TOPDIR)/generic/etc/chrony/chrony.conf, \ + /etc/chrony/chrony.conf, n) + @$(call install_copy, chrony, 0, 0, 0600, \ + $(PTXDIST_TOPDIR)/generic/etc/chrony/chrony.keys, \ + /etc/chrony/chrony.keys, n) +endif +ifdef PTXCONF_CHRONY_USERCONFIG +# users one + @$(call install_copy, chrony, 0, 0, 0644, \ + $(PTXDIST_WORKSPACE)/projectroot/etc/chrony/chrony.conf, \ + /etc/chrony/chrony.conf, n) + @$(call install_copy, chrony, 0, 0, 0600, \ + $(PTXDIST_WORKSPACE)/projectroot/etc/chrony/chrony.keys, \ + /etc/chrony/chrony.keys, n) +endif +# modify placeholders with data from configuration + @$(call install_replace, chrony, /etc/chrony/chrony.conf, \ + @UNCONFIGURED_CHRONY_SERVER_IP@, $(PTXCONF_CHRONY_DEFAULT_NTP_SERVER) ) + + @$(call install_replace, chrony, /etc/chrony/chrony.keys, \ + @UNCONFIGURED_CHRONY_ACCESS_KEY@, $(PTXCONF_CHRONY_DEFAULT_ACCESS_KEY) ) +endif + +# --------------------------- +# install startup script on demand +# +ifdef PTXCONF_ROOTFS_ETC_INITD_CHRONY +ifdef PTXCONF_ROOTFS_ETC_INITD_CHRONY_DEFAULT +# generic script with path modifications + @$(call install_copy, chrony, 0, 0, 0755, \ + $(PTXDIST_TOPDIR)/generic/etc/init.d/chrony, \ + /etc/init.d/chrony, n) +endif +ifdef PTXCONF_ROOTFS_ETC_INITD_CHRONY_USER +# users one + @$(call install_copy, chrony, 0, 0, 0755, \ + $(PTXDIST_WORKSPACE)/projectroot/etc/init.d/chrony, \ + /etc/init.d/chrony, n) +endif +# install link to launch automatically if enabled +ifneq ($(PTXCONF_ROOTFS_ETC_INITD_CHRONY_LINK),"") + @$(call install_link, chrony, \ + ../init.d/chrony, \ + /etc/rc.d/$(PTXCONF_ROOTFS_ETC_INITD_CHRONY_LINK)) +endif +endif + +# --------------------------- +# install chrony command helper script +# +ifdef PTXCONF_CHRONY_INSTALL_CHRONY_COMMAND + @$(call install_copy, chrony, 0, 0, 0755, \ + $(PTXDIST_TOPDIR)/generic/usr/bin/chrony_command, \ + /usr/bin/chrony_command, n) +endif + @$(call install_finish, chrony) diff --git a/rules/rootfs_rc_d_links.in b/rules/rootfs_rc_d_links.in index 69a40dc55..ce31f1885 100644 --- a/rules/rootfs_rc_d_links.in +++ b/rules/rootfs_rc_d_links.in @@ -42,6 +42,16 @@ config ROOTFS_ETC_INITD_BANNER_LINK /etc/init.d/banner. Keep this entry empty if you do not want to start this service automatically. +config ROOTFS_ETC_INITD_CHRONY_LINK + depends on ROOTFS_ETC_INITD_CHRONY_DEFAULT || ROOTFS_ETC_INITD_CHRONY_USER + string + prompt "chrony link name" + default "S03_chrony" + help + Set a link into /etc/rc.d which points to /etc/init.d/chrony to + start chronyd ntp client/server when system starts. Keep this + entry empty if you do not want to start this service automatically. + config ROOTFS_ETC_INITD_NFS_LINK depends on ROOTFS_ETC_INITD_NFS_DEFAULT || ROOTFS_ETC_INITD_NFS_USER string |