You are not logged in.

#1 2009-06-03 21:59:01

alienman
Member
From: Mexico
Registered: 2008-07-08
Posts: 106

OpenNtp and NetworkManager

Hi guys. I don't know how many of you guys use NetworkManager and OpenNtp for time synchronization, but I do (Yes I know must archers use netcfg profiles but anyway I like NetworkManager).

I notice that just adding openntpd to the daemons array didn't work and I was looking for a solution to this problem. One option was to set a cron job to do the job, but I remember I read that some servers kicks you if you're doing many requests.

I found a script very useful to use with my NetworkManager (I ignored NetworkManager had a place to put scripts). So I decided to post the script here and maybe someone could find it useful or even some people could help us to improve if something is wrong. BTW it is working really well for me.

You have to put the script under /etc/NetworkManager/dispatcher.d/

I named the script as 40-OpenNtp because I read that the scripts are launched alphabetically so I decided to use numbers at the beggining.

#!/bin/bash

if [ -x /usr/bin/logger ]; then
        LOGGER="/usr/bin/logger -s -p user.notice -t NetworkManagerDispatcher"
else
        LOGGER=echo
fi

if [ ! -x /etc/rc.d/openntpd ]; then
  $LOGGER "init script /etc/rc.d/openntpd missing or not executible"
  return
fi
  
if [ -n $1 ] && [ $2 == "up" ]; then

  if [ -f /var/run/openntpd.pid ]; then
    $LOGGER "openntpd is running, restart"
    /etc/rc.d/openntpd restart
  else
    $LOGGER "ntpd is not running, start"
    /etc/rc.d/openntpd start
  fi

fi

if [ -n $1 ] && [ $2 == "down" ] && [ -f /var/run/openntpd.pid ]; then
  $LOGGER "openntpd is running, stop"
  /etc/rc.d/openntpd stop
fi

After that you have to make the script executable

chmod +x /etc/NetworkManager/dispatcher.d/40-OpenNtp

As recommendation, the wiki of NetworkManager says that it is recommended that scripts are owned by root:root so have this into consideration.

Well hope it helps someone.


ISC - Ignacio Marmolejo
ArchLinux & GNOME User.

Offline

Board footer

Powered by FluxBB