openntpd: Improved init script

This commit is contained in:
Alan Mizrahi 2014-11-19 11:14:36 +09:00
parent ee93490efa
commit 8370e0eac7
3 changed files with 69 additions and 15 deletions

View File

@ -1,3 +1,3 @@
1edcbbfaed3be43cea078c9b863865e6 linux-adjtimex.patch
6e76cfac0e9fb9bb727c49a98dcf898b ntpd
8e42b6b3709b17ba8b56cb6b1be01543 ntpd
afc34175f38d08867c1403d9008600b3 openntpd-3.9p1.tar.gz

View File

@ -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 )

View File

@ -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