ports/opt (3.1): openntpd: Improved init script
commit 8370e0eac7f2e094c8bbf872678c4587ae43c888 Author: Alan Mizrahi <alan+crux@mizrahi.com.ve> Date: Wed Nov 19 11:14:36 2014 +0900 openntpd: Improved init script diff --git a/openntpd/.md5sum b/openntpd/.md5sum index fe455d1..1225415 100644 --- a/openntpd/.md5sum +++ b/openntpd/.md5sum @@ -1,3 +1,3 @@ 1edcbbfaed3be43cea078c9b863865e6 linux-adjtimex.patch -6e76cfac0e9fb9bb727c49a98dcf898b ntpd +8e42b6b3709b17ba8b56cb6b1be01543 ntpd afc34175f38d08867c1403d9008600b3 openntpd-3.9p1.tar.gz diff --git a/openntpd/Pkgfile b/openntpd/Pkgfile index 1a920fb..63666c8 100644 --- a/openntpd/Pkgfile +++ b/openntpd/Pkgfile @@ -5,7 +5,7 @@ name=openntpd version=3.9p1 -release=3 +release=4 source=(ftp://ftp.openbsd.org/pub/OpenBSD/OpenNTPD/$name-$version.tar.gz \ ntpd \ linux-adjtimex.patch ) diff --git a/openntpd/ntpd b/openntpd/ntpd index 9061d26..26e6850 100644 --- a/openntpd/ntpd +++ b/openntpd/ntpd @@ -1,23 +1,77 @@ -#!/bin/sh -# -# /etc/rc.d/ntpd: start/stop ntpd daemon -# +#!/bin/bash + +NAME=ntpd +USER=root +CONFIG= +RUNDIR=/var/run +PIDFILE= +STARTCMD="/usr/sbin/ntpd -s" +STOPCMD= +STOPTIMEOUT=120 + +function getpid() { + if [ -z "$PIDFILE" ]; then + pid="$(pgrep -xfn "$STARTCMD")" + else + if [ -f "$PIDFILE" ]; then + pid=$(< $PIDFILE) + if [ ! -d /proc/"$pid" ]; then + echo "$NAME: removing stale pidfile $PIDFILE" >&2 + rm -f "$PIDFILE" + unset pid + fi + fi + fi + echo "$pid" +} case $1 in - start) - /usr/sbin/ntpd -s +start) + pid=$(getpid) + install -d -m 755 -o $USER $RUNDIR || exit 1 + if [ -n "$pid" ]; then + echo "$NAME already running with pid $pid" >&2 + exit 1 + fi + eval "$STARTCMD" ;; - stop) - killall -q /usr/sbin/ntpd +stop) + pid=$(getpid) + if [ -n "$pid" ]; then + if [ -n "$STOPCMD" ]; then + eval "$STOPCMD" + else + kill "$pid" + fi + t=$(printf '%(%s)T' -1) + tend=$((t+STOPTIMEOUT)) + while [ -d /proc/$pid -a $t -lt $tend ]; do + sleep 0.5 + t=$(printf '%(%s)T' -1) + done + if [ -d /proc/"$pid" ]; then + echo "$NAME still running with pid $pid" >&2 + else + [ -n "$PIDFILE" ] && rm -f "$PIDFILE" + fi + else + echo "$NAME is not running" >&2 + fi ;; - restart) +restart) $0 stop - sleep 2 $0 start ;; - *) - echo "usage: $0 [start|stop|restart]" +status) + pid=$(getpid) + if [ -n "$pid" ]; then + echo "$NAME is running with pid $pid" + else + echo "$NAME is not running" + fi + ;; +*) + echo "usage: $0 [start|stop|restart|status]" ;; esac -# End of file
participants (1)
-
crux@crux.nu