使用 Haproxy 的 SSL Node.js Charms

使用 Haproxy 的 SSL Node.js Charms

在编写需要 SSL 的 Node.js charm 时,我应该如何编写 Haproxy web hooks?

我使用以下钩子基于示例代码

钩子/网站关系加入:

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

钩子/网站关系改变:

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

juju add-relation mindproject:website mind-proxy:reverseproxyHaproxy charm 挂载失败后reverseproxy-relation-changed显示以下日志:

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

挂接失败

答案1

我认为 haproxy charm 的文档不正确。我写了一点脚本对 haproxy 提取的 yaml 进行建模。你的 website-relation-hook 应该如下所示:

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

您发布的代码的主要问题是,您传递的服务是字典形式,而它期望的是一个数组。除此之外,服务器部分需要四个参数,但最后一个参数(在自述文件中记录为“option httpchk GET / HTTP/1.0”)需要位于 service_options 节中。

希望这可以帮助!

相关内容