This document explains how to create a custom Health Check for Rundeck, based on the execution mode of the Rundeck instance (active or passive) in order to redirect the traffic from the load balancer (in this case HAPROXY) to the active (or the passive if needed) Rundeck instance.
- Enable CGI Scripts for Rundeck installed with deb/rpm or launcher
The first step is to enable the CGI Script access on the embedded Jetty container. Please take a look at the following documentation:
- Create the health check script on each instance:
The health check uses a Rundeck API to get system information. A health check could factor in other information like scheduler thread ratio, CPU load or memory utilization. For an active/standby configuration, the health check should check the execution mode. When the execution mode is set to “passive” the load balancer should route around it.
The example below uses a python script to demonstrate this.
Create the following script on $RDECK_BASE/server/exp/webapp/WEB-INF/cgi-bin/status
from cgi import escape
form = cgi.FieldStorage()
token = form.getvalue("token")
url = 'http://localhost:4440/api/20/system/info?format=json&authtoken='+token
response = requests.post(url)
info = json.loads(response.text)
currentExecutionMode = info["system"]["executions"]["executionMode"]
print "Content-type: text/html"
print 'Status:'+status+' '
print "<!doctype html>"
print 'Current Execution Mode:' + currentExecutionMode
print 'Expected Execution Mode:' +executionMode
After the script has been deployed use your browser to visit the new health check page.
The URL accepts a parameter called “executionMode” which takes one of two values: active or passive. If specified mode matches the actual mode the page will return HTTP response code 200 otherwise it will return 403.
For example: http://localhost:4440/cgi-bin/status?token=<token>&executionMode=active
- On HAProxy, add the following settings:
The web load balancer serving traffic to the Rundeck instance should be configured with the health check.
- Add the “httpchk” with the URI of the health check. The token value and the execution mode that you want to use are needed.
- Add the “http-check” with the expected status (in this case 200)
cookie JSESSIONID prefix nocache
option httpchk get /cgi-bin/status?token=<TOKEN_VALUE>&executionMode=active
http-check expect status 200
server rundeck1 192.168.0.1:4440 cookie rundeck1 check inter 2000 rise 2 fall 3
server rundeck2 192.168.0.2:4440 cookie rundeck2 check inter 2000 rise 2 fall 3
server rundeck3 192.168.0.3:4440 cookie rundeck3 check inter 2000 rise 2 fall 3
- Check if HAproxy redirect to the active instance
Once the web load balancer has been configured with the health check, any instance that is not in “active” mode will not be passed traffic.