Welcome, Guest Login

Rundeck Enterprise Support Center

Health-Check based on Execution Mode for HAProxy LB

Last Updated: Oct 26, 2017 10:09AM PDT

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.

 

  1. 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:
 

http://support.rundeck.com/customer/portal/articles/2894840-enable-cgi-script-on-jetty

 

  1. 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

 

#!/usr/bin/python

 

import sys

import os

import cgi

 

from cgi import escape

import requests

import json

 

 

form = cgi.FieldStorage()

token = form.getvalue("token")

executionMode= form.getvalue("executionMode")

 

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"]

 

if currentExecutionMode==executionMode:

status="200"

else:

status="403"

 

print "Content-type: text/html"

print 'Status:'+status+' '

 

print

print "<!doctype html>"

print "<html>"

print "<body>"

 

print 'Current Execution Mode:' + currentExecutionMode

print "<br>"

print 'Expected Execution Mode:' +executionMode

print "</body>"

print "</html>"

 

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



 

  1. 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)

 

backend default_service

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

 

 

  1. 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.
 

1fb43f9155a47800b95738aff7e657fc@rundeck.desk-mail.com
http://assets3.desk.com/
false
desk
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/en/portal/articles/autocomplete