summaryrefslogtreecommitdiff
path: root/source/n/ntp/rc.ntpd
blob: d1ad4484145c208ef5862fde089b4796ece4121f (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
#!/bin/sh
# Start/stop/restart ntpd.

# Start ntpd:
ntpd_start() {
  echo -n "Starting NTP daemon:  /usr/sbin/ntpd -g -u ntp:ntp"
  /usr/sbin/ntpd -g -u ntp:ntp
  echo
}

# Stop ntpd:
ntpd_stop() {
  echo -n "Stopping NTP daemon..."
  if [ -r /var/run/ntpd.pid ]; then
    kill -HUP $(cat /var/run/ntpd.pid)
    rm -f /var/run/ntpd.pid
  else
    killall -HUP -q ntpd
  fi
  echo
}

# Restart ntpd:
ntpd_restart() {
  ntpd_stop
  sleep 1
  ntpd_start
}

# Check if ntpd is running
ntpd_status() {
  if [ -e /var/run/ntpd.pid ]; then
    echo "ntpd is running as pid $(cat /var/run/ntpd.pid)."
  else 
    echo "ntpd is stopped."
    exit 1
  fi
}

case "$1" in
'start')
  ntpd_start
  ;;
'stop')
  ntpd_stop
  ;;
'restart')
  ntpd_restart
  ;;
'status')
  ntpd_status
  ;;
*)
  echo "usage $0 start|stop|restart|status"
esac