问题
I have a curious situation.
I'm working on a pair of freeradius
servers and had planned to stick a load balancer in front of them in GCP. Not entirely sure if this is the best approach, as I don't have much experience with Freeradius really.. but it's the avenue I went down.
So I threw together some Terraform to build a couple of GCP instances and wrote a startup script to deploy the application and configuration files. All good so far.
Then I got started on the load balancer, and I noticed that GCP offer a UDP
Load Balancer as a service, great.. that works. However, it really wants a health check. Which is in principle fine, but not really possible over UDP
.
So then, I thought... maybe I'll write some python which can check if the radiusd
service is up and running, and if not.. stop httpd
... That way the load balancer can run it's http healthcheck
and if the radiusd
service stops, the python script will simply stop the httpd service
, and the load balancer will know that server is down, and switch to the other one.
My questions are multi-fold.. Although this approach may work, is it the best approach? To me it seems the more I drive down this road, the more it feels like the wrong way.
If by chance, it does seem to be the best approach.. I don't have much experience of running python output to a webpage. I've written a simple bit of python to check the service, as such?
import os
import subprocess
def running(name):
with open(os.devnull, 'wb') as hide_output:
exit_code = subprocess.Popen(['service', name, 'status'], stdout=hide_output, stderr=hide_output).wait()
return exit_code == 0
if not running('radiusd'):
os.system('service httpd stop')
As you can see, in this instance it will stop the httpd
service.. which will achieve what I want.. but it won't then start httpd
when the radiusd
service comes back up.
So, is there an alternative solution?
If not, is there a way I can run the script as a web app, which constantly runs checking the radiusd
service and bringing a holding page up or down depending on the outcome?
Thanks, and sorry for the essay.
来源:https://stackoverflow.com/questions/54539764/python-monitoring-radiusd-service-loadbalancer-tcp-healthcheck