def render_config_restart_on_changed(hosts, bootstrap=False): """Render mysql config and restart mysql service if file changes as a result. If bootstrap is True we do a bootstrap-pxc in order to bootstrap the percona cluster. This should only be performed once at cluster creation time. If percona is already bootstrapped we can get away with just ensuring that it is started so long as the new node to be added is guaranteed to have been restarted so as to apply the new config. """ config_file = resolve_cnf_file() pre_hash = file_hash(config_file) render_config(hosts) create_binlogs_directory() update_db_rels = False if file_hash(config_file) != pre_hash or bootstrap: if bootstrap: bootstrap_pxc() # NOTE(dosaboy): this will not actually do anything if no cluster # relation id exists yet. notify_bootstrapped() update_db_rels = True else: # NOTE(jamespage): # if mysql@bootstrap is running, then the native # bootstrap systemd service was used to start this # instance, and it was the initial seed unit # stop the bootstap version before restarting normal mysqld if service_running('mysql@bootstrap'): service_stop('mysql@bootstrap') attempts = 0 max_retries = 5 cluster_wait() while not service_restart('mysql'): if attempts == max_retries: raise Exception("Failed to start mysql (max retries " "reached)") log("Failed to start mysql - retrying per distributed wait", WARNING) attempts += 1 cluster_wait() # If we get here we assume prior actions have succeeded to always # this unit is marked as seeded so that subsequent calls don't result # in a restart. mark_seeded() if update_db_rels: update_client_db_relations() else: log("Config file '{}' unchanged".format(config_file), level=DEBUG)
def render_config_restart_on_changed(clustered, hosts, bootstrap=False): """Render mysql config and restart mysql service if file changes as a result. If bootstrap is True we do a bootstrap-pxc in order to bootstrap the percona cluster. This should only be performed once at cluster creation time. If percona is already bootstrapped we can get away with just ensuring that it is started so long as the new node to be added is guaranteed to have been restarted so as to apply the new config. """ config_file = resolve_cnf_file() pre_hash = file_hash(config_file) render_config(clustered, hosts) create_binlogs_directory() update_db_rels = False if file_hash(config_file) != pre_hash or bootstrap: if bootstrap: bootstrap_pxc() # NOTE(dosaboy): this will not actually do anything if no cluster # relation id exists yet. notify_bootstrapped() update_db_rels = True else: delay = 1 attempts = 0 max_retries = 5 # NOTE(dosaboy): avoid unnecessary restarts. Once mysql is started # it needn't be restarted when new units join the cluster since the # new units will join and apply their own config. if not seeded(): action = service_restart else: action = service_start while not action('mysql'): if attempts == max_retries: raise Exception("Failed to start mysql (max retries " "reached)") log("Failed to start mysql - retrying in %ss" % (delay), WARNING) time.sleep(delay) delay += 2 attempts += 1 # If we get here we assume prior actions have succeeded to always # this unit is marked as seeded so that subsequent calls don't result # in a restart. mark_seeded() if update_db_rels: update_shared_db_rels() else: log("Config file '{}' unchanged".format(config_file), level=DEBUG)
def render_config_restart_on_changed(clustered, hosts, bootstrap=False): """Render mysql config and restart mysql service if file changes as a result. If bootstrap is True we do a bootstrap-pxc in order to bootstrap the percona cluster. This should only be performed once at cluster creation time. If percona is already bootstrapped we can get away with just ensuring that it is started so long as the new node to be added is guaranteed to have been restarted so as to apply the new config. """ pre_hash = file_hash(resolve_cnf_file()) render_config(clustered, hosts) create_binlogs_directory() update_db_rels = False if file_hash(resolve_cnf_file()) != pre_hash or bootstrap: if bootstrap: service('stop', 'mysql') service('bootstrap-pxc', 'mysql') # NOTE(dosaboy): this will not actually do anything if no cluster # relation id exists yet. notify_bootstrapped() update_db_rels = True else: delay = 1 attempts = 0 max_retries = 5 # NOTE(dosaboy): avoid unnecessary restarts. Once mysql is started # it needn't be restarted when new units join the cluster since the # new units will join and apply their own config. if not seeded(): action = service_restart else: action = service_start while not action('mysql'): if attempts == max_retries: raise Exception("Failed to start mysql (max retries " "reached)") log("Failed to start mysql - retrying in %ss" % (delay), WARNING) time.sleep(delay) delay += 2 attempts += 1 # If we get here we assume prior actions have succeeded to always # this unit is marked as seeded so that subsequent calls don't result # in a restart. mark_seeded() if update_db_rels: update_shared_db_rels() else: log("Config file '%s' unchanged", level=DEBUG)