summaryrefslogtreecommitdiff
path: root/salt/openbook/database/files/run.sh
blob: f9966ca8d370d9cf4bf0e04df8d347950941b6e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash

# find other running nodes
other_nodes_found=1
for i in $(echo "{% raw %}{{ openbook_gcomm_addresses }}{% endraw %}" | sed -e 's|,| |g'); do
    if [ "${i}" != "{% raw %}{{ ansible_default_ipv4.address }}{% endraw %}" ]; then
        nc ${i} 4567 </dev/null >/dev/null
        if [ "${?}" == "0" ]; then
            other_nodes_found=0
        fi
    fi
done

# bootstrap or cluster join depending on whether other nodes were found
if [ "${other_nodes_found}" == "0" ]; then
    mysql_args=""
else
    mysql_args="--wsrep-new-cluster"
fi

docker run -d --net=host -p 3306:3306 -p 4444:4444 -p 4567:4567 -p 4567:4567/udp -p 4568:4568 -p 9200:9200 -v {{ pillar["database"]["dirs"]["etc_openbook_database"]["name"] }}:/etc/mysql -v {{ pillar["database"]["dirs"]["var_lib_mysql"]["name"] }}:/var/lib/mysql -v {{ pillar["database"]["dirs"]["var_log_mysql"]["name"] }}:/var/log/mysql --name {{ pillar["database"]["container_name"] }} {{ pillar["registry"]["url"] }}/{{ pillar["database"]["image_name"] }} ${mysql_args}

exit 0