def main(): local_services = get_marathon_services_running_here_for_nerve( cluster=None, soa_dir=DEFAULT_SOA_DIR, ) paasta_print(json.dumps(local_services)) sys.exit(0)
def main(argv=None): args = parse_args(argv) soa_dir = args.soa_dir service_dump = get_marathon_services_running_here_for_nerve( cluster=None, soa_dir=soa_dir) + get_puppet_services_running_here_for_nerve( soa_dir=soa_dir) paasta_print(json.dumps(service_dump)) sys.exit(0)
def main() -> None: opts = parse_args(sys.argv[1:]) new_config = generate_configuration( paasta_services=( get_marathon_services_running_here_for_nerve( # type: ignore cluster=None, soa_dir=DEFAULT_SOA_DIR, ) + get_paasta_native_services_running_here_for_nerve( cluster=None, soa_dir=DEFAULT_SOA_DIR, ) + get_kubernetes_services_running_here_for_nerve( cluster=None, soa_dir=DEFAULT_SOA_DIR, )), puppet_services=get_puppet_services_running_here_for_nerve( soa_dir=DEFAULT_SOA_DIR, ), heartbeat_path=opts.heartbeat_path, hacheck_port=opts.hacheck_port, weight=opts.weight, zk_topology_dir=opts.zk_topology_dir, zk_location_type=opts.zk_location_type, zk_cluster_type=opts.zk_cluster_type, labels_dir=opts.labels_dir, envoy_listeners=get_envoy_listeners(opts.envoy_admin_port), ) # Must use os.rename on files in the same filesystem to ensure that # config is swapped atomically, so we need to create the temp file in # the same directory as the config file new_config_path = '{0}.tmp'.format(opts.nerve_config_path) with open(new_config_path, 'w') as fp: json.dump(new_config, fp, sort_keys=True, indent=4, separators=(',', ': ')) # Match the permissions that puppet expects os.chmod(new_config_path, 0o644) # Restart/reload nerve if the config files differ # Always force a restart if the heartbeat file is old should_reload = not filecmp.cmp(new_config_path, opts.nerve_config_path) should_restart = file_not_modified_since(opts.heartbeat_path, opts.heartbeat_threshold) # Always swap new config file into place, even if we're not going to # restart nerve. Our monitoring system checks the opts.nerve_config_path # file age to ensure that this script is functioning correctly. try: # Verify the new config is _valid_ command = [opts.nerve_executable_path] command.extend(['-c', new_config_path, '-k']) subprocess.check_call(command) # Move the config over shutil.move(new_config_path, opts.nerve_config_path) except subprocess.CalledProcessError: # Nerve config is invalid!, bail out **without restarting** # so staleness monitoring can trigger and alert us of a problem return # If we can reload with SIGHUP, use that, otherwise use the normal # graceful method if should_reload and opts.reload_with_sighup: try: with open(opts.nerve_pid_path) as f: pid = int(f.read().strip()) os.kill(pid, signal.SIGHUP) except (OSError, ValueError, IOError): # invalid pid file, time to restart should_restart = True else: # Always try to stop the backup process subprocess.call(opts.nerve_backup_command + ['stop']) else: should_restart |= should_reload if should_restart: # Try to do a graceful restart by starting up the backup nerve # prior to restarting the main nerve. Then once the main nerve # is restarted, stop the backup nerve. try: subprocess.call(opts.nerve_backup_command + ['start']) time.sleep(opts.nerve_registration_delay_s) subprocess.check_call(opts.nerve_command + ['stop']) subprocess.check_call(opts.nerve_command + ['start']) time.sleep(opts.nerve_registration_delay_s) finally: # Always try to stop the backup process subprocess.call(opts.nerve_backup_command + ['stop'])
def main(): opts = parse_args(sys.argv[1:]) new_config = generate_configuration( classic_services=get_classic_services_running_here_for_nerve( soa_dir=DEFAULT_SOA_DIR, ), paasta_services=get_marathon_services_running_here_for_nerve( cluster=None, soa_dir=DEFAULT_SOA_DIR, ), heartbeat_path=opts.heartbeat_path, hacheck_port=opts.hacheck_port, weight=opts.weight, zk_topology_dir=opts.zk_topology_dir, zk_location_type=opts.zk_location_type, zk_cluster_type=opts.zk_cluster_type, ) # Must use os.rename on files in the same filesystem to ensure that # config is swapped atomically, so we need to create the temp file in # the same directory as the config file new_config_path = '{0}.tmp'.format(opts.nerve_config_path) with open(new_config_path, 'w') as fp: json.dump(new_config, fp, sort_keys=True, indent=4, separators=(',', ': ')) # Match the permissions that puppet expects os.chmod(new_config_path, 0644) # Restart/reload nerve if the config files differ # Always force a restart if the heartbeat file is old should_reload = not filecmp.cmp(new_config_path, opts.nerve_config_path) should_restart = file_not_modified_since(opts.heartbeat_path, opts.heartbeat_threshold) # Always swap new config file into place, even if we're not going to # restart nerve. Our monitoring system checks the opts.nerve_config_path # file age to ensure that this script is functioning correctly. try: # Verify the new config is _valid_ command = [opts.nerve_executable_path] command.extend(['-c', new_config_path, '-k']) subprocess.check_call(command) # Move the config over shutil.move(new_config_path, opts.nerve_config_path) except subprocess.CalledProcessError: # Nerve config is invalid!, bail out **without restarting** # so staleness monitoring can trigger and alert us of a problem return # If we can reload with SIGHUP, use that, otherwise use the normal # graceful method if should_reload and opts.reload_with_sighup: try: with open(opts.nerve_pid_path) as f: pid = int(f.read().strip()) os.kill(pid, signal.SIGHUP) except (OSError, ValueError, IOError): # invalid pid file, time to restart should_restart = True else: # Always try to stop the backup process subprocess.call(opts.nerve_backup_command + ['stop']) else: should_restart |= should_reload if should_restart: # Try to do a graceful restart by starting up the backup nerve # prior to restarting the main nerve. Then once the main nerve # is restarted, stop the backup nerve. try: subprocess.call(opts.nerve_backup_command + ['start']) time.sleep(opts.nerve_registration_delay_s) subprocess.check_call(opts.nerve_command + ['stop']) subprocess.check_call(opts.nerve_command + ['start']) time.sleep(opts.nerve_registration_delay_s) finally: # Always try to stop the backup process subprocess.call(opts.nerve_backup_command + ['stop'])