Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 1 | #!/bin/bash -xe |
| 2 | |
| 3 | export SALT_MASTER_DEPLOY_IP=10.1.0.14 |
| 4 | export APTLY_DEPLOY_IP=10.1.0.14 |
| 5 | export APTLY_DEPLOY_NETMASK=255.255.0.0 |
| 6 | export APTLY_MINION_ID=apt01.deploy-name.local |
| 7 | |
azvyagintsev | de63c76 | 2018-07-26 12:05:48 +0200 | [diff] [blame] | 8 | # Funcs ======================================================================= |
| 9 | function docker_ca_wa(){ |
| 10 | crt="/var/lib/docker/swarm/certificates/swarm-node.crt" |
| 11 | if ! $(openssl x509 -checkend 86400 -noout -in ${crt}); then |
| 12 | echo "WARNING: swarm CA not expired yet.Something wrong with docker" |
| 13 | echo "WARNING: docker CA WA not applied" |
| 14 | exit 1 |
| 15 | fi |
| 16 | echo 'WARNING: re-creating docker stack services!' |
| 17 | |
| 18 | systemctl stop docker || true |
| 19 | rm -rf /var/lib/docker/swarm/* |
| 20 | systemctl restart docker |
| 21 | sleep 5 |
| 22 | docker swarm init --advertise-addr 127.0.0.1 |
| 23 | sleep 5 |
| 24 | for c in docker aptly; do |
| 25 | pushd /etc/docker/compose/${c}/ |
| 26 | retry=5 |
| 27 | i=1 |
| 28 | while [[ $i -lt $retry ]]; do |
| 29 | docker stack deploy --compose-file docker-compose.yml ${c}; |
| 30 | ret=$?; |
| 31 | if [[ $ret -eq 0 ]]; then echo 'Stack created'; break; |
| 32 | else |
| 33 | echo "Stack creation failed, retrying in 3 seconds.." >&2; |
| 34 | sleep 3; |
| 35 | i=$(( i + 1 )); |
| 36 | fi; |
| 37 | if [[ $i -ge $retry ]]; then |
| 38 | echo "Stack creation failed!"; exit 1; |
| 39 | fi; |
| 40 | done; |
| 41 | popd |
| 42 | sleep 1 |
| 43 | done |
| 44 | } |
| 45 | |
| 46 | # Body ======================================================================== |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 47 | echo "Configuring network interfaces" |
Dmitry Stremkouski | f50ea26 | 2017-12-05 19:35:40 +0300 | [diff] [blame] | 48 | find /etc/network/interfaces.d/ -type f -delete |
| 49 | kill $(pidof /sbin/dhclient) || /bin/true |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 50 | envsubst < /root/interfaces > /etc/network/interfaces |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 51 | ip a flush dev ens3 |
Dmitry Stremkouski | b43c4ee | 2017-12-02 02:21:05 +0300 | [diff] [blame] | 52 | rm -f /var/run/network/ifstate.ens3 |
| 53 | if [[ $(grep -E '^\ *gateway\ ' /etc/network/interfaces) ]]; then |
| 54 | (ip r s | grep ^default) && ip r d default || /bin/true |
| 55 | fi; |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 56 | ifup ens3 |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 57 | |
| 58 | echo "Configuring salt" |
azvyagintsev | d453a71 | 2018-08-03 10:50:59 +0200 | [diff] [blame] | 59 | rm -f /etc/salt/pki/minion/minion_master.pub |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 60 | envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf |
Richard Felkl | 9c13fb0 | 2018-06-14 17:59:24 +0200 | [diff] [blame] | 61 | service salt-minion restart |
azvyagintsev | de63c76 | 2018-07-26 12:05:48 +0200 | [diff] [blame] | 62 | |
| 63 | # Check for failed docker-start. |
| 64 | # WA PROD-21676 |
| 65 | if [[ ! $(docker stack ls) ]] ; then |
| 66 | docker_ca_wa |
| 67 | fi |
| 68 | |
azvyagintsev | c1c6204 | 2018-09-26 11:47:49 +0300 | [diff] [blame] | 69 | # Set bootstrap-done flag for future |
| 70 | mkdir -p /var/log/mcp/ |
| 71 | touch /var/log/mcp/.bootstrap_done |