I played around with Marathon tonight and built a simple script that one might find useful.
Marathon Is a framework running on top of Apache Mesos. Mesos itself is a cluster manager that provides efficient resource isolation and sharing across distributed applications, or frameworks. It provides semantics for automatically distributing tasks to different nodes, based on various demands (CPU-Cores, RAM, special hardware features).
Marathon provides such a task of framework for creating and scaling long-running tasks like webservers. It automatically distributes them to ephemeral ports by setting the
PORT environment variable to a free ephemeral port.
Marathon comes with a script for generating a haproxy config for all configures applications. I used this and Chronos for automatically reloading a transparent proxy. Due to the simple reloading, haproxy restarted every minute (the interval I set in Chronos). To not bother haproxy I wrote an easy script I’d like to share:
#!/bin/bash original_sum=`md5sum haproxy.cfg` rm haproxy.cfg ./bin/haproxy_cfg localhost:8080 > haproxy.cfg new_sum=`md5sum haproxy.cfg` if [ "$original_sum" != "$new_sum" ] then echo "Reloading" haproxy -f haproxy.cfg -p haproxy.pid -sf $(cat haproxy.pid) else echo "Not reloading" fi
It creates an
md5sum from the current config, regenerates it and compares the md5sums. If they changed it reloads haproxy gracefully, otherwise juts prints “Not reloading”. With a script as simple as that you have a basic proxy and, provided by Marathon, a fault-tolerant task manager.
To take that a step further you should set up at least 2 dedicated loadbalancers and facilitate Marathon Events to reload them on demand. Let me know if you built sth. awesome with that :)