Update
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
@@ -114,26 +113,22 @@ public static class ApiBootstrap
|
|||||||
Environment.GetEnvironmentVariable("COMPUTERNAME") ?? // Windows hostname
|
Environment.GetEnvironmentVariable("COMPUTERNAME") ?? // Windows hostname
|
||||||
"localhost";
|
"localhost";
|
||||||
|
|
||||||
// Parse the hostname to IP address for Orleans
|
// For Docker containers on the same server, use localhost binding with unique ports
|
||||||
IPAddress advertisedIP;
|
IPAddress bindIP = IPAddress.Any; // Bind to all interfaces (0.0.0.0)
|
||||||
if (IPAddress.TryParse(hostname, out advertisedIP))
|
IPAddress advertisedIP = IPAddress.Loopback; // Advertise as localhost for same-server clustering
|
||||||
|
|
||||||
|
// Only use external IP if specifically provided for multi-server scenarios
|
||||||
|
var externalIP = Environment.GetEnvironmentVariable("CAPROVER_SERVER_IP") ??
|
||||||
|
Environment.GetEnvironmentVariable("EXTERNAL_IP");
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(externalIP) && IPAddress.TryParse(externalIP, out var parsedExternalIP))
|
||||||
{
|
{
|
||||||
// hostname is already an IP address
|
advertisedIP = parsedExternalIP;
|
||||||
|
Console.WriteLine($"Using external IP for multi-server clustering: {advertisedIP}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Try to resolve hostname to IP address
|
Console.WriteLine($"Using localhost for same-server clustering: {advertisedIP}");
|
||||||
try
|
|
||||||
{
|
|
||||||
var hostEntry = Dns.GetHostEntry(hostname);
|
|
||||||
advertisedIP = hostEntry.AddressList.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork)
|
|
||||||
?? hostEntry.AddressList.FirstOrDefault();
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
// Fallback to localhost if resolution fails
|
|
||||||
advertisedIP = IPAddress.Loopback;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var postgreSqlConnectionString = configuration.GetSection("PostgreSql")["Orleans"];
|
var postgreSqlConnectionString = configuration.GetSection("PostgreSql")["Orleans"];
|
||||||
@@ -156,7 +151,12 @@ public static class ApiBootstrap
|
|||||||
options.ConnectionString = postgreSqlConnectionString;
|
options.ConnectionString = postgreSqlConnectionString;
|
||||||
options.Invariant = "Npgsql";
|
options.Invariant = "Npgsql";
|
||||||
})
|
})
|
||||||
.ConfigureEndpoints(advertisedIP, siloPort, gatewayPort)
|
.Configure<EndpointOptions>(options =>
|
||||||
|
{
|
||||||
|
options.AdvertisedIPAddress = advertisedIP;
|
||||||
|
options.SiloPort = siloPort;
|
||||||
|
options.GatewayPort = gatewayPort;
|
||||||
|
})
|
||||||
.Configure<ClusterOptions>(options =>
|
.Configure<ClusterOptions>(options =>
|
||||||
{
|
{
|
||||||
options.ServiceId = "ManagingApp";
|
options.ServiceId = "ManagingApp";
|
||||||
@@ -193,8 +193,13 @@ public static class ApiBootstrap
|
|||||||
}
|
}
|
||||||
else if (string.IsNullOrEmpty(postgreSqlConnectionString))
|
else if (string.IsNullOrEmpty(postgreSqlConnectionString))
|
||||||
{
|
{
|
||||||
// In Docker/containerized environments, use the resolved IP address
|
// In Docker/containerized environments, use endpoint options
|
||||||
siloBuilder.ConfigureEndpoints(advertisedIP, siloPort, gatewayPort);
|
siloBuilder.Configure<EndpointOptions>(options =>
|
||||||
|
{
|
||||||
|
options.AdvertisedIPAddress = advertisedIP;
|
||||||
|
options.SiloPort = siloPort;
|
||||||
|
options.GatewayPort = gatewayPort;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
siloBuilder
|
siloBuilder
|
||||||
|
|||||||
Reference in New Issue
Block a user