SSL Node.js Encantos com Haproxy

2

Ao escrever um encanto do Node.js que requer SSL, como devo escrever os ganchos da web da Haproxy?

Estou usando os seguintes ganchos com base no código de exemplo :

ganchos / 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]]}"

Depois de juju add-relation mindproject:website mind-proxy:reverseproxy , o encanto de Haproxy falha reverseproxy-relation-changed de gancho com este 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

    
por Brandon Clark 24.03.2015 / 23:09

1 resposta

2

Eu não acho que a documentação do haproxy charm esteja correta. Eu escrevi um pequeno script para modelar o yaml ingerido pelo haproxy. Seu site-relacionamento-gancho deve ficar assim:

#!/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']}]"

O principal problema com o código que você postou é que você está passando serviços como um dict quando ele está esperando um array. Além disso, a seção de servidores requer quatro parâmetros, mas o último parâmetro, que está documentado no readme como 'opção httpchk GET / HTTP / 1.0', precisa estar na sub-rotina service_options.

Espero que isso ajude!

    
por Adam Israel 25.03.2015 / 01:53