1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ntp/rc.ntp Thu Oct 04 20:34:54 2012 +0200 1.3 @@ -0,0 +1,99 @@ 1.4 +#!@l_prefix@/bin/openpkg rc 1.5 +## 1.6 +## rc.ntp -- Run-Commands 1.7 +## 1.8 + 1.9 +%config 1.10 + ntp_enable="$openpkg_rc_def" 1.11 + ntp_mode="daemon" 1.12 + ntp_daemon_flags="" 1.13 + ntp_log_prolog="true" 1.14 + ntp_log_epilog="true" 1.15 + ntp_log_numfiles="10" 1.16 + ntp_log_minsize="1M" 1.17 + ntp_log_complevel="9" 1.18 + 1.19 +%common 1.20 + ntp_pidfile=`grep "^pidfile" @l_prefix@/etc/ntp/ntp.conf | awk '{ printf("%s", $2); }'` 1.21 + ntp_signal () { 1.22 + [ -f $ntp_pidfile ] && kill -$1 `cat $ntp_pidfile` 1.23 + } 1.24 + ntp_once () { 1.25 + [ ".$1" != . ] && sleep $1 1.26 + @l_prefix@/bin/ntpd -q -g 1.27 + } 1.28 + 1.29 +%status -u @l_susr@ -o 1.30 + ntp_usable="unknown" 1.31 + ntp_active="no" 1.32 + rcService ntp enable yes && \ 1.33 + [ ".$ntp_mode" = ".daemon" ] && \ 1.34 + ntp_signal 0 && ntp_active="yes" 1.35 + echo "ntp_enable=\"$ntp_enable\"" 1.36 + echo "ntp_usable=\"$ntp_usable\"" 1.37 + echo "ntp_active=\"$ntp_active\"" 1.38 + 1.39 +%start -p 200 -u @l_susr@ 1.40 + rcService ntp enable yes || exit 0 1.41 + rcService ntp active yes && exit 0 1.42 + 1.43 + # under both periodical and daemon mode, synchronize local machine 1.44 + # once manually -- either to fill the gap between startup time and 1.45 + # the first run of the cron jobs (periodical mode) or to perform 1.46 + # a possible large time offset which ntpd does not perform itself 1.47 + # (daemon mode). 1.48 + case "$ntp_mode" in 1.49 + once | \ 1.50 + daemon | \ 1.51 + quarterly | hourly | daily | weekly | monthly ) 1.52 + ntp_once 1.53 + ;; 1.54 + esac 1.55 + 1.56 + # run the NTP daemon for continued synchronization 1.57 + if [ ".$ntp_mode" = .daemon ]; then 1.58 + @l_prefix@/bin/ntpd ${ntp_daemon_flags} 1.59 + fi 1.60 + 1.61 +%stop -p 800 -u @l_susr@ 1.62 + rcService ntp enable yes || exit 0 1.63 + rcService ntp active no && exit 0 1.64 + ntp_signal TERM 1.65 + rm -f $ntp_pidfile 2>/dev/null || true 1.66 + 1.67 +%restart -p 200 -u @l_susr@ 1.68 + rcService ntp enable yes || exit 0 1.69 + rcService ntp active no && exit 0 1.70 + rc ntp stop start 1.71 + 1.72 +%quarterly -p 800 -u @l_susr@ 1.73 + rcService ntp enable yes || exit 0 1.74 + [ ".$ntp_mode" = .quarterly ] && ntp_once 30 1.75 + exit 0 1.76 + 1.77 +%hourly -p 800 -u @l_susr@ 1.78 + rcService ntp enable yes || exit 0 1.79 + [ ".$ntp_mode" = .hourly ] && ntp_once 30 1.80 + exit 0 1.81 + 1.82 +%daily -p 800 -u @l_susr@ 1.83 + rcService ntp enable yes || exit 0 1.84 + [ ".$ntp_mode" = .daily ] && ntp_once 30 1.85 + shtool rotate -f \ 1.86 + -n ${ntp_log_numfiles} -s ${ntp_log_minsize} -d \ 1.87 + -z ${ntp_log_complevel} -m 644 -o @l_susr@ -g @l_mgrp@ \ 1.88 + -P "${ntp_log_prolog}" \ 1.89 + -E "${ntp_log_epilog}; rc ntp restart" \ 1.90 + @l_prefix@/var/ntp/ntp.log 1.91 + exit 0 1.92 + 1.93 +%weekly -p 800 -u @l_susr@ 1.94 + rcService ntp enable yes || exit 0 1.95 + [ ".$ntp_mode" = .weekly ] && ntp_once 30 1.96 + exit 0 1.97 + 1.98 +%monthly -p 800 -u @l_susr@ 1.99 + rcService ntp enable yes || exit 0 1.100 + [ ".$ntp_mode" = .monthly ] && ntp_once 30 1.101 + exit 0 1.102 +