0199c3901014c100ef2c9c8e56cae3835ea537d1
[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 # Tini init system resembles upstart very much, but needs a little adjustment
73 sed -i -e "s|return 'start/running' in |return 'is running' in |" \
74        -e "s|ret = _default_runlevel|return _default_runlevel|" \
75     /usr/lib/python2.7/dist-packages/salt/modules/upstart.py
76
77 # Workaround for: https://github.com/salt-formulas/reclass/issues/77
78 sed -i -e 's|\(ignore_overwritten_missing_references\)defaults.|\1|' \
79     /usr/local/lib/python2.7/dist-packages/reclass/settings.py
80
81 # Remove broken symlinks in /srv/salt, silences recurring warnings
82 find -L /srv/salt /srv/salt/env/prd/_* -maxdepth 1 -type l -delete
83
84 # Fix up any permissions after above file shuffling
85 chown root:root -R /srv/salt
86
87 service ssh start
88 service salt-minion start
89
90 if [[ $# -lt 1 ]] || [[ "$1" == "--"* ]]; then
91     exec /usr/bin/salt-master --log-file-level=quiet --log-level=info "$@"
92 else
93     exec "$@"
94 fi