~landscape/charms/trusty/ntpmaster/trunk

« back to all changes in this revision

Viewing changes to hooks/config-changed

  • Committer: James Page
  • Date: 2013-08-29 13:19:15 UTC
  • mfrom: (1.1.55 ntpmaster)
  • Revision ID: james.page@canonical.com-20130829131915-gfu6zoqy5yj46c6s
Python rewrite from melmoth

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
 
3
 
set -e
4
 
 
5
 
source=`config-get source`
6
 
 
7
 
if [[ -n "$source" && $source != 'LOCAL' ]]
8
 
then
9
 
    cat > /etc/ntp.conf << EOF
10
 
# juju generate ntp configuration
11
 
driftfile /var/lib/ntp/ntp.drift
12
 
statistics loopstats peerstats clockstats
13
 
filegen loopstats file loopstats type day enable
14
 
filegen peerstats file peerstats type day enable
15
 
filegen clockstats file clockstats type day enable
16
 
restrict -4 default kod notrap nomodify nopeer noquery
17
 
restrict -6 default kod notrap nomodify nopeer noquery
18
 
restrict 127.0.0.1
19
 
restrict ::1
20
 
EOF
21
 
    for host in $source
22
 
    do
23
 
        echo "server $host iburst" >> /etc/ntp.conf
24
 
    done
25
 
elif [[ -n "$source" && $source == 'LOCAL' ]] 
26
 
 then
27
 
 echo "THIS IS GOING TO BE A LOCAL SERVER"
28
 
 echo "Let s pretent the local clock is stratum 5"
29
 
    cat > /etc/ntp.conf << EOF
30
 
# juju generate ntp configuration
31
 
driftfile /var/lib/ntp/ntp.drift
32
 
statistics loopstats peerstats clockstats
33
 
filegen loopstats file loopstats type day enable
34
 
filegen peerstats file peerstats type day enable
35
 
filegen clockstats file clockstats type day enable
36
 
restrict -4 default kod notrap nomodify nopeer noquery
37
 
restrict -6 default kod notrap nomodify nopeer noquery
38
 
restrict 127.0.0.1
39
 
server 127.127.1.0
40
 
fudge   127.127.1.0 stratum 5
41
 
restrict ::1
42
 
EOF
43
 
else
44
 
    # Restore backup of installed file
45
 
    cp /etc/ntp.conf.orig /etc/ntp.conf
46
 
fi
47
 
 
48
 
service ntp restart || true
49