Package Details: networkmanager-dispatcher-chrony 2.1-1

Git Clone URL: (read-only, click to copy)
Package Base: networkmanager-dispatcher-chrony
Description: Dispatcher Script for chrony
Upstream URL:
Keywords: chrony dispatcher networkmanager ntp script
Licenses: MIT
Submitter: Freso
Maintainer: Freso
Last Packager: Freso
Votes: 70
Popularity: 0.000430
First Submitted: 2011-11-01 22:21 (UTC)
Last Updated: 2015-07-12 13:43 (UTC)

Required by (0)

Sources (2)

Latest Comments

vinicentus commented on 2024-06-01 12:25 (UTC)

I made some modifications, namely excluding the lo interface, using a different connectivity check, and checking connectivity on any action. Hopefully this is useful to someone.

Full script


# Make sure we're always getting the standard response strings

CHRONY=$(which chronyc)

chrony_cmd() {
  echo "Chrony going $1."
  exec $CHRONY -a $1

nm_connected() {
  # Let networkmanager check if we are able to reach the internet
  [ "$(nmcli networking connectivity check)" = 'full' ]

case "$STATUS" in
    if [ "$INTERFACE" != "lo" ]; then
      # Check for full connectivity, take online if connected
      nm_connected && chrony_cmd online
    if [ "$INTERFACE" != "lo" ]; then
      # Check for full connectivity, take offline if not connected
      nm_connected || chrony_cmd offline

soylens commented on 2023-09-11 13:04 (UTC)

The current logic of the dispatcher script causes chrony to go online as soon as the loopback device goes up. It sort of contradicts the purpose of the script halting chrony when no connection is available. My suggestions: Either do the same connectedness check before going online as going offline, or blacklist devices like lo from the script. Beware that the result of nmcli g at the time where the dispatcher is running could be connected (site only) instead of connected. Also I would like to point to the possibility of using chronyc onoffline to let chrony decide whether to go on- or offline. However, I'm having trouble with a dispatcher script using onoffline, in that chrony remains offline after my WLAN connects automatically on startup. Using online instead, or connecting only after startup has finished, doesn't pose the problem.

pcmoore commented on 2019-06-14 02:27 (UTC)

I made some small changes to add NTP servers from DHCP and use chrony's built in network route detection to mark servers on/offline. If anyone is interested, I've put a copy up at the link below:

lotia commented on 2018-09-28 22:40 (UTC) (edited on 2018-09-28 22:46 (UTC) by lotia)

This script is errorring because it can't find 'which'. The error in the systemd journal is

/etc/NetworkManager/dispatcher.d/10-chrony: line 9: which: command not found

Instead it is possible to use 'command -v' to get the path of chronyc on line 9. has a patch that has been confirmed working.

sampurna commented on 2014-12-10 07:07 (UTC)

this script produces authentication errors for me: 501 Not authorised --- Reply not authenticated which I think it's because the generated password in /etc/chrony.keys was hashed with SHA1. 10-chrony could be enhanced to specify the "authhash" command before "password", but this seems simpler: --- 10-chrony~ 2014-12-08 00:09:03.000000000 -0500 +++ 10-chrony 2014-12-10 02:04:29.086331142 -0500 @@ -7,17 +7,13 @@ LANG='C' # Chrony set-up -CHRONY=/usr/bin/chronyc +CHRONY='/usr/bin/chronyc -a' CONFIG=/etc/chrony.conf -KEYFILE=`grep ^keyfile $CONFIG | sed 's/[^ ]* //' -` -COMMANDKEY=`grep ^commandkey $CONFIG | sed 's/[^ ]* //' -` -PASSWORD=`grep ^$COMMANDKEY $KEYFILE | sed 's/.*[^ ] //' -` STATECMD='nmcli -t --fields STATE g' chrony_cmd() { echo Chrony going $1. exec $CHRONY <<EOF -password $PASSWORD $1 EOF }

<deleted-account> commented on 2014-10-06 13:51 (UTC)

@Freso I sent you a PR with some fixes.

Freso commented on 2014-08-14 08:53 (UTC)

Implemented latest changes by Troy Engel. Thank you! Also, feel free to make pull requests proper against in the future. :)

tengel commented on 2014-08-11 22:53 (UTC)

The NetworkManager that is in the repository no longer ships the 'nm-tool' utility, so this script is also broken in that area. It can be replaced by "nmcli -t --fields STATE g" easily: STATECMD="nmcli -t --fields STATE g" [...] if [ ! `${STATECMD}` = 'connected' ]; then [...] This fix plus the PASSWORD one now results in a fully working dispatcher with the latest NM release.

tengel commented on 2014-08-11 21:30 (UTC)

This script doesn't work with the default configuration of chrony.conf and chrony.keys; they set the keyword 'generatecommandkey' which writes the key in MD5 format (other Googling shows SHA is also possible): 1 MD5 HEX:AABBCCDDEEFF This is documented here: The issue is the sed line for PASSWORD doesn't strip out the method, so tries to pass "MD5 HEX:..." over to chronyc. Here's a sed that works for both what's in the wiki ('1 xyzzy') and the autogenerated keys ('1 MD5 HEX:...'): -PASSWORD=`grep ^$COMMANDKEY $KEYFILE | sed 's/[^ ]* //' -` +PASSWORD=`grep ^$COMMANDKEY $KEYFILE | sed 's/.*[^ ] //' -` That will extract the other direction - find the last space and grab what follows it, rather than finding the first space etc. It also looks like we could just avoid this altogether and use "chronyc -a" to automatically do the needful.