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
|
#!/bin/sh -e
. /usr/share/debconf/confmodule
db_version 2.0
create_log_dir() {
# create log dir
if [ ! -d /var/lib/maas ]; then
mkdir -p /var/lib/maas
fi
if [ ! -d /var/log/maas/oops ]; then
mkdir -p /var/log/maas/oops
fi
# Give appropriate permissions
chown -R maas:maas /var/lib/maas/
chown -R maas:maas /var/log/maas
chmod -R 775 /var/log/maas/oops
}
configure_maas_tgt(){
# Set up iSCSI: add maas.conf to tgt conf.d.
local tgtcfg="/etc/tgt/targets.conf"
[ -d /etc/tgt/conf.d/ ] ||
echo "Warning! $tgtcfg did not exist" 1>&2;
mkdir -p /etc/tgt/conf.d/ /var/lib/maas/ephemeral/
ln -sf /var/lib/maas/ephemeral/tgt.conf /etc/tgt/conf.d/maas.conf
}
extract_cluster_uuid(){
# Extract ClUSTER_UUID setting from config file $1. This will work
# both the cluster celery config (which is python) and the cluster
# config (which is shell).
sed -n -e "s/^CLUSTER_UUID *= *[\"']\([^\"']*\).*/\1/p" "$1"
}
configure_cluster_uuid(){
# The cluster uuid goes into maas_cluster.conf, but we also still
# keep a copy in maas_local_celeryconfig_cluster.py (hopefully just
# temporarily). If an old uuid is configured, we replicate that to
# maas_cluster.conf; otherwise, we want to generate one.
local uuid
if [ -n "$(extract_cluster_uuid /etc/maas/maas_cluster.conf)" ]; then
# UUID is already set up. Wonderful.
return
fi
# Look for a UUID stored in the old location.
uuid="$(extract_cluster_uuid /etc/maas/maas_local_celeryconfig_cluster.py)"
if [ -z "$uuid" ]; then
# No UUID at all yet. Generate one, and insert it into its
# placeholder in the old config location.
uuid="$(uuidgen)"
sed -i "s|^CLUSTER_UUID = None$|CLUSTER_UUID = '$uuid'|" \
/etc/maas/maas_local_celeryconfig_cluster.py
fi
# Either way, at this point we have a uuid, and it is configured in
# the old config location.
#
# Write it to maas_cluster.conf as well. There is no initial
# placeholder in this file, so just append the setting.
echo "CLUSTER_UUID=\"$uuid\"" >>/etc/maas/maas_cluster.conf
}
if [ "$1" = "configure" ] && [ -z "$2" ]; then
# logging
create_log_dir
configure_maas_tgt
fi
if ([ "$1" = "configure" ] && [ -z "$2" ]) || [ "$1" = "reconfigure" ] || [ -n "$DEBCONF_RECONFIGURE" ]; then
if dpkg --compare-versions "$2" lt 0.1+bzr1239+dfsg-0ubuntu1; then
create_log_dir
fi
# Get the MAAS_URL on configure/reconfigure and write it to the conf files.
db_get maas-cluster-controller/maas-url || true
if [ -n "$RET" ]; then
sed -i "s|MAAS_URL=.*|MAAS_URL="$RET"|" /etc/maas/maas_cluster.conf
# Extract the hostname part.
HOSTPART=$(echo $RET|awk '{ split($0,array,"/")} END{print array[3] }')
# And substitute it in-place in pserv.yaml on an indented, non-commented
# line.
sed -ri "s|^([[:space:]]+)(#+[[:space:]]*)?(generator:[[:space:]]+https?://)[^:/]+|\1\3$HOSTPART|" /etc/maas/pserv.yaml
fi
fi
if [ "$1" = "configure" ]; then
# These config files may contain a private cluster UUID. Only maas
# can read them; only root can write them
chown root:maas \
/etc/maas/maas_local_celeryconfig_cluster.py \
/etc/maas/maas_cluster.conf
chmod 0640 \
/etc/maas/maas_local_celeryconfig_cluster.py \
/etc/maas/maas_cluster.conf
configure_cluster_uuid
fi
#DEBHELPER#
exit 0
|