blob: 387c16ba001e49490a40142eb9c0223c1003fe54 [file] [log] [blame]
Richard Felkl4c4829d2017-11-11 00:12:20 +01001#!/bin/bash -xe
2
3export SALT_MASTER_DEPLOY_IP=10.1.0.14
4export APTLY_DEPLOY_IP=10.1.0.14
5export APTLY_DEPLOY_NETMASK=255.255.0.0
6export APTLY_MINION_ID=apt01.deploy-name.local
7
azvyagintsevde63c762018-07-26 12:05:48 +02008# Funcs =======================================================================
9function 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 Felkl4c4829d2017-11-11 00:12:20 +010047echo "Configuring network interfaces"
Dmitry Stremkouskif50ea262017-12-05 19:35:40 +030048find /etc/network/interfaces.d/ -type f -delete
49kill $(pidof /sbin/dhclient) || /bin/true
Richard Felkl4c4829d2017-11-11 00:12:20 +010050envsubst < /root/interfaces > /etc/network/interfaces
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +030051ip a flush dev ens3
Dmitry Stremkouskib43c4ee2017-12-02 02:21:05 +030052rm -f /var/run/network/ifstate.ens3
53if [[ $(grep -E '^\ *gateway\ ' /etc/network/interfaces) ]]; then
54(ip r s | grep ^default) && ip r d default || /bin/true
55fi;
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +030056ifup ens3
Richard Felkl4c4829d2017-11-11 00:12:20 +010057
58echo "Configuring salt"
azvyagintsevd453a712018-08-03 10:50:59 +020059rm -f /etc/salt/pki/minion/minion_master.pub
Richard Felkl4c4829d2017-11-11 00:12:20 +010060envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
Richard Felkl9c13fb02018-06-14 17:59:24 +020061service salt-minion restart
azvyagintsevde63c762018-07-26 12:05:48 +020062
63# Check for failed docker-start.
64# WA PROD-21676
65if [[ ! $(docker stack ls) ]] ; then
66 docker_ca_wa
67fi
68
azvyagintsevc1c62042018-09-26 11:47:49 +030069# Set bootstrap-done flag for future
70mkdir -p /var/log/mcp/
71touch /var/log/mcp/.bootstrap_done