From b1f0282c6a369780bffee14497da143f48297847 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 10 May 2009 17:52:04 +0200 Subject: [PATCH] ntp: switch to OpenRC. Create ntpd user/group for chroot. --HG-- extra : convert_revision : 5ecbdd2f519c0605978a7a2e3e503dae5bb7e99f --- templates/ntp/INSTALL | 24 ++++++++++++++++++++++ templates/ntp/REMOVE | 11 ++++++++++ templates/ntp/files/ntp.conf | 2 +- templates/ntp/files/ntpd | 19 ----------------- templates/ntp/files/ntpd.confd | 6 ++++++ templates/ntp/files/ntpd.rc | 37 ++++++++++++++++++++++++++++++++++ templates/ntp/files/ntpdate | 36 --------------------------------- templates/ntp/template | 13 ++++++++---- 8 files changed, 88 insertions(+), 60 deletions(-) create mode 100644 templates/ntp/INSTALL create mode 100644 templates/ntp/REMOVE delete mode 100644 templates/ntp/files/ntpd create mode 100644 templates/ntp/files/ntpd.confd create mode 100644 templates/ntp/files/ntpd.rc delete mode 100644 templates/ntp/files/ntpdate diff --git a/templates/ntp/INSTALL b/templates/ntp/INSTALL new file mode 100644 index 0000000000..2272d605c4 --- /dev/null +++ b/templates/ntp/INSTALL @@ -0,0 +1,24 @@ +# +# This script creates the ntpd system user/group. +# + +case "${ACTION}" in +pre) + ;; +post) + echo "Running ${PKGNAME}-${VERSION} post installation hooks..." + if ! getent group ntpd >/dev/null; then + groupadd -r ntpd 2>&1 >/dev/null + [ $? -ne 0 ] && exit $? + echo "Created ntpd system group." + fi + if ! getent passwd ntpd >/dev/null; then + useradd -c "Network Time Protocol Daemon" \ + -d /var/chroot/ntpd \ + -s /sbin/nologin -g ntpd -r ntpd && \ + passwd -l ntpd 2>&1 >/dev/null + [ $? -ne 0 ] && exit $? + echo "Created ntpd system user." + fi + ;; +esac diff --git a/templates/ntp/REMOVE b/templates/ntp/REMOVE new file mode 100644 index 0000000000..9157bf0c89 --- /dev/null +++ b/templates/ntp/REMOVE @@ -0,0 +1,11 @@ +# +# This script removes the ntpd user/group. +# +case "${ACTION}" in +pre) + userdel ntpd 2>&1 >/dev/null + [ $? -eq 0 ] && echo "Removed ntpd system user/group." + ;; +post) + ;; +esac diff --git a/templates/ntp/files/ntp.conf b/templates/ntp/files/ntp.conf index 8d22843c63..759ef1bb5c 100644 --- a/templates/ntp/files/ntp.conf +++ b/templates/ntp/files/ntp.conf @@ -17,7 +17,7 @@ pidfile /var/run/ntpd.pid # The correction calculated by ntpd(8) for the local system clock's # drift is stored here. -driftfile /var/db/ntp.drift +driftfile /var/db/ntpd.drift # Suppress the syslog(3) message for each peer synchronization change. diff --git a/templates/ntp/files/ntpd b/templates/ntp/files/ntpd deleted file mode 100644 index e836d88858..0000000000 --- a/templates/ntp/files/ntpd +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh -# -# $NetBSD: ntpd,v 1.13 2004/08/13 18:08:03 mycroft Exp $ -# - -# PROVIDE: ntpd -# REQUIRE: DAEMON -# BEFORE: LOGIN - -$_rc_subr_loaded . /etc/rc.subr - -name="ntpd" -rcvar=$name -command="/usr/bin/${name}" -pidfile="/var/run/${name}.pid" -required_files="/etc/ntp.conf" - -load_rc_config $name -run_rc_command "$1" diff --git a/templates/ntp/files/ntpd.confd b/templates/ntp/files/ntpd.confd new file mode 100644 index 0000000000..06b64575ac --- /dev/null +++ b/templates/ntp/files/ntpd.confd @@ -0,0 +1,6 @@ +# Configuration file for ntp. +# +# Uncomment the following to run ntpd(8) enjailed in +# a chroot directory. +# +#ntpd_chroot=/var/chroot/ntpd diff --git a/templates/ntp/files/ntpd.rc b/templates/ntp/files/ntpd.rc new file mode 100644 index 0000000000..cf0e14a163 --- /dev/null +++ b/templates/ntp/files/ntpd.rc @@ -0,0 +1,37 @@ +#!/sbin/runscript +# Copyright (c) 2007-2009 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +: ${ntpd_config:=/etc/ntp.conf} +: ${ntpd_drift:=/var/db/ntpd.drift} + +command=/usr/bin/ntpd +required_files=$ntpd_config +pidfile=/var/run/ntpd.pid +command_args="$ntpd_args -c $ntpd_config -f $ntpd_drift -p $pidfile" +name="Network Time Protocol Daemon" + +depend() +{ + use dns + need localmount + after bootmisc ntp-client +} + +start_pre() +{ + if [ -n "$ntpd_chroot" ]; then + case "$RC_UNAME" in + *BSD|DragonFly) + if [ ! -c "$ntpd_chroot/dev/clockctl" ]; then + rm -f "$ntpd_chroot/dev/clockctl" + (cd /dev; /bin/pax -rw -pe clockctl \ + "$ntpd_chroot/dev") + fi + ;; + esac + ln -fs "$ntpd_chroot$ntpd_drift" "$ntpd_drift" + + command_args="$command_args -u ntpd:ntpd -i $ntpd_chroot" + fi +} diff --git a/templates/ntp/files/ntpdate b/templates/ntp/files/ntpdate deleted file mode 100644 index d07aea0199..0000000000 --- a/templates/ntp/files/ntpdate +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -# -# $NetBSD: ntpdate,v 1.18 2005/03/15 12:06:12 lukem Exp $ -# - -# PROVIDE: ntpdate -# REQUIRE: NETWORKING LOGIN - -$_rc_subr_loaded . /etc/rc.subr - -name="ntpdate" -rcvar=$name -command="/usr/bin/${name}" -start_cmd="ntpdate_start" -stop_cmd=":" - -ntpdate_start() -{ - if [ -z "$ntpdate_hosts" ]; then - ntpdate_hosts=$(awk ' - /^#/ { next } - /^(server|peer)[ \t]*127.127/ { next } - /^(server|peer)/ { if ($2 ~ /^-[46]/) - print $3 - else - print $2 } - ' &1 >/dev/null & - fi -} - -load_rc_config $name -run_rc_command "$1" diff --git a/templates/ntp/template b/templates/ntp/template index 94c2e0413c..a205b029f1 100644 --- a/templates/ntp/template +++ b/templates/ntp/template @@ -2,7 +2,7 @@ pkgname=ntp sourcepkg=$pkgname version=4.2.4p6 -revision=1 +revision=2 distfiles="http://archive.ntp.org/ntp4/$pkgname-$version.tar.gz" build_style=gnu_configure configure_args="--enable-linuxcaps --enable-getifaddrs=glibc @@ -19,17 +19,22 @@ long_desc=" subpackages="perl" conf_files="/etc/ntp.conf" +openrc_services="ntpd default" +triggers="openrc-service" Add_dependency full glibc Add_dependency full openssl +Add_dependency run ncurses-libs +Add_dependency run OpenRC post_install() { - install -d ${DESTDIR}/etc/rc.d + install -d ${DESTDIR}/var/chroot/ntpd + install -d ${DESTDIR}/etc/init.d ${DESTDIR}/etc/conf.d install -d ${DESTDIR}/usr/share/ntp install -d ${DESTDIR}/usr/share/doc/ntp - install -m 755 ${FILESDIR}/ntpd ${DESTDIR}/etc/rc.d/ntpd - install -m 755 ${FILESDIR}/ntpdate ${DESTDIR}/etc/rc.d/ntpdate + install -m 644 ${FILESDIR}/ntpd.confd ${DESTDIR}/etc/conf.d/ntpd + install -m 755 ${FILESDIR}/ntpd.rc ${DESTDIR}/etc/init.d/ntpd install -m 644 ${FILESDIR}/ntp.conf ${DESTDIR}/etc/ntp.conf cp -a ${wrksrc}/html ${DESTDIR}/usr/share/doc/ntp cp -a ${wrksrc}/conf ${DESTDIR}/usr/share/ntp