2

When writing a Node.js charm that requires SSL how should I write the Haproxy web hooks?

I am using the following hooks based on the sample code:

hooks/website-relation-joined:

#!/bin/bash

relation-set "hostname=$(unit-get private-address)"
relation-set "port=80"

# Set an optional service name, allowing more config-based
# customization
relation-set "service_name=mindproject"

hooks/website-relation-changed:

#!/bin/bash

host=$(unit-get private-address)
port=80

relation-set "services={ service_name: mindproject,service_options: [mode http, balance leastconn],crts: [DEFAULT], servers: [[mindproject, $host, $port, option httpchk GET / HTTP/1.0]]}"

After juju add-relation mindproject:website mind-proxy:reverseproxy the Haproxy charm fails reverseproxy-relation-changed hook with this log:

2015-03-24 20:17:31 INFO reverseproxy-relation-changed ^MReading package lists... 0%^M^MReading package lists... 0%^M^MReading package lists... 1%^M^MReading package lists... 11%^M^MReading package lists.$
2015-03-24 20:17:31 INFO reverseproxy-relation-changed ^MBuilding dependency tree... 0%^M^MBuilding dependency tree... 0%^M^MBuilding dependency tree... 50%^M^MBuilding dependency tree... 50%^M^MBuilding $
2015-03-24 20:17:31 INFO reverseproxy-relation-changed ^MReading state information... 0%^M^MReading state information... 5%^M^MReading state information... Done
2015-03-24 20:17:32 INFO reverseproxy-relation-changed Traceback (most recent call last):
2015-03-24 20:17:32 INFO reverseproxy-relation-changed   File "/var/lib/juju/agents/unit-mind-proxy-0/charm/hooks/reverseproxy-relation-changed", line 1271, in <module>
2015-03-24 20:17:32 INFO reverseproxy-relation-changed     main(hook_name)
2015-03-24 20:17:32 INFO reverseproxy-relation-changed   File "/var/lib/juju/agents/unit-mind-proxy-0/charm/hooks/reverseproxy-relation-changed", line 1246, in main
2015-03-24 20:17:32 INFO reverseproxy-relation-changed     reverseproxy_interface("changed")
2015-03-24 20:17:32 INFO reverseproxy-relation-changed   File "/var/lib/juju/agents/unit-mind-proxy-0/charm/hooks/reverseproxy-relation-changed", line 946, in reverseproxy_interface
2015-03-24 20:17:32 INFO reverseproxy-relation-changed     config_changed()
2015-03-24 20:17:32 INFO reverseproxy-relation-changed   File "/var/lib/juju/agents/unit-mind-proxy-0/charm/hooks/reverseproxy-relation-changed", line 903, in config_changed
2015-03-24 20:17:32 INFO reverseproxy-relation-changed     if not create_services():
2015-03-24 20:17:32 INFO reverseproxy-relation-changed   File "/var/lib/juju/agents/unit-mind-proxy-0/charm/hooks/reverseproxy-relation-changed", line 577, in create_services
2015-03-24 20:17:32 INFO reverseproxy-relation-changed     relation_info['services'])
2015-03-24 20:17:32 INFO reverseproxy-relation-changed   File "/var/lib/juju/agents/unit-mind-proxy-0/charm/hooks/reverseproxy-relation-changed", line 473, in parse_services_yaml
2015-03-24 20:17:32 INFO reverseproxy-relation-changed     service_name = service["service_name"]
2015-03-24 20:17:32 INFO reverseproxy-relation-changed TypeError: string indices must be integers, not str
2015-03-24 20:17:32 ERROR juju.worker.uniter uniter.go:486 hook failed: exit status 1

failed-hook

hatch
  • 2,323

1 Answers1

2

I don't think the haproxy charm's documentation is correct. I wrote a little script to model the yaml ingested by haproxy. Your website-relation-hook should look like this:

#!/bin/bash
set -eux

host=$(unit-get private-address)
port=80

relation-set "services=[{'server_options': ['maxconn 100'], 'service_name': 'demo', 'servers': [['mindproject', '${host}', '${port}', '']], 'service_options': ['mode http', 'balance leastconn', 'option httpchk GET / HTTP/1.0']}]"

The main problem with the code you posted is that you're passing services as a dict when it's expecting an array. On top of that, the servers section requires four parameters, but the last parameter, which is documented in the readme as 'option httpchk GET / HTTP/1.0' needs to be in the service_options stanza.

Hope this helps!