summaryrefslogtreecommitdiff
blob: 09f3729300c3ff07f6fe06e995cd7694c8802fe1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/sbin/runscript
# Copyright 1999-2002 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2         
# $Header: /var/cvsroot/gentoo-x86/net-misc/ntp/files/ntpd.rc,v 1.6 2002/12/23 17:12:48 vapier Exp $

depend() {
	need net
}

checkconfig() {
	if [ ! -f /etc/ntp.conf ] ; then
		eerror "Please create /etc/ntp.conf"
		return 1
	fi

	return 0
}

start() {
	checkconfig || return $?

	NTPDATESERVERS=`egrep '^(server|peer)[[:space:]]+' /etc/ntp.conf | awk '{print $2}'`
	if [ -n "${NTPDATESERVERS}" ] ; then
		ebegin "Running ntpdate"
		ntpdate -b ${NTPDATESERVERS} > /dev/null
		eend $? "Failed to run ntpdate"
	else
		ewarn "Please set a valid server line in /etc/ntp.conf"
	fi

	ebegin "Starting ntpd"
	start-stop-daemon --start --quiet --pidfile /var/run/ntpd.pid \
		--startas /usr/bin/ntpd -- -p /var/run/ntpd.pid
	eend $? "Failed to start ntpd"
}

stop() {
	ebegin "Stopping ntpd"
	start-stop-daemon --stop --quiet --pidfile /var/run/ntpd.pid
	eend $? "Failed to stop ntpd"

	# clean stale pidfile
	[ -f /var/run/ntpd.pid ] && rm -f /var/run/ntpd.pid
}