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