Is there a way to redirect traffic to another port in the event that the service listening to the original port is unresponsive?

1

1

This is a rather specific question, but it is one I haven't been able to find an answer to. I'm running a set of services on an LXC container in Ubuntu 16.04 LTS, specifically game servers. However, this service is known to fail, and so has its wrapper. So in order to maintain uptime and load balance where services are hanging or unresponsive, I need to be able to redirect both UDP and TCP traffic based on whether a service or services are responsive or not.

To better explain the scenario, I have an LXC container exposed to a public IP, with another LXC container nested with iptables redirecting traffic on port 21025 to the nested container. Inside that container, if the services that accept the traffic (called ServiceWrapper and ServiceMain) are unresponsive, the traffic must go to another service on another port which we'll call ServiceFallback. Otherwise, the traffic goes as expected to ServiceWrapper which then sends the traffic to ServiceMain.

My current attempt to implement this sort of routing has been to use HAProxy to loadbalance between ServiceWrapper and ServiceFallback, however at first glance it appears HAProxy does not detect or allow the redirection of additional ports based on how it is loadbalancing ServiceWrapper and ServiceFallback. You see, ServiceMain accepts UDP traffic on another port to facilitate server queries such as version, hostname, etc etc. And as far as I can tell, HAProxy will not route or detect UDP traffic.

I'm semi-desperate to get this to work. I know it is possible because the exact setup I'm attempting to perform has worked for one of my direct competitors, however they seem reluctant to share with me even the packages they used to do it (reasonable, but eh).

Shigbeard_

Posted 2018-03-09T15:01:35.950

Reputation: 11

I feel you need NGINX – Garr Godfrey – 2018-03-09T17:48:55.013

Answers

0

NGINX should do everything you need. It support UDP routing and has both passive and active health checks, so you can configure how it determines if the main service is running or not. It can be configured to only fall back to your backup service if the health checks fail.

Garr Godfrey

Posted 2018-03-09T15:01:35.950

Reputation: 394

Does NGINX rewrite the source IP? And if so, does it send traffic back to where it originally came from when it receives a response? This was another issue I encountered later with HAproxy: packets coming into the ServiceWrapper would read as coming from the internal IP HAproxy was running out of, and not the actual source IP. – Shigbeard_ – 2018-03-10T05:32:05.577

Generally, yes, it will appear to be from an internal IP but be forwardd back to client. I haven't used the UDP proxy, however, as it seems like it would have to have the source IP somehow. For http traffic it would put the original in the header. – Garr Godfrey – 2018-03-10T07:41:51.493