summaryrefslogblamecommitdiffstats
path: root/source/n/ntp/rc.ntpd
blob: 9d1e3e88f13f6ddbb0b58e2b5136e4e14badaa1f (plain) (tree)
1
2
3
4
5
6
7




                          

                                                              





                                  


                                  


                        
      










                          

                                                       

                           
          


















                                           
#!/bin/sh
# Start/stop/restart ntpd.

# Start ntpd:
ntpd_start() {
  echo -n "Starting NTP daemon:  /usr/sbin/ntpd -g -u ntp:ntp"
  /usr/sbin/ntpd -g -u ntp:ntp
  echo
}

# Stop ntpd:
ntpd_stop() {
  echo -n "Stopping NTP daemon..."
  if [ -r /run/ntpd.pid ]; then
    kill -HUP $(cat /run/ntpd.pid)
    rm -f /run/ntpd.pid
  else
    killall -HUP -q ntpd
  fi
  echo
}

# Restart ntpd:
ntpd_restart() {
  ntpd_stop
  sleep 1
  ntpd_start
}

# Check if ntpd is running
ntpd_status() {
  if [ -e /run/ntpd.pid ]; then
    echo "ntpd is running as pid $(cat /run/ntpd.pid)."
  else 
    echo "ntpd is stopped."
    exit 1
  fi
}

case "$1" in
'start')
  ntpd_start
  ;;
'stop')
  ntpd_stop
  ;;
'restart')
  ntpd_restart
  ;;
'status')
  ntpd_status
  ;;
*)
  echo "usage $0 start|stop|restart|status"
esac