docker-compose: Align hosts with hostname
[fuel.git] / mcp / scripts / docker-compose / files / entrypoint.sh
1 #!/bin/bash -e
2 ##############################################################################
3 # Copyright (c) 2018 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
10 mkdir -p /etc/salt/{master.d,minion.d,proxy.d}
11
12 if [ ! -z "$SALT_EXT_PILLAR" ]; then
13     cp -avr "/tmp/${SALT_EXT_PILLAR}.conf" /etc/salt/master.d/
14 fi
15
16 if [ ! -f /home/ubuntu/.ssh/authorized_keys ]; then
17     install -D -o ubuntu /root/fuel/mcp/scripts/mcp.rsa.pub \
18                          /home/ubuntu/.ssh/authorized_keys
19     mkdir -p /root/.ssh/
20     echo 'User ubuntu' > /root/.ssh/config
21     echo 'IdentityFile /root/fuel/mcp/scripts/mcp.rsa' >> /root/.ssh/config
22 fi
23
24 # salt state does not properly configure file_roots in master.conf, hard set it
25 cp -a /root/fuel/mcp/scripts/docker-compose/files/opnfv_master.conf \
26       /etc/salt/master.d/opnfv_master.conf
27 echo -e 'master: localhost\nmine_interval: 15' > /etc/salt/minion.d/opnfv_slave.conf
28
29 # NOTE: Most Salt and/or reclass tools have issues traversing Docker mounts
30 # or detecting them as directories inside the container.
31 # For now, let's do a lot of copy operations to bypass this.
32 # Later, we will inject the OPNFV patched reclass model during image build.
33 rm -rf /srv/salt/reclass/classes/*
34 cp -ar /root/fuel/mcp/reclass/classes/* /srv/salt/reclass/classes
35 cp -ar /root/fuel/mcp/reclass/nodes/* /srv/salt/reclass/nodes
36 # Sensitive data should stay out of /root/fuel, which is exposed via Jenkins WS
37 cp -a /root/pod_config.yml \
38       /srv/salt/reclass/classes/cluster/all-mcp-arch-common/opnfv/pod_config.yml
39
40 # OPNFV formulas
41 prefix=/srv/salt/formula/salt-formulas
42 rm -f /root/fuel/mcp/salt-formulas/*/.git
43 cp -ar /root/fuel/mcp/salt-formulas/* ${prefix}/
44 for formula in 'armband' 'opendaylight' 'tacker' 'quagga'; do
45     ln -sf /root/fuel/mcp/salt-formulas/salt-formula-${formula}/* \
46            /srv/salt/env/prd/
47 done
48
49 # Re-create classes.service links that we destroyed above
50 for formula in ${prefix}/*; do
51     if [ -e "${formula}/metadata/service" ] && [[ ! $formula =~ \. ]]; then
52         ln -sf "${formula}/metadata/service" \
53                "/srv/salt/reclass/classes/service/${formula#${prefix}/salt-formula-}"
54     fi
55 done
56
57 # Create links for salt-formula-* packages to mimic git-style salt-formulas
58 for artifact in /usr/share/salt-formulas/env/_*/*; do
59     ln -sf "${artifact}" "/srv/salt/env/prd/${artifact#/usr/share/salt-formulas/env/}"
60 done
61 for artifact in /usr/share/salt-formulas/env/*; do
62     if [[ ! ${artifact} =~ ^_ ]]; then
63         ln -sf "${artifact}" "/srv/salt/env/prd/$(basename ${artifact})"
64     fi
65 done
66 for formula in /usr/share/salt-formulas/reclass/service/*; do
67     ln -sf "${formula}" "/srv/salt/reclass/classes/service/$(basename ${formula})"
68 done
69
70 # Temporary link rocky configs to stein
71 for f in /srv/salt/env/prd/*/files/rocky; do
72     if [ ! -d "$f/../stein" ]; then
73         ln -sf "$f" "$f/../stein"
74     fi
75 done
76
77 # Tini init system resembles upstart very much, but needs a little adjustment
78 sed -i -e "s|return 'start/running' in |return 'is running' in |" \
79        -e "s|ret = _default_runlevel|return _default_runlevel|" \
80     /usr/lib/python2.7/dist-packages/salt/modules/upstart.py
81
82 # Workaround for: https://github.com/salt-formulas/reclass/issues/77
83 sed -i -e 's|\(ignore_overwritten_missing_references\)defaults.|\1|' \
84     /usr/local/lib/python2.7/dist-packages/reclass/settings.py
85
86 # Remove broken symlinks in /srv/salt, silences recurring warnings
87 find -L /srv/salt /srv/salt/env/prd/_* -maxdepth 1 -type l -delete
88
89 # Fix up any permissions after above file shuffling
90 chown root:root -R /srv/salt
91
92 # Docker-ce 19.x+ workaround for broken domainname setup
93 # shellcheck source=/dev/null
94 source /root/fuel/mcp/scripts/xdf_data.sh
95 hostname -b "cfg01.${CLUSTER_DOMAIN}"
96
97 service ssh start
98 service salt-minion start
99
100 if [[ $# -lt 1 ]] || [[ "$1" == "--"* ]]; then
101     exec /usr/bin/salt-master --log-file-level=quiet --log-level=info "$@"
102 else
103     exec "$@"
104 fi