#!/usr/bin/env python3 # Author: Maurice Makaay, XS4ALL # {{ ansible_managed }} # # This script is used to find out what the latest recorded transaction # on this host is. It is used by the galera cluster bootstrapping # script (which is available in /root/bootstrap_galera_cluster on the # ansible host) to find out in what order to start the nodes in case # of an unclean full shutdown of the cluster. # # DO NOT RUN FOR FUN! This script will bring down the mysql service # when it is not already down. # import subprocess import re import json from sys import exit subprocess.check_output(["service", "mysql", "stop"]) result = subprocess.check_output( ['mysqld', '--wsrep-recover'], stderr= subprocess.STDOUT) info = re.compile('WSREP: Recovered position: (.+)\s*$') for line in result.split("\n"): result = info.search(line) if result is not None: print(json.dumps(result.group(1))) exit(0) print(json.dumps(None))