ntp/rc.ntp

Mon, 28 Jan 2013 17:37:18 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Mon, 28 Jan 2013 17:37:18 +0100
changeset 758
a2c6460cfb16
permissions
-rw-r--r--

Correct socket error reporting improvement with IPv6 portable code,
after helpful recommendation by Saúl Ibarra Corretgé on OSips devlist.

michael@719 1 #!@l_prefix@/bin/openpkg rc
michael@719 2 ##
michael@719 3 ## rc.ntp -- Run-Commands
michael@719 4 ##
michael@719 5
michael@719 6 %config
michael@719 7 ntp_enable="$openpkg_rc_def"
michael@719 8 ntp_mode="daemon"
michael@719 9 ntp_daemon_flags=""
michael@719 10 ntp_log_prolog="true"
michael@719 11 ntp_log_epilog="true"
michael@719 12 ntp_log_numfiles="10"
michael@719 13 ntp_log_minsize="1M"
michael@719 14 ntp_log_complevel="9"
michael@719 15
michael@719 16 %common
michael@719 17 ntp_pidfile=`grep "^pidfile" @l_prefix@/etc/ntp/ntp.conf | awk '{ printf("%s", $2); }'`
michael@719 18 ntp_signal () {
michael@719 19 [ -f $ntp_pidfile ] && kill -$1 `cat $ntp_pidfile`
michael@719 20 }
michael@719 21 ntp_once () {
michael@719 22 [ ".$1" != . ] && sleep $1
michael@719 23 @l_prefix@/bin/ntpd -q -g
michael@719 24 }
michael@719 25
michael@719 26 %status -u @l_susr@ -o
michael@719 27 ntp_usable="unknown"
michael@719 28 ntp_active="no"
michael@719 29 rcService ntp enable yes && \
michael@719 30 [ ".$ntp_mode" = ".daemon" ] && \
michael@719 31 ntp_signal 0 && ntp_active="yes"
michael@719 32 echo "ntp_enable=\"$ntp_enable\""
michael@719 33 echo "ntp_usable=\"$ntp_usable\""
michael@719 34 echo "ntp_active=\"$ntp_active\""
michael@719 35
michael@719 36 %start -p 200 -u @l_susr@
michael@719 37 rcService ntp enable yes || exit 0
michael@719 38 rcService ntp active yes && exit 0
michael@719 39
michael@719 40 # under both periodical and daemon mode, synchronize local machine
michael@719 41 # once manually -- either to fill the gap between startup time and
michael@719 42 # the first run of the cron jobs (periodical mode) or to perform
michael@719 43 # a possible large time offset which ntpd does not perform itself
michael@719 44 # (daemon mode).
michael@719 45 case "$ntp_mode" in
michael@719 46 once | \
michael@719 47 daemon | \
michael@719 48 quarterly | hourly | daily | weekly | monthly )
michael@719 49 ntp_once
michael@719 50 ;;
michael@719 51 esac
michael@719 52
michael@719 53 # run the NTP daemon for continued synchronization
michael@719 54 if [ ".$ntp_mode" = .daemon ]; then
michael@719 55 @l_prefix@/bin/ntpd ${ntp_daemon_flags}
michael@719 56 fi
michael@719 57
michael@719 58 %stop -p 800 -u @l_susr@
michael@719 59 rcService ntp enable yes || exit 0
michael@719 60 rcService ntp active no && exit 0
michael@719 61 ntp_signal TERM
michael@719 62 rm -f $ntp_pidfile 2>/dev/null || true
michael@719 63
michael@719 64 %restart -p 200 -u @l_susr@
michael@719 65 rcService ntp enable yes || exit 0
michael@719 66 rcService ntp active no && exit 0
michael@719 67 rc ntp stop start
michael@719 68
michael@719 69 %quarterly -p 800 -u @l_susr@
michael@719 70 rcService ntp enable yes || exit 0
michael@719 71 [ ".$ntp_mode" = .quarterly ] && ntp_once 30
michael@719 72 exit 0
michael@719 73
michael@719 74 %hourly -p 800 -u @l_susr@
michael@719 75 rcService ntp enable yes || exit 0
michael@719 76 [ ".$ntp_mode" = .hourly ] && ntp_once 30
michael@719 77 exit 0
michael@719 78
michael@719 79 %daily -p 800 -u @l_susr@
michael@719 80 rcService ntp enable yes || exit 0
michael@719 81 [ ".$ntp_mode" = .daily ] && ntp_once 30
michael@719 82 shtool rotate -f \
michael@719 83 -n ${ntp_log_numfiles} -s ${ntp_log_minsize} -d \
michael@719 84 -z ${ntp_log_complevel} -m 644 -o @l_susr@ -g @l_mgrp@ \
michael@719 85 -P "${ntp_log_prolog}" \
michael@719 86 -E "${ntp_log_epilog}; rc ntp restart" \
michael@719 87 @l_prefix@/var/ntp/ntp.log
michael@719 88 exit 0
michael@719 89
michael@719 90 %weekly -p 800 -u @l_susr@
michael@719 91 rcService ntp enable yes || exit 0
michael@719 92 [ ".$ntp_mode" = .weekly ] && ntp_once 30
michael@719 93 exit 0
michael@719 94
michael@719 95 %monthly -p 800 -u @l_susr@
michael@719 96 rcService ntp enable yes || exit 0
michael@719 97 [ ".$ntp_mode" = .monthly ] && ntp_once 30
michael@719 98 exit 0
michael@719 99

mercurial