Compare commits

...

1 Commits

Author SHA1 Message Date
Henning Heinold c046dbb883 ntp: change the cron call for ntpdate
* the ntpdate cron job turned into
  a shell script which now checks
  for running timeserver before
  updating the time via ntpdate

* install the cron stanza to the
  cron.d directory like serval
  other packages does

* comment the entry in the old
  crontab file when found

Fixes: SYS#1841
2015-09-15 20:32:59 +02:00
3 changed files with 54 additions and 7 deletions

View File

@ -0,0 +1,34 @@
#!/bin/sh
# script installed as cronjob for handling
# machines which have not ntp or systemd-timessyncd installed
#
# (C) 2015 by sysmocom - s.f.m.c. GmbH
# Author: Henning Heinold
RUN_NTPDATE=1
# check for systemd otherwise assume sysvinit with ps
systemctl > /dev/null 2>&1
if [ $? -eq 0 ]; then
systemctl status ntpd > /dev/null 2>&1 || systemctl status systemd-timesyncd > /dev/null 2>&1
else
PS="ps"
ps -ef > /dev/null 2>&1
if [ $? -eq 0 ]; then
PS="ps -ef"
fi
# poor man search for a running ntpd
# under sysvinit we have no systemd-timesyncd
$PS | grep -v grep | grep "ntpd " > /dev/null 2>&1
fi
RUN_NTPDATE=$?
# the commands must fail to run ntpdate
if [ ${RUN_NTPDATE} -ne 0 ]; then
__bindir__/ntpdate-sync silent
fi

View File

@ -0,0 +1 @@
*/30 * * * * root __bindir__/ntpdate-cron

View File

@ -21,9 +21,11 @@ SRC_URI = "http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-${PV}.tar.g
file://sntp.service \
file://sntp \
file://ntpd.list \
file://ntpdate-cron \
file://ntpdate.cron \
"
PR = "r7"
PR = "r8"
SRC_URI[md5sum] = "65d8cdfae4722226fbe29863477641ed"
SRC_URI[sha256sum] = "948274b88f1ed002d867ced6aaefdfd0999668b11285ac2b3a67ff2629d59d88"
@ -64,6 +66,8 @@ do_install_append() {
install -m 755 ${WORKDIR}/ntpd ${D}${sysconfdir}/init.d
install -d ${D}${bindir}
install -m 755 ${WORKDIR}/ntpdate ${D}${bindir}/ntpdate-sync
install -m 755 ${WORKDIR}/ntpdate-cron ${D}${bindir}/ntpdate-cron
install -D -m 0644 ${WORKDIR}/ntpdate.cron ${D}${sysconfdir}/cron.d/ntpdate
install -m 755 -d ${D}${NTP_USER_HOME}
chown ntp:ntp ${D}${NTP_USER_HOME}
@ -74,6 +78,8 @@ do_install_append() {
sed -i 's!/etc/!${sysconfdir}/!g' ${D}${sysconfdir}/init.d/ntpd ${D}${bindir}/ntpdate-sync
sed -i 's!/var/!${localstatedir}/!g' ${D}${sysconfdir}/init.d/ntpd ${D}${bindir}/ntpdate-sync
sed -i 's!^PATH=.*!PATH=${base_sbindir}:${base_bindir}:${sbindir}:${bindir}!' ${D}${bindir}/ntpdate-sync
sed -i 's!__bindir__!${bindir}!g' ${D}${bindir}/ntpdate-cron
sed -i 's!__bindir__!${bindir}!g' ${D}${sysconfdir}/cron.d/ntpdate
sed -i '1s,#!.*perl -w,#! ${bindir}/env perl,' ${D}${sbindir}/ntptrace
sed -i '/use/i use warnings;' ${D}${sbindir}/ntptrace
sed -i '1s,#!.*perl,#! ${bindir}/env perl,' ${D}${sbindir}/ntp-wait
@ -136,6 +142,8 @@ FILES_ntpdate = "${sbindir}/ntpdate \
${bindir}/ntpdate-sync \
${sysconfdir}/default/ntpdate \
${systemd_unitdir}/system/ntpdate.service \
${bindir}/ntpdate-cron \
${sysconfdir}/cron.d/ntpdate \
"
FILES_sntp = "${sbindir}/sntp \
${sysconfdir}/default/sntp \
@ -143,17 +151,21 @@ FILES_sntp = "${sbindir}/sntp \
"
CONFFILES_${PN} = "${sysconfdir}/ntp.conf"
CONFFILES_ntpdate = "${sysconfdir}/default/ntpdate"
CONFFILES_ntpdate = "${sysconfdir}/default/ntpdate ${sysconfdir}/cron.d/ntpdate"
INITSCRIPT_NAME = "ntpd"
# No dependencies, so just go in at the standard level (20)
INITSCRIPT_PARAMS = "defaults"
pkg_postinst_ntpdate() {
if ! grep -q -s ntpdate $D/var/spool/cron/root; then
echo "adding crontab"
test -d $D/var/spool/cron || mkdir -p $D/var/spool/cron
echo "30 * * * * ${bindir}/ntpdate-sync silent" >> $D/var/spool/cron/root
if grep -q -s ntpdate $D/var/spool/cron/root; then
echo "comment the old crontab entry"
sed -i -e "/^[^#]/ s/\(.*\)\(.*ntpdate-sync.*$\)/#\1\2/g" $D/var/spool/cron/root
fi
systemctl status crond > /dev/null 2>&1
if [ $? -eq 0 ]; then
systemctl restart crond
else
/etc/init.d/cron restart
fi
}