/// <summary> /// Open file descriptor (SD_LISTEN_FDS_START) initialized by systemd socket-based activation logic if available. /// Specify callback to configure endpoint-specific settings. /// </summary> /// <returns> /// The <see cref="KestrelServerOptions"/>. /// </returns> public static KestrelServerOptions UseSystemd(this KestrelServerOptions options, Action <ListenOptions> configure) { if (string.Equals(Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture), Environment.GetEnvironmentVariable(ListenPidEnvVar), StringComparison.Ordinal)) { options.ListenHandle(SdListenFdsStart, configure); } return(options); }
/// <summary> /// Open file descriptors (starting from SD_LISTEN_FDS_START) initialized by systemd socket-based activation logic if available. /// Specify callback to configure endpoint-specific settings. /// </summary> /// <returns> /// The <see cref="KestrelServerOptions"/>. /// </returns> public static KestrelServerOptions UseSystemd(this KestrelServerOptions options, Action <ListenOptions> configure) { if (string.Equals(Environment.ProcessId.ToString(CultureInfo.InvariantCulture), Environment.GetEnvironmentVariable(ListenPidEnvVar), StringComparison.Ordinal)) { // This matches sd_listen_fds behavior that requires %LISTEN_FDS% to be present and in range [1;INT_MAX-SD_LISTEN_FDS_START] if (int.TryParse(Environment.GetEnvironmentVariable(ListenFdsEnvVar), NumberStyles.None, NumberFormatInfo.InvariantInfo, out var listenFds) && listenFds > 0 && listenFds <= int.MaxValue - SdListenFdsStart) { for (var handle = SdListenFdsStart; handle < SdListenFdsStart + listenFds; ++handle) { options.ListenHandle((ulong)handle, configure); } } } return(options); }