Page MenuHomePhabricator
Paste P23031

(An Untitled Masterwork)
ActivePublic

Authored by Ladsgroup on Mar 24 2022, 5:20 PM.
Tags
None
Referenced Files
F35022467: raw-paste-data.txt
Mar 24 2022, 5:21 PM
F35022466: raw-paste-data.txt
Mar 24 2022, 5:20 PM
Subscribers
None
from auto_schema.replica_set import ReplicaSet
from auto_schema.bash import run
from auto_schema.host import Host
import sys
import re
section = 's4'
ticket = 'T302950'
replicas = ['db2110']
def get_port(section):
return '331' + re.findall(r'(\d+)', section)[0]
replica_set = ReplicaSet(replicas, section)
for host in replica_set.replicas:
sqldata_paths = host.run_on_host('ls /srv/').replace('sqldata.bak', '')
instances = None
if 'sqldata.' in sqldata_paths:
instances = re.findall(r'sqldata\.(\D+?\d+)', sqldata_paths)
if '--after' in sys.argv:
host.run_on_host('chown -R mysql. /srv/* ; systemctl set-environment MYSQLD_OPTS="--skip-slave-start"')
if not instances:
host.run_on_host('systemctl start mariadb ; mysql_upgrade')
host.run_sql('start slave;')
host.run_on_host('systemctl restart prometheus-mysqld-exporter.service')
res = input('Does it look good?')
if res.lower() in ['y', 'yes', 'si']:
host.repool(ticket)
else:
for instance in instances:
host.run_on_host('systemctl start mariadb@{} ; mysql_upgrade -S /run/mysqld/mysqld.{}.sock'.format(instance, instance))
host_section = Host(host.host + ':' + get_port(instance), instance)
host_section.run_sql('start slave;')
host.run_on_host('systemctl restart prometheus-mysqld-exporter@{}.service'.format(instance))
res = input('Does it look good?')
if res.lower() in ['y', 'yes', 'si']:
host_section.repool(ticket)
continue
replicas_to_downtime = []
if not instances and host.has_replicas():
replicas_to_downtime = host.get_replicas(recursive=True)
host.downtime('24', replicas_to_downtime)
if instances:
panic = False
for instance in instances:
host_section = Host(host.host + ':' + get_port(instance), instance)
depooled = host_section.depool(ticket)
if not depooled:
panic = True
break
host_section.run_sql('stop slave;')
host.run_on_host('service mariadb@{} stop'.format(instance))
if panic:
continue
else:
depooled = host.depool(ticket)
if not depooled:
continue
host.run_sql('stop slave;')
host.run_on_host('service mariadb stop')
host.run_on_host('umount /srv; swapoff -a')
print('sudo cookbook sre.hosts.reimage --os bullseye {} -t {}'.format(host.host, ticket))