2023-02-13 09:44:56 +00:00
|
|
|
#!/bin/bash
|
|
|
|
PATH="${PATH}:/usr/local/bin"
|
|
|
|
restarted="false"
|
2023-03-24 13:36:07 +00:00
|
|
|
domain=$(hostname -d)
|
|
|
|
prefix="intern-db"
|
|
|
|
if [[ ${domain} =~ ^drive ]]; then
|
|
|
|
prefix="multinode-db"
|
|
|
|
fi
|
|
|
|
|
2023-02-13 09:44:56 +00:00
|
|
|
for index in 1 2 3; do
|
2023-03-24 13:36:07 +00:00
|
|
|
db_ip=$(host "${prefix}${index}.${domain}" | awk '/has address/ {print $NF}')
|
2023-02-13 09:44:56 +00:00
|
|
|
result=$(proxysql "select * from main.mysql_servers where hostname = '${db_ip}' and hostgroup_id = 10")
|
|
|
|
if [[ -z ${result} ]]; then
|
|
|
|
query="INSERT INTO main.mysql_servers (hostgroup_id, hostname, max_connections, comment) VALUES( 10, '${db_ip}', 100, 'Inserted by script at $(date)')"
|
|
|
|
proxysql "${query}"
|
|
|
|
restarted="true"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [[ "${restarted}" == "true" ]]; then
|
|
|
|
systemctl restart sunet-proxysql.service
|
|
|
|
fi
|