~julian-edwards/maas/packaging-syslog

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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/sh

set -e

. /usr/share/debconf/confmodule
db_version 2.0

RELEASE=`lsb_release -rs` || RELEASE=""

restart_squid_deb_proxy() {
    invoke-rc.d squid-deb-proxy restart || true
}

configure_region_http() {
    case $RELEASE in
        12.04|12.10|13.04)
            # handle apache configs
            if [ -e /etc/maas/maas-http.conf -a \
                ! -e /etc/apache2/conf.d/maas-http.conf ]; then
                ln -sf /etc/maas/maas-http.conf /etc/apache2/conf.d/maas-http.conf
            fi
            ;;
        *)
            # handle apache configs
            if [ -e /etc/maas/maas-http.conf -a \
                ! -e /etc/apache2/conf-enabled/maas-http.conf ]; then
                ln -sf /etc/maas/maas-http.conf /etc/apache2/conf-enabled/maas-http.conf
            fi
            ;;
    esac
    # enable apache modules needed
    a2enmod proxy_http
    a2enmod expires
    a2enmod wsgi
}

configure_maas_default_url() {
    local ipaddr="$1"

    if grep -qs "^DEFAULT_MAAS_URL\ \= \"[a-zA-Z0-9:/.]\{0,\}\"$" /etc/maas/maas_local_settings.py; then
        sed -i "s/^DEFAULT_MAAS_URL\ \= \"[a-zA-Z0-9:/.]\{0,\}\"$/DEFAULT_MAAS_URL = \"http:\/\/$ipaddr\/MAAS\"/" /etc/maas/maas_local_settings.py
    fi
}

get_default_route_ip() {
    while read Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT; do
        [ "$Mask" = "00000000" ] && break
    done < /proc/net/route
    interface="$Iface"
    ipaddr=$(LC_ALL=C /sbin/ip -4 addr list dev "$interface" scope global)
    ipaddr=${ipaddr#* inet }
    ipaddr=${ipaddr%%/*}
    echo $ipaddr
}

configure_maas_squid_deb_proxy() {
    local ipaddr="$1"

    if [ -e /usr/share/maas/conf/99-maas -a \
        ! -L /etc/squid-deb-proxy/mirror-dstdomain.acl.d/99-maas ]; then
        ln -sf /usr/share/maas/conf/99-maas \
               /etc/squid-deb-proxy/mirror-dstdomain.acl.d/99-maas
    fi

    sed -i "s/\(^[a-zA-Z0-9\.\-].*\) # maasurl$/$ipaddr # maasurl/" \
        /usr/share/maas/conf/99-maas
}

# Please keep this stanza until 14.10
if [ "$1" = "configure" ]; then
        if dpkg --compare-versions "$2" le-nl 1.5+bzr1909-0ubuntu1 ; then
                chown root:maas /etc/maas/txlongpoll.yaml
                chmod 0640 /etc/maas/txlongpoll.yaml
        fi
fi

if [ "$1" = "configure" ] && [ -z "$2" ]; then
    #########################################################
    ################ Folder Permissions  ####################
    #########################################################
    mkdir -p /var/lib/maas/media/storage
    chown -R maas:maas /var/lib/maas/

    # Config will contain credentials, so should be readable
    # by the application but nobody else.
    chown root:maas \
        /etc/maas/maas_local_celeryconfig.py \
        /etc/maas/maas_local_settings.py \
        /etc/maas/txlongpoll.yaml
    chmod 0640 \
        /etc/maas/maas_local_celeryconfig.py \
        /etc/maas/maas_local_settings.py \
        /etc/maas/txlongpoll.yaml

    #########################################################
    ################  Configure Apache2  ####################
    #########################################################
    configure_region_http

    #########################################################
    ##########  Configure DEFAULT_MAAS_URL  #################
    #########################################################

    # Obtain IP address of default route and change DEFAULT_MAAS_URL
    # if default-maas-url has not been preseeded.
    db_get maas/default-maas-url
    ipaddr="$RET"
    if [ -z "$RET" ]; then
        ipaddr=$(get_default_route_ip)
    fi
    # Set the IP address of the interface with default route
    if [ -n "$ipaddr" ]; then
        configure_maas_default_url "$ipaddr"
        configure_maas_squid_deb_proxy "$ipaddr"
        db_set maas/default-maas-url "$ipaddr"
    fi

    #########################################################
    ################  Configure Logging  ####################
    #########################################################

    # Give appropriate permissions
    if [ ! -f /var/log/maas/maas-django.log ]; then
        touch /var/log/maas/maas-django.log
    fi
    chown -R maas:maas /var/log/maas
    chmod -R 775 /var/log/maas/oops

    # Main syslog file.
    if [ ! -f /var/log/maas/maas.log ]; then
        touch /var/log/maas/maas.log
    fi
    chown syslog:syslog /var/log/maas/maas.log

    # Create log directory base
    mkdir -p /var/log/maas/rsyslog
    chown -R syslog:syslog /var/log/maas/rsyslog
    # Make sure rsyslog reads our config
    invoke-rc.d rsyslog restart

    #########################################################
    ################### Squid-deb-proxy  ####################
    #########################################################
    # Make sure squid-deb-proxy reads our config (99-maas)
    restart_squid_deb_proxy

elif [ -n "$DEBCONF_RECONFIGURE" ]; then
    # Set the IP address of the interface with default route
    db_get maas/default-maas-url
    ipaddr="$RET"
    if [ -n "$ipaddr" ]; then
        configure_maas_default_url "$ipaddr"
        configure_maas_squid_deb_proxy "$ipaddr"
    fi

elif [ "$1" = "configure" ] && dpkg --compare-versions "$2" gt 0.1+bzr266+dfsg-0ubuntu1; then
    # If upgrading to any later package version, then upgrade db.
    invoke-rc.d apache2 stop || true

    # make sure maas http config is symlinked
    configure_region_http

    # we need to regenerate the passwords and update configs.
    db_get maas/default-maas-url
    ipaddr="$RET"
    configure_maas_default_url "$ipaddr"
    configure_maas_squid_deb_proxy "$ipaddr"
fi

invoke-rc.d apache2 restart || true

restart_squid_deb_proxy

db_stop

#DEBHELPER#