#!/bin/bash . `dirname $0`/functions option config standard_option /etc/ntp/ntp.conf option keys standard_option /etc/ntp/ntp.keys option pidfile reserved_option /var/run/ntp.pid option hard_sync boolean_option # not used anymore option min_servers standard_option 1 option force_sync boolean_option option unpriv_port boolean_option 1 option sync_servers long_option option procname reserved_option ntpd option bin reserved_option /usr/sbin/ntpd option cmdline reserved_option '$bin -c $opt_config -p $pidfile -k $opt_keys' function do_help { echo "Usage: ${0##*/} " echo "List of config.rc options (name, type, default value, current value) :" echo echo " - config : file ; def='/etc/ntp/ntp.conf' ; cur=$opt_config" echo " - keys : file ; def='/etc/ntp/ntp.keys' ; cur=$opt_keys" echo " - min_servers : integer ; def=1 ; cur=$opt_min_servers" echo " - force_sync : boolean ; def=0 ; cur=$opt_force_sync" echo " - unpriv_port : boolean ; def=1 ; cur=$opt_unpriv_port" echo " - sync_servers : IP list ; def= ; cur='${opt_sync_servers[@]}'" echo exit 1 } # assign values after all the options have been read function fct_end_section { if [ -z "$opt_sync_servers" ]; then valueof $opt_config server > /dev/null opt_sync_servers=( $REPLY ) opt_sync_servers=( ${opt_sync_servers[@]##127.*} ) fi } # perform a forced synchronisation before starting the daemon function fct_pre_start { local driftfile local synced=0 valueof $opt_config driftfile > /dev/null 2>&1 ; driftfile=$REPLY if [ -n "$driftfile" -a ! -e "${driftfile%/*}" ] ; then mkdir -p ${driftfile%/*} fi if [ "$opt_force_sync" = "1" ]; then if [ -x /usr/bin/ntptimeset ]; then echo " Using ntptimeset to sync with servers..." if /usr/bin/ntptimeset -l -s -c $opt_config -S $opt_min_servers \ -V $opt_min_servers -t 5 ${opt_unpriv_port:+-u}; then synced=1 else echo " --> sync failed." fi fi if [ $synced -eq 0 ]; then if [ -z "$opt_sync_servers" ]; then echo " --> sync_servers not set, and ntptimeset not installed. Not forcing sync." else echo " Using ntpdate to sync with server(s) ${opt_sync_servers[*]}..." if /usr/bin/ntpdate ${opt_unpriv_port:+-u} -t 2 ${opt_sync_servers[*]}; then synced=1 else echo " --> sync failed, starting unsynced." fi fi fi fi return 0 } # execute a forced resynchronisation to sync servers function do_update { local synced=0 if [ -x /usr/bin/ntptimeset ]; then echo " Using ntptimeset to sync with servers..." if /usr/bin/ntptimeset -l -s -c $opt_config -S $opt_min_servers \ -V $opt_min_servers -t 5 ${opt_unpriv_port:+-u}; then synced=1 else echo " --> sync failed." fi fi if [ $synced -eq 0 ]; then if [ -z "$opt_sync_servers" ]; then echo " --> sync_servers not set, and ntptimeset not installed. Aborting." else echo " Using ntpdate to sync with server(s) ${opt_sync_servers[*]}..." if /usr/bin/ntpdate ${opt_unpriv_port:+-u} -t 2 ${opt_sync_servers[*]}; then synced=1 else echo " --> sync failed. Aborting." fi fi fi test $synced -eq 1 return $? } function do_query { ntpq -p 127.0.0.1 } load_config