forked from signal18/replication-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprov_opensvc_haproxy.go
73 lines (65 loc) · 2.25 KB
/
prov_opensvc_haproxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// replication-manager - Replication Manager Monitoring and CLI for MariaDB and MySQL
// Copyright 2017 Signal 18 SARL
// Authors: Guillaume Lefranc <guillaume@signal18.io>
// Stephane Varoqui <svaroqui@gmail.com>
// This source code is licensed under the GNU General Public License, version 3.
package cluster
import (
"fmt"
"log"
"github.com/signal18/replication-manager/opensvc"
)
func (cluster *Cluster) GetHaproxyTemplate(collector opensvc.Collector, servers string, agent opensvc.Host, prx *Proxy) (string, error) {
conf := `
[DEFAULT]
nodes = {env.nodes}
flex_primary = {env.nodes[0]}
cluster_type = flex
rollback = false
show_disabled = false
`
conf = conf + cluster.GetDockerDiskTemplate(collector)
i := 0
pod := fmt.Sprintf("%02d", i+1)
conf = conf + cluster.GetPodDiskTemplate(collector, pod)
conf = conf + `post_provision = {svcmgr} -s {svcname} push service status;{svcmgr} -s {svcname} compliance fix --attach --moduleset mariadb.svc.mrm.proxy
`
conf = conf + cluster.GetPodNetTemplate(collector, pod, i)
conf = conf + cluster.GetPodDockerHaproxyTemplate(collector, pod)
conf = conf + cluster.GetPodPackageTemplate(collector, pod)
conf = conf + cluster.GetProxiesEnv(collector, servers, agent, prx)
log.Println(conf)
return conf, nil
}
func (cluster *Cluster) GetPodDockerHaproxyTemplate(collector opensvc.Collector, pod string) string {
var vm string
if collector.ProvProxMicroSrv == "docker" {
vm = vm + `
[container#00` + pod + `]
type = docker
run_image = busybox:latest
run_args = --net=none -i -t
-v /etc/localtime:/etc/localtime:ro
run_command = /bin/sh
[container#20` + pod + `]
tags = pod` + pod + `
type = docker
run_image = {env.haproxy_img}
run_args = --net=container:{svcname}.container.00` + pod + `
-v {env.base_dir}/pod` + pod + `/init/checkslave:/usr/bin/checkslave:rw
-v {env.base_dir}/pod` + pod + `/init/checkmaster:/usr/bin/checkmaster:rw
-v /etc/localtime:/etc/localtime:ro
-v {env.base_dir}/pod` + pod + `/conf:/usr/local/etc/haproxy:rw
`
if dockerMinusRm {
vm = vm + ` --rm
`
}
}
return vm
}
func (cluster *Cluster) OpenSVCProvisionReloadHaproxyConf(Conf string) string {
svc := cluster.OpenSVCConnect()
svc.SetRulesetVariableValue("mariadb.svc.mrm.proxt.cnf.haproxy", "proxy_cnf_haproxy", Conf)
return ""
}