summaryrefslogtreecommitdiffstats
path: root/generic/etc/init.d/ntp
blob: 8ae07b03957a439f7429082ba3a708757e2c9039 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/sh
# 
# This is a ntp init.d script which ist called by init(1) with [start|stop] as argument
# PII ntp config 
# Wed May 25 14:36:31 CEST 2005

PATH=/sbin:/bin:/usr/bin
BINARY=/usr/sbin/ntpd
PIDFILE="/var/run/ntpd.pid"

case "`basename $0`" in 
	ntp-client)
		CONFIG="/etc/ntp-client.conf"
		;;
	ntp-server)
		CONFIG="/etc/ntp-server.conf"
		;;
	*)
		echo "script has to be ntp-client or ntp-server"
		exit 1
		;;
esac

HARD=false

# --- nothing to change after this line ---

test -f $BINARY || { echo "$BINARY not found" >&2 ; exit 0; }

start_proc() {
	echo -n "Starting NTP server: ntpd ..."
	test -f "$PIDFILE" && { echo "pid-file exists" >&2 ; exit 0; }
	$BINARY -p $PIDFILE -c $CONFIG
	echo "DONE"
}

stop_proc() {
	echo -n "Stopping NTP server: ntpd ..."
	test -f "$PIDFILE"
	case $? in
		0)
			kill `cat $PIDFILE` && rm -f $PIDFILE
			;;
		*)
			if [ "$HARD" = "true" ] ; then killall ntpd; fi
			;;
	esac
	echo "DONE"
}


case "$1" in
        start)
        	start_proc
		;;
	stop)	
		stop_proc
		;;
        restart|force-reload)
                echo -n "Restarting NTP server: ntpd... "
                stop_proc
		sleep 2
                start_proc
		echo "done."
                ;;
        reload)
                echo "Not supported" >&2
                exit 1
                ;;
        *)
                echo "Usage: $0 {start|stop|restart|force-reload}"
                exit 1
                ;;
esac

exit 0