diff --git a/extras/README.md b/extras/README.md new file mode 100644 index 00000000..a4c3d59a --- /dev/null +++ b/extras/README.md @@ -0,0 +1,13 @@ +### confd + +`confd` directory contains haproxy template files for the [confd](https://github.com/kelseyhightower/confd) -- lightweight configuration management tool +You need to copy content of `confd` directory into /etcd/confd and run confd service: +```bash +$ confd -prefix=/service/$PATRONI_SCOPE -backend etcd -node $PATRONI_ETCD_HOST -interval=10 +``` +It will periodically update haproxy.cfg with the actual list of Patroni nodes from `etcd` and "reload" haproxy when it is necessary. + + +### startup-scripts + +`startup-scripts` directory contains startup scripts for various OSes and management tools for Patroni. diff --git a/extras/confd/conf.d/haproxy.toml b/extras/confd/conf.d/haproxy.toml new file mode 100644 index 00000000..f9f04fbc --- /dev/null +++ b/extras/confd/conf.d/haproxy.toml @@ -0,0 +1,13 @@ +[template] +#prefix = "/service/batman" +#owner = "haproxy" +#mode = "0644" +src = "haproxy.tmpl" +dest = "/etc/haproxy/haproxy.cfg" + +check_cmd = "/usr/sbin/haproxy -c -f {{ .src }}" +reload_cmd = "haproxy -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid -D -sf $(cat /var/run/haproxy.pid)" + +keys = [ + "/members/", +] diff --git a/extras/confd/templates/haproxy.tmpl b/extras/confd/templates/haproxy.tmpl new file mode 100644 index 00000000..4309ed0c --- /dev/null +++ b/extras/confd/templates/haproxy.tmpl @@ -0,0 +1,28 @@ +global + maxconn 100 + +defaults + log global + mode tcp + retries 2 + timeout client 30m + timeout connect 4s + timeout server 30m + timeout check 5s + +frontend master_postgresql + bind *:5000 + default_backend backend_master + +frontend replicas_postgresql + bind *:5001 + default_backend backend_replicas + +backend backend_master + option httpchk OPTIONS /master +{{range gets "/members/*"}} server {{base .Key}} {{$data := json .Value}}{{base (replace (index (split $data.conn_url "/") 2) "@" "/" -1)}} maxconn 100 check port {{index (split (index (split $data.api_url "/") 2) ":") 1}} +{{end}} +backend backend_replicas + option httpchk OPTIONS /replica +{{range gets "/members/*"}} server {{base .Key}} {{$data := json .Value}}{{base (replace (index (split $data.conn_url "/") 2) "@" "/" -1)}} maxconn 100 check port {{index (split (index (split $data.api_url "/") 2) ":") 1}} +{{end}}