]> git.pld-linux.org Git - packages/chrony.git/blob - chronyd.init
- rel 4; socket based authentication is gone for some time; enable optional (-d)...
[packages/chrony.git] / chronyd.init
1 #!/bin/sh
2 #
3 # chronyd       chronyd short service description
4 #
5 # chkconfig:   2345 58 74
6 # description: Client/server for the Network Time Protocol, \
7 #              this program keeps your computer's clock accurate.
8 #
9
10 # Source function library
11 . /etc/rc.d/init.d/functions
12
13 # Get network config
14 . /etc/sysconfig/network
15
16 # default user if not overriden by config
17 NTPD_USER="ntp"
18
19 # Get service config - may override defaults
20 [ -f /etc/sysconfig/chronyd ] && . /etc/sysconfig/chronyd
21
22 # Check that networking is up.
23 if is_yes "${NETWORKING}"; then
24         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
25                 msg_network_down "Chronyd NTPD"
26                 exit 1
27         fi
28 else
29         exit 0
30 fi
31
32 config=/etc/ntp/chrony.conf
33 keyfile=/etc/ntp/keys
34 chronyc=/usr/bin/chronyc
35
36 chrony_command() {
37     ! (
38         $chronyc <<EOF &
39 $1
40 EOF
41         chronycpid=$!
42
43         # chronyc will hang if the daemon doesn't respond, kill it after 3 s
44                 #'
45         (sleep 3; kill $chronycpid) < /dev/null > /dev/null 2>&1 &
46         killerpid=$!
47
48         wait $chronycpid >/dev/null 2>&1
49         kill $killerpid >/dev/null 2>&1 || echo "chronyd not responding"
50     ) | grep -v '200 OK'
51 }
52
53 start() {
54         # Check if the service is already running?
55         if [ -f /var/lock/subsys/chronyd ]; then
56                 msg_already_running "Chronyd NTPD"
57                 return
58         fi
59
60         msg_starting "Chronyd NTPD"
61         daemon /usr/sbin/chronyd -u $NTPD_USER $OPTIONS
62         RETVAL=$?
63         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/chronyd
64 }
65
66 stop() {
67         if [ ! -f /var/lock/subsys/chronyd ]; then
68                 msg_not_running "Chronyd NTPD"
69                 return
70         fi
71
72         # Stop daemons.
73         msg_stopping "Chronyd NTPD"
74         killproc chronyd
75         rm -f /var/lock/subsys/chronyd
76 }
77
78 condrestart() {
79         if [ ! -f /var/lock/subsys/chronyd ]; then
80                 msg_not_running "Chronyd NTPD"
81                 RETVAL=$1
82                 return
83         fi
84
85         stop
86         start
87 }
88
89 RETVAL=0
90 # See how we were called.
91 case "$1" in
92   start)
93         start
94         ;;
95   stop)
96         stop
97         ;;
98   restart)
99         stop
100         start
101         ;;
102   try-restart)
103         condrestart 0
104         ;;
105   force-reload)
106         condrestart 7
107         ;;
108   cyclelogs|flush-logs)
109         status chronyd >/dev/null 2>&1 || exit 7
110         chrony_command cyclelogs
111         ;;
112   online|offline)
113         status chronyd >/dev/null 2>&1 || exit 7
114         chrony_command $1
115         ;;
116   command)
117         status chronyd >/dev/null 2>&1 || exit 7
118         chrony_command "$2"
119         ;;
120   status)
121         status chronyd
122         RETVAL=$?
123         if [ $RETVAL = 0 ]; then
124                 chrony_command sources
125         fi
126         ;;
127   *)
128         msg_usage "$0 {start|stop|restart|try-restart|force-reload|online|offline|cyclelogs|command|status}"
129         exit 3
130 esac
131
132 exit $RETVAL
This page took 0.062511 seconds and 3 git commands to generate.