97 lines
2.5 KiB
Bash
97 lines
2.5 KiB
Bash
#!/bin/bash
|
|
#
|
|
# ntpd -- startup script for the Network Time Protocol (NTP) daemon
|
|
#
|
|
# description: this script takes care of starting and stopping \
|
|
# the NTPv4 daemon needed to set the system date and time \
|
|
# using an external source (the ntp server)
|
|
#
|
|
# chkconfig: 2345 55 10
|
|
#
|
|
# processname: nptd
|
|
# config: /etc/ntp.conf, /etc/ntp/*
|
|
# lockfile: /var/lock/subsys/ntpd
|
|
|
|
# Copyright (c) by Silvan Calarco <silvan.calarco@mambasoft.it>
|
|
# Copyright (c) by Davide Madrisan <davide.madrisan@gmail.com>
|
|
|
|
. /etc/sysconfig/rc
|
|
|
|
# Source function library.
|
|
[ -r "$rc_functions" ] && . $rc_functions
|
|
|
|
NAME=ntpd
|
|
DAEMON=/usr/sbin/$NAME
|
|
DAEMONPID=/var/run/$NAME.pid
|
|
DAEMONCONF=/etc/ntp.conf
|
|
OPTIONS="-c $DAEMONCONF -p $DAEMONPID -g"
|
|
|
|
[ -x $DAEMON ] || exit 0
|
|
|
|
# Source networking configuration.
|
|
[ -r /etc/sysconfig/network ] && . /etc/sysconfig/network
|
|
|
|
# Check that networking is up.
|
|
[ "$NETWORKING" = "yes" ] || exit 0
|
|
|
|
[ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
|
|
|
|
# check if the squid conf file is present
|
|
[ -r $DAEMONCONF ] || exit 0
|
|
|
|
# source clock configuration
|
|
[ -r /etc/sysconfig/clock ] && . /etc/sysconfig/clock
|
|
|
|
# see how we were called
|
|
case "$1" in
|
|
start)
|
|
# adjust time to make life easy for ntpd
|
|
if [ -r /etc/ntp/step-tickers ]; then
|
|
echo -n $"Syncing time for $NAME: "
|
|
/usr/sbin/ntpdate -sbup8 `cat /etc/ntp/step-tickers`
|
|
RETVAL=$?
|
|
evaluate_retval
|
|
echo
|
|
if [ $RETVAL = 0 ]; then
|
|
if [ $UTC = "1" ]; then
|
|
echo -n $"Syncing hardware clock to UTC: "
|
|
hwclock --set --date="`date --utc --rfc-822`" --utc
|
|
else
|
|
echo -n $"Syncing hardware clock to local time: "
|
|
hwclock --set --date="`date --utc --rfc-822`" --localtime
|
|
fi
|
|
evaluate_retval
|
|
echo
|
|
fi
|
|
fi
|
|
# start daemon
|
|
echo -n $"Starting $NAME: "
|
|
daemon --pidfile=$DAEMONPID $DAEMON $OPTIONS
|
|
RETVAL=$?
|
|
echo
|
|
[ $RETVAL = 0 ] && touch /var/lock/subsys/$NAME
|
|
;;
|
|
stop)
|
|
echo -n $"Stopping $NAME: "
|
|
killproc -p $DAEMONPID $DAEMON
|
|
RETVAL=$?
|
|
echo
|
|
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/$NAME $DAEMONPID
|
|
;;
|
|
status)
|
|
statusproc ntpd
|
|
;;
|
|
restart|reload)
|
|
$0 stop
|
|
sleep 1
|
|
$0 start
|
|
;;
|
|
condrestart)
|
|
[ -e /var/lock/subsys/$NAME ] && $0 restart || :
|
|
;;
|
|
*)
|
|
echo "Usage: /etc/init.d/$NAME {start|stop|restart|condrestart|status}"
|
|
exit 1
|
|
;;
|
|
esac
|