def stop_control_plane_services(): """ Stop the control plane services """ for service in services: if is_service_expected_to_start(service): systemd_service_name = "microk8s.daemon-{}".format(service) print("Stopping {}".format(systemd_service_name), flush=True) cmd = "snapctl stop {}".format(systemd_service_name) subprocess.check_output(cmd.split()) set_service_expected_to_start(service, False)
def start_control_plane_services(): """ Start the control plane services """ for service in services: if not is_service_expected_to_start(service): systemd_service_name = "eks.daemon-{}".format(service) print("Starting {}".format(systemd_service_name), flush=True) cmd = "snapctl start {}".format(systemd_service_name) subprocess.check_output((cmd.split())) set_service_expected_to_start(service, True)
# Check for changes every 10 seconds sleep(10) try: if microk8s_group_exists(): set_dqlite_file_permissions() # We will not attempt to stop services if: # 1. The cluster is not ready # 2. We are not on an HA cluster # 3. The control plane kicker is disabled # 4. dqlite has less than 4 nodes if ( not is_cluster_ready() or not is_ha_enabled() or not is_service_expected_to_start('control-plane-kicker') ): start_control_plane_services() continue info = get_dqlite_info() if len(info) <= 3: start_control_plane_services() continue local_ips = [] for interface in netifaces.interfaces(): if netifaces.AF_INET not in netifaces.ifaddresses(interface): continue for link in netifaces.ifaddresses(interface)[netifaces.AF_INET]: local_ips.append(link['addr'])