File: init.d

package info (click to toggle)
chrony 1.24-3%2Bsqueeze3
  • links: PTS
  • area: main
  • in suites: squeeze-lts
  • size: 2,640 kB
  • ctags: 2,657
  • sloc: ansic: 17,290; yacc: 871; sh: 758; perl: 426; makefile: 155
file content (98 lines) | stat: -rw-r--r-- 2,622 bytes parent folder | download | duplicates (3)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#! /bin/sh
#
# Written by Miquel van Smoorenburg <miquels@drinkel.ow.org>.
# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
# Modified for Debian by Christoph Lameter <clameter@debian.org>
# Modified for chrony by John Hasler <jhasler@debian.org> 1998-2010

### BEGIN INIT INFO
# Provides:          chrony
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Should-Start:      $syslog $network $named $hwclock
# Should-Stop:       $syslog $network $named $hwclock
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Controls chronyd NTP time daemon
# Description:       Chronyd is the NTP time daemon in the Chrony package
### END INIT INFO

PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/sbin/chronyd
FLAGS="defaults"
NAME="chronyd"
DESC="time daemon"

test -f $DAEMON || exit 0

putonline ()
{ # Do we have a default route?  If so put chronyd online.
    if timelimit -q -s9 -t5 -- netstat -rn 2>/dev/null | grep UG | cut -f 1 -d ' ' | grep -q '0\.0\.0\.0' 
    then
	sleep 2  # Chronyd can take a while to start.
	KEY=$(awk '$1 ~ /^commandkey$/ { print $2; exit}' /etc/chrony/chrony.conf)
	PASSWORD=`awk '$1 ~ /^'$KEY'$/ {print $2; exit}' /etc/chrony/chrony.keys`
	# Make sure chronyc can't hang us up.
	if timelimit -q -s9 -t5 -- /usr/bin/chronyc > /dev/null << EOF
password $PASSWORD
online
burst 5/10
quit
EOF
        then
                touch /var/run/chrony-ppp-up
                echo "$NAME is running and online."
        else
                rm -f /var/run/chrony-ppp-up
                echo "$NAME is running and offline."    
        fi
    else
        rm -f /var/run/chrony-ppp-up
        echo "$NAME is running and offline."
    fi
}

case "$1" in
    start)
	start-stop-daemon --start --verbose --exec $DAEMON
	case "$?" in
		0) # daemon successfully started
			putonline
			;;
	        1) # daemon already running
		        ;;
		*) # daemon could not be started
			echo "$DAEMON failed to start."
			exit 1
			;;
	esac
	;;
    stop)
	start-stop-daemon --stop --verbose --oknodo --exec $DAEMON
	rm -f /var/run/chrony-ppp-up
	;;
    restart|force-reload)
	echo -n "Restarting $DESC: "
	start-stop-daemon --stop --quiet --exec $DAEMON
	sleep 1
	start-stop-daemon --start --verbose --exec $DAEMON -- -r
	case "$?" in
		0) # daemon successfully started
			putonline
			;;
	        1) # still running
		        ;;
		*) # daemon could not be started
			echo "$DAEMON failed to restart."
			rm -f /var/run/chrony-ppp-up
			exit 1
			;;
	esac
	;;
    *)
	echo "Usage: /etc/init.d/chrony {start|stop|restart|force-reload}"
	exit 1
	;;
esac

exit 0