123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- #!/bin/sh
- ### BEGIN INIT INFO
- # Provides: ntp
- # Required-Start: $network networking
- # Required-Stop:
- # Default-Start: 2 3 4 5
- # Default-Stop:
- # Short-Description: Start NTP daemon
- ### END INIT INFO
- PATH=/sbin:/bin:/usr/sbin:/usr/bin
- . /lib/lsb/init-functions
- PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
- DESC="network time protocol daemon"
- NTPDATE_BIN=/usr/sbin/ntpdate
- DAEMON=/usr/sbin/ntpd
- PIDFILE=/var/run/ntpd.pid
- test -x $DAEMON || exit 5
- if [ -r /etc/default/ntp ]; then
- . /etc/default/ntp
- fi
- if [ -e /var/lib/ntp/ntp.conf.dhcp ]; then
- NTPD_OPTS="$NTPD_OPTS -c /var/lib/ntp/ntp.conf.dhcp"
- fi
- LOCKFILE=/var/lock/ntpdate
- lock_ntpdate() {
- if [ -x /usr/bin/lockfile-create ]; then
- lockfile-create $LOCKFILE
- lockfile-touch $LOCKFILE &
- LOCKTOUCHPID="$!"
- fi
- }
- unlock_ntpdate() {
- if [ -x /usr/bin/lockfile-create ] ; then
- kill $LOCKTOUCHPID
- lockfile-remove $LOCKFILE
- fi
- }
- RUNASUSER=ntp
- UGID=$(getent passwd $RUNASUSER | cut -f 3,4 -d:) || true
- if test "$(uname -s)" = "Linux"; then
- NTPD_OPTS="$NTPD_OPTS -u $UGID"
- fi
- case $1 in
- start)
-
- #add
- cat /etc/asterisk/ntp.conf | tail -n 4 | tr -d " " > /tmp/ntp.conf.val
- . /tmp/ntp.conf.val
- sed -i "/export TZ/d" /etc/profile
- echo 'server 127.127.1.0 # local clock' >/etc/ntp.conf
- echo 'fudge 127.127.1.0 stratum 2' >>/etc/ntp.conf
- if [ $TIMEZONE ] ; then
- echo $TIMEZONE > /etc/TZ
- echo "export TZ=`cat /etc/TZ`" >> /etc/profile
- export TZ=$TIMEZONE
- ln -sf /usr/share/zoneinfo/$TZNAME /etc/localtime
- fi
- if [ $NTP = "yes" ] ; then
- if [ -x $NTPDATE_BIN ] ; then
- echo -n "Getting initial time via ntp"
- $NTPDATE_BIN $NTPDATE_OPTS $NTPserver > /dev/null 2>&1
- echo "."
- fi
- fi
- #end add for user
-
- log_daemon_msg "Starting NTP server" "ntpd"
- if [ -z "$UGID" ]; then
- log_failure_msg "user \"$RUNASUSER\" does not exist"
- exit 1
- fi
- lock_ntpdate
- start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON -- -p $PIDFILE $NTPD_OPTS
- status=$?
- unlock_ntpdate
- log_end_msg $status
- ;;
- stop)
- log_daemon_msg "Stopping NTP server" "ntpd"
- start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
- log_end_msg $?
- rm -f $PIDFILE
- ;;
- restart|force-reload)
- $0 stop && sleep 2 && $0 start
- ;;
- try-restart)
- if $0 status >/dev/null; then
- $0 restart
- else
- exit 0
- fi
- ;;
- reload)
- exit 3
- ;;
- status)
- status_of_proc $DAEMON "NTP server"
- ;;
- *)
- echo "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
- exit 2
- ;;
- esac
|