def bootstrap_pxc(args): """ Force a bootstrap on this node This action will run bootstrap-pxc on this node bootstrapping the cluster. This action should only be run after a cold start requiring a bootstrap. This action should only be run on the node with the highest sequence number as displayed in workgoup status and found in grastate.dat. If this unit has the highest sequence number and is not the juju leader node, a subsequent action run of notify-bootstrapped is required. """ try: # Force safe to bootstrap percona_utils.set_grastate_safe_to_bootstrap() # Boostrap this node percona_utils.bootstrap_pxc() percona_utils.notify_bootstrapped() except (percona_utils.GRAStateFileNotFound, OSError) as e: action_set({'output': e.output, 'return-code': e.returncode}) action_fail("The GRAState file does not exist or cannot " "be written to.") except (subprocess.CalledProcessError, Exception) as e: action_set({ 'output': e.output, 'return-code': e.returncode, 'traceback': traceback.format_exc() }) action_fail("The bootstrap-pxc failed. " "See traceback in show-action-output") action_set({ 'output': "Bootstrap succeeded. " "Wait for the other units to run update-status" }) percona_utils.assess_status(percona_utils.register_configs())
def main(): try: hooks.execute(sys.argv) except UnregisteredHookError as e: log('Unknown hook {} - skipping.'.format(e)) update_shared_db_rels() assess_status(register_configs())
def main(): try: hooks.execute(sys.argv) except UnregisteredHookError as e: log('Unknown hook {} - skipping.'.format(e)) kvstore = kv() if not kvstore.get(INITIAL_CLIENT_UPDATE_KEY, False): update_client_db_relations() assess_status(register_configs())
def resume(args): """Resume the MySQL service. @raises Exception should the service fail to start. """ resume_unit_helper(register_configs()) # NOTE(ajkavanagh) - we force a config_changed pseudo-hook to see if the # unit needs to bootstrap or restart it's services here. config_changed()
def prepare(): # Use the pause feature to stop mysql during the duration of the upgrade pause_unit_helper(register_configs()) # Set this unit to series upgrading set_unit_upgrading() # The leader will "bootstrap" with no wrep peers # Non-leaders will point only at the newly upgraded leader until the # cluster series upgrade is completed. # Set cluster_series_upgrading for the duration of the cluster series # upgrade. This will be unset with the action # complete-cluster-series-upgrade on the leader node. hosts = [] if not leader_get('cluster_series_upgrade_leader'): leader_set(cluster_series_upgrading=True) leader_set(cluster_series_upgrade_leader=get_relation_ip('cluster')) else: hosts = [leader_get('cluster_series_upgrade_leader')] # Render config render_config(hosts)
def prepare(): # Use the pause feature to stop mysql during the duration of the upgrade pause_unit_helper(register_configs()) # Set this unit to series upgrading set_unit_upgrading() # The leader will "bootstrap" with no wrep peers # Non-leaders will point only at the newly upgraded leader until the # cluster series upgrade is completed. # Set cluster_series_upgrading for the duration of the cluster series # upgrade. This will be unset with the action # complete-cluster-series-upgrade on the leader node. hosts = [] if not leader_get('cluster_series_upgrade_leader'): leader_set(cluster_series_upgrading=True) leader_set( cluster_series_upgrade_leader=get_relation_ip('cluster')) else: hosts = [leader_get('cluster_series_upgrade_leader')] # Render config render_config(hosts)
def series_upgrade(): # Set this unit to series upgrading set_unit_upgrading() # The leader will "bootstrap" with no wrep peers # Non-leaders will point only at the newly upgraded leader until the # cluster series upgrade is completed. # Set cluster_series_upgrading for the duration of the cluster series # upgrade. This will be unset with the action # complete-cluster-series-upgrade on the leader node. if (leader_get('cluster_series_upgrade_leader') == get_relation_ip( 'cluster')): hosts = [] else: hosts = [leader_get('cluster_series_upgrade_leader')] # New series after series upgrade and reboot _release = lsb_release()['DISTRIB_CODENAME'].lower() if _release == "xenial": # Guarantee /var/run/mysqld exists _dir = '/var/run/mysqld' mkdir(_dir, owner="mysql", group="mysql", perms=0o755) # Install new versions of the percona packages apt_install(determine_packages()) service_stop("mysql") if _release == "bionic": render_config(hosts) if _release == "xenial": # Move the packaged version empty DB out of the way. cmd = [ "mv", "/var/lib/percona-xtradb-cluster", "/var/lib/percona-xtradb-cluster.dpkg" ] subprocess.check_call(cmd) # Symlink the previous versions data to the new cmd = ["ln", "-s", "/var/lib/mysql", "/var/lib/percona-xtradb-cluster"] subprocess.check_call(cmd) # Start mysql temporarily with no wrep for the upgrade cmd = ["mysqld"] if _release == "bionic": cmd.append("--skip-grant-tables") cmd.append("--user=mysql") cmd.append("--wsrep-provider=none") log("Starting mysqld --wsrep-provider='none' and waiting ...") proc = subprocess.Popen(cmd, stderr=subprocess.PIPE) # Wait for the mysql socket to exist check_for_socket(MYSQL_SOCKET, exists=True) # Execute the upgrade process log("Running mysql_upgrade") cmd = ['mysql_upgrade'] if _release == "xenial": cmd.append('-p{}'.format(root_password())) subprocess.check_call(cmd) # Terminate the temporary mysql proc.terminate() # Wait for the mysql socket to be removed check_for_socket(MYSQL_SOCKET, exists=False) # Clear states clear_unit_paused() clear_unit_upgrading() if _release == "xenial": # Point at the correct my.cnf cmd = [ "update-alternatives", "--set", "my.cnf", "/etc/mysql/percona-xtradb-cluster.cnf" ] subprocess.check_call(cmd) # Render config render_config(hosts) resume_unit_helper(register_configs()) # finally update the sstuser if needed. # BUG: #1838044 _sst_password = sst_password() if _sst_password: configure_sstuser(_sst_password)
def pause(args): """Pause the MySQL service. @raises Exception should the service fail to stop. """ pause_unit_helper(register_configs())
def main(): try: hooks.execute(sys.argv) except UnregisteredHookError as e: log('Unknown hook {} - skipping.'.format(e)) assess_status(register_configs())
def series_upgrade(): # Set this unit to series upgrading set_unit_upgrading() # The leader will "bootstrap" with no wrep peers # Non-leaders will point only at the newly upgraded leader until the # cluster series upgrade is completed. # Set cluster_series_upgrading for the duration of the cluster series # upgrade. This will be unset with the action # complete-cluster-series-upgrade on the leader node. if (leader_get('cluster_series_upgrade_leader') == get_relation_ip('cluster')): hosts = [] else: hosts = [leader_get('cluster_series_upgrade_leader')] # New series after series upgrade and reboot _release = lsb_release()['DISTRIB_CODENAME'].lower() if _release == "xenial": # Guarantee /var/run/mysqld exists _dir = '/var/run/mysqld' mkdir(_dir, owner="mysql", group="mysql", perms=0o755) # Install new versions of the percona packages apt_install(determine_packages()) service_stop("mysql") if _release == "bionic": render_config(hosts) if _release == "xenial": # Move the packaged version empty DB out of the way. cmd = ["mv", "/var/lib/percona-xtradb-cluster", "/var/lib/percona-xtradb-cluster.dpkg"] subprocess.check_call(cmd) # Symlink the previous versions data to the new cmd = ["ln", "-s", "/var/lib/mysql", "/var/lib/percona-xtradb-cluster"] subprocess.check_call(cmd) # Start mysql temporarily with no wrep for the upgrade cmd = ["mysqld"] if _release == "bionic": cmd.append("--skip-grant-tables") cmd.append("--user=mysql") cmd.append("--wsrep-provider=none") log("Starting mysqld --wsrep-provider='none' and waiting ...") proc = subprocess.Popen(cmd, stderr=subprocess.PIPE) # Wait for the mysql socket to exist check_for_socket(MYSQL_SOCKET, exists=True) # Execute the upgrade process log("Running mysql_upgrade") cmd = ['mysql_upgrade'] if _release == "xenial": cmd.append('-p{}'.format(root_password())) subprocess.check_call(cmd) # Terminate the temporary mysql proc.terminate() # Wait for the mysql socket to be removed check_for_socket(MYSQL_SOCKET, exists=False) # Clear states clear_unit_paused() clear_unit_upgrading() if _release == "xenial": # Point at the correct my.cnf cmd = ["update-alternatives", "--set", "my.cnf", "/etc/mysql/percona-xtradb-cluster.cnf"] subprocess.check_call(cmd) # Render config render_config(hosts) resume_unit_helper(register_configs())