~veebers/juju-ci-tools/charm-add-dummy-storage

« back to all changes in this revision

Viewing changes to charms/squid-forwardproxy/hooks/config-changed

  • Committer: Curtis Hovey
  • Date: 2016-10-13 18:09:44 UTC
  • Revision ID: curtis@canonical.com-20161013180944-izh30v269wiscdaz
Added squid-forwardproxy to test closed and restricted networks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
set -eux
 
3
 
 
4
status-set maintenance "Getting dstdomain" || true
 
5
SITENAMES="$(config-get sitenames)"
 
6
PORT="$(config-get port)"
 
7
IP="$(unit-get private-address)"
 
8
LOCALNET=""
 
9
 
 
10
# Create a "localnet" rule for all addresses that can use this proxy.
 
11
for app in $(relation-ids forwardproxy); do
 
12
    for unit in $(relation-list -r $app); do
 
13
        addr="$(relation-get -r $app private-address $unit)"
 
14
        if [[ "$addr" != "" ]]; then
 
15
            LOCALNET="$LOCALNET\nacl localnet src $addr"
 
16
        fi
 
17
    done
 
18
done
 
19
LOCALNET="$(echo -e $LOCALNET)"
 
20
# Create the squid conf that is included in the default conf.
 
21
cat > /etc/squid/forwardproxy.conf << EOF
 
22
http_port $PORT
 
23
$LOCALNET
 
24
http_access allow localnet
 
25
EOF
 
26
 
 
27
service squid restart || service squid start
 
28
 
 
29
if [[ -z $SITENAMES ]]; then
 
30
    status-set active "Proxying: *" || true
 
31
else
 
32
    status-set active "Proxying: $SITENAMES" || true
 
33
fi
 
34
 
 
35
# Update the proxy-ees with the necessary config.
 
36
if [[ $0 != 'config-changed' ]]; then
 
37
    for relation_id in $(relation-ids forwardproxy); do
 
38
        relation-set -r $relation_id ip="$IP" port="$PORT"
 
39
    done
 
40
fi