[salt-formulas] Add & enable armband formula
[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 # NOTE: Most Salt and/or reclass tools have issues traversing Docker mounts
22 # or detecting them as directories inside the container.
23 # For now, let's do a lot of copy operations to bypass this.
24 # Later, we will inject the OPNFV patched reclass model during image build.
25 rm -rf /srv/salt/reclass/classes/*
26 cp -ar /root/fuel/mcp/reclass/classes/* /srv/salt/reclass/classes
27 cp -ar /root/fuel/mcp/reclass/nodes/* /srv/salt/reclass/nodes
28 # Sensitive data should stay out of /root/fuel, which is exposed via Jenkins WS
29 cp -a /root/pod_config.yml \
30       /srv/salt/reclass/classes/cluster/all-mcp-arch-common/opnfv/pod_config.yml
31
32 # OPNFV formulas
33 prefix=/srv/salt/formula/salt-formulas
34 rm -f /root/fuel/mcp/salt-formulas/*/.git
35 cp -ar /root/fuel/mcp/salt-formulas/* ${prefix}/
36 for formula in 'armband' 'opendaylight' 'tacker'; do
37     ln -sf /root/fuel/mcp/salt-formulas/salt-formula-${formula}/* \
38            /srv/salt/env/prd/
39 done
40
41 # Re-create classes.service links that we destroyed above
42 for formula in ${prefix}/*; do
43     if [ -e "${formula}/metadata/service" ] && [[ ! $formula =~ \. ]]; then
44         ln -sf "${formula}/metadata/service" \
45                "/srv/salt/reclass/classes/service/${formula#${prefix}/salt-formula-}"
46     fi
47 done
48
49 # Create links for salt-formula-* packages to mimic git-style salt-formulas
50 for artifact in /usr/share/salt-formulas/env/_*/*; do
51     ln -sf "${artifact}" "/srv/salt/env/prd/${artifact#/usr/share/salt-formulas/env/}"
52 done
53 for artifact in /usr/share/salt-formulas/env/*; do
54     if [[ ! ${artifact} =~ ^_ ]]; then
55         ln -sf "${artifact}" "/srv/salt/env/prd/$(basename ${artifact})"
56     fi
57 done
58 for formula in /usr/share/salt-formulas/reclass/service/*; do
59     ln -sf "${formula}" "/srv/salt/reclass/classes/service/$(basename ${formula})"
60 done
61
62 # Tini init system resembles upstart very much, but needs a little adjustment
63 sed -i -e "s|return 'start/running' in |return 'is running' in |" \
64        -e "s|ret = _default_runlevel|return _default_runlevel|" \
65     /usr/lib/python2.7/dist-packages/salt/modules/upstart.py
66
67 # Remove broken symlinks in /srv/salt, silences recurring warnings
68 find -L /srv/salt /srv/salt/env/prd/_* -maxdepth 1 -type l -delete
69
70 # Fix up any permissions after above file shuffling
71 sudo chown root:root -R /srv/salt
72
73 service ssh start
74 service salt-minion start
75
76 if [[ $# -lt 1 ]] || [[ "$1" == "--"* ]]; then
77     exec /usr/bin/salt-master --log-file-level=quiet --log-level=info "$@"
78 else
79     exec "$@"
80 fi