[maas] Fix permissions on (partial) redeploy
[fuel.git] / mcp / scripts / docker-compose / files / entrypoint_maas.sh.j2
1 #!/bin/bash -e
2 ##############################################################################
3 # Copyright (c) 2019 Mirantis Inc., Enea AB and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 {%- import 'net_map.j2' as nm with context %}
10 {%- set pxebr_addr = nm.net_admin | ipnet_hostaddr(nm.start_ip[nm.net_admin] + nm.net_admin_hosts.index('opnfv_infra_maas_node01_deploy_address') +1) %}
11 if [ ! -e /var/lib/postgresql/*/main ]; then
12     cp -ar /var/lib/opnfv/{postgresql,maas} /var/lib/
13     cp -ar /var/lib/opnfv/etc/maas /etc/
14 fi
15 chown -R maas:maas /var/lib/maas /etc/maas
16 chown -R postgres:postgres /var/lib/postgresql
17 chown -R proxy:proxy /var/spool/maas-proxy
18
19 if [ ! -f /etc/sysctl.d/99-salt.conf ]; then
20     echo 'net.ipv4.ip_forward = 1' > /etc/sysctl.d/99-salt.conf
21 fi
22
23 cat <<-EOF | tee /etc/resolv.conf
24 {%- for server in nm.dns_public %}
25 nameserver {{ server }}
26 {%- endfor %}
27 EOF
28
29 cat <<-EOF | tee /etc/salt/minion.d/opnfv.conf
30 id: mas01.{{ conf.cluster.domain }}
31 master: {{ conf.SALT_MASTER }}
32 grains:
33   virtual_subtype: Docker_
34 EOF
35 rm -f /etc/salt/minion.d/99-master-address.conf
36
37 # Work around MaaS issues with PXE/admin using jumbo frames
38 MAAS_MTU_SERVICE="/etc/systemd/system/maas-mtu.service"
39 cat <<-EOF | tee "${MAAS_MTU_SERVICE}"
40 [Unit]
41 Requires=network-online.target
42 After=network-online.target
43 [Service]
44 ExecStart=/bin/sh -ec '\
45   /sbin/ifconfig $(/sbin/ip addr | /bin/grep -Po "{{ pxebr_addr }}.* \K(.*)") mtu 1500'
46 EOF
47 ln -sf "${MAAS_MTU_SERVICE}" "/etc/systemd/system/multi-user.target.wants/"
48
49 # Configure mass-region-controller if not already done previously
50 [ ! -e /var/lib/maas/secret ] || exit 0
51 MAAS_FIXUP_SERVICE="/etc/systemd/system/maas-fixup.service"
52 cat <<-EOF | tee "${MAAS_FIXUP_SERVICE}"
53 [Unit]
54 After=postgresql.service
55 [Service]
56 ExecStart=/bin/sh -ec '\
57   echo "debconf debconf/frontend select Noninteractive" | debconf-set-selections && \
58   /var/lib/dpkg/info/maas-region-controller.config configure && \
59   /var/lib/dpkg/info/maas-region-controller.postinst configure'
60 EOF
61 ln -sf "${MAAS_FIXUP_SERVICE}" "/etc/systemd/system/multi-user.target.wants/"
62 rm "/usr/sbin/policy-rc.d"