From c520e20c428c18e27f5739d02c06b5b0c91ee2d6 Mon Sep 17 00:00:00 2001 From: Sergey Yakubov <sergey.yakubov@desy.de> Date: Fri, 17 Jan 2020 13:27:02 +0100 Subject: [PATCH] update deployment scripts for orc template --- .../scripts/asapo.auto.tfvars | 5 -- .../scripts/monitoring.nmd.tpl | 21 +++--- .../scripts/nginx.conf.tpl | 66 +++++++++++-------- .../scripts/nginx.nmd.tpl | 12 +--- .../scripts/templates.tf | 8 --- .../scripts/vars.tf | 5 -- 6 files changed, 53 insertions(+), 64 deletions(-) diff --git a/deploy/asapo_orchestration_docker/scripts/asapo.auto.tfvars b/deploy/asapo_orchestration_docker/scripts/asapo.auto.tfvars index 3d6338cae..78479b1e0 100644 --- a/deploy/asapo_orchestration_docker/scripts/asapo.auto.tfvars +++ b/deploy/asapo_orchestration_docker/scripts/asapo.auto.tfvars @@ -1,9 +1,6 @@ job_scripts_dir = "/var/run/asapo" -consul_dns_port = 8600 - grafana_total_memory_size = "256" -grafana_port = 3000 grafana_version="latest" nginx_total_memory_size = 256 @@ -12,11 +9,9 @@ nginx_port_stream = 8402 nginx_version = "1.14" influxdb_total_memory_size = "256" -influxdb_port = 8086 influxdb_version = "latest" telegraf_total_memory_size = "256" -telegraf_port_stream = 8125 telegraf_version = "latest" monitoring = true diff --git a/deploy/asapo_orchestration_docker/scripts/monitoring.nmd.tpl b/deploy/asapo_orchestration_docker/scripts/monitoring.nmd.tpl index 0a4e667a4..3ab354c40 100644 --- a/deploy/asapo_orchestration_docker/scripts/monitoring.nmd.tpl +++ b/deploy/asapo_orchestration_docker/scripts/monitoring.nmd.tpl @@ -39,13 +39,16 @@ job "monitoring" { env { PRE_CREATE_DB="asapo_receivers;asapo_brokers" + INFLUXDB_BIND_ADDRESS="127.0.0.1:$${NOMAD_PORT_influxdb_rpc}" + INFLUXDB_HTTP_BIND_ADDRESS=":$${NOMAD_PORT_influxdb}" } resources { memory = "${influxdb_total_memory_size}" network { port "influxdb" { - static = "${influxdb_port}" + } + port "influxdb_rpc" { } } } @@ -94,7 +97,6 @@ job "monitoring" { memory = "${grafana_total_memory_size}" network { port "grafana" { - static = "${grafana_port}" } } } @@ -156,7 +158,6 @@ job "monitoring" { memory = "${telegraf_total_memory_size}" network { port "telegraf_stream" { - static = "${telegraf_port_stream}" } } } @@ -167,16 +168,16 @@ job "monitoring" { check { name = "telegraf-alive" type = "script" - command = "/bin/ps" - args = ["-fC","telegraf"] + command = "/bin/pidof" + args = ["telegraf"] interval = "10s" timeout = "2s" } - check_restart { - limit = 2 - grace = "15s" - ignore_warnings = false - } +# check_restart { +# limit = 2 +# grace = "15s" +# ignore_warnings = false +# } } template { diff --git a/deploy/asapo_orchestration_docker/scripts/nginx.conf.tpl b/deploy/asapo_orchestration_docker/scripts/nginx.conf.tpl index 18eacfafd..4632be50e 100644 --- a/deploy/asapo_orchestration_docker/scripts/nginx.conf.tpl +++ b/deploy/asapo_orchestration_docker/scripts/nginx.conf.tpl @@ -7,57 +7,69 @@ events { error_log "/dev/stdout"; pid "/tmp/nginx.pid"; -http { -# include mime.types; -# default_type application/octet-stream; - -# sendfile on; -# tcp_nopush on; - -# keepalive_timeout 0; -# keepalive_timeout 65; - - access_log off; - +{{ $grafana := false -}} +{{ $influxdb := false -}} +{{ $telegraf := false -}} +{{ range service "grafana" -}} {{ $grafana = true }}{{ end -}} +{{ range service "influxdb" -}} {{ $influxdb = true }}{{ end -}} +{{ range service "telegraf" -}} {{ $telegraf = true }}{{ end -}} +http { + access_log off; client_body_temp_path "/tmp/client_body" 1 2; proxy_temp_path "/tmp/proxy" 1 2; fastcgi_temp_path "/tmp/fastcgi" 1 2; scgi_temp_path "/tmp/scgi" 1 2; uwsgi_temp_path "/tmp/uwsgi" 1 2; +{{ if $grafana }} + upstream grafana { + {{- range service "grafana" }} + server {{ .Address }}:{{ .Port }}; + {{ end -}} + } +{{ end -}} +{{- if $influxdb}} + upstream influxdb { + {{- range service "influxdb" }} + server {{ .Address }}:{{ .Port }}; + {{ end -}} + } +{{- end }} - resolver 127.0.0.1:{{ env "NOMAD_META_consul_dns_port" }} valid=1s; server { listen {{ env "NOMAD_PORT_nginx" }} reuseport; - set $grafana_endpoint grafana.service.asapo; - set $influxdb_endpoint influxdb.service.asapo; - - location /influxdb/ { +{{- if $influxdb }} + location /influxdb/ { rewrite ^/influxdb(/.*) $1 break; - proxy_pass http://$influxdb_endpoint:{{ env "NOMAD_META_influxdb_port" }}$uri$is_args$args; + proxy_pass http://influxdb$uri$is_args$args; } - +{{ end -}} +{{- if $grafana }} location /monitoring/ { rewrite ^/monitoring(/.*) $1 break; - proxy_pass http://$grafana_endpoint:{{ env "NOMAD_META_grafana_port" }}$uri$is_args$args; + proxy_pass http://grafana$uri$is_args$args; } +{{- end }} location /nginx-health { return 200 "healthy\n"; - } + } } } +{{ if $telegraf -}} stream { - resolver 127.0.0.1:{{ env "NOMAD_META_consul_dns_port" }} valid=1s; - - map $remote_addr $upstream { - default telegraf.service.asapo; + upstream telegraf { + {{- range service "telegraf" }} + server {{ .Address }}:{{ .Port }}; + {{- end }} } - server { listen {{ env "NOMAD_PORT_nginx_stream" }} udp; - proxy_pass $upstream:{{ env "NOMAD_META_telegraf_port_stream" }}; + proxy_pass telegraf; } } +{{ end -}} + + diff --git a/deploy/asapo_orchestration_docker/scripts/nginx.nmd.tpl b/deploy/asapo_orchestration_docker/scripts/nginx.nmd.tpl index 994d99004..703997875 100644 --- a/deploy/asapo_orchestration_docker/scripts/nginx.nmd.tpl +++ b/deploy/asapo_orchestration_docker/scripts/nginx.nmd.tpl @@ -18,20 +18,13 @@ job "asapo-nginx" { user = "${asapo_user}" - meta { - telegraf_port_stream = "${telegraf_port_stream}" - grafana_port = "${grafana_port}" - influxdb_port = "${influxdb_port}" - consul_dns_port = "${consul_dns_port}" - } - config { network_mode = "host" security_opt = ["no-new-privileges"] userns_mode = "host" image = "nginx:${nginx_version}" volumes = [ - "local/nginx.conf:/etc/nginx/nginx.conf" + "local:/etc/nginx" ] } @@ -70,7 +63,8 @@ job "asapo-nginx" { template { source = "${scripts_dir}/nginx.conf.tpl" destination = "local/nginx.conf" - change_mode = "restart" + change_mode = "signal" + change_signal = "SIGHUP" } } } diff --git a/deploy/asapo_orchestration_docker/scripts/templates.tf b/deploy/asapo_orchestration_docker/scripts/templates.tf index cf1994d74..a689d2397 100644 --- a/deploy/asapo_orchestration_docker/scripts/templates.tf +++ b/deploy/asapo_orchestration_docker/scripts/templates.tf @@ -5,16 +5,12 @@ data "template_file" "monitoring_template" { service_dir = "${var.service_dir}" grafana_version = "${var.grafana_version}" grafana_total_memory_size = "${var.grafana_total_memory_size}" - grafana_port = "${var.grafana_port}" grafana_version = "${var.grafana_version}" grafana_total_memory_size = "${var.grafana_total_memory_size}" - grafana_port = "${var.grafana_port}" influxdb_version = "${var.influxdb_version}" influxdb_total_memory_size = "${var.influxdb_total_memory_size}" - influxdb_port = "${var.influxdb_port}" telegraf_version = "${var.telegraf_version}" telegraf_total_memory_size = "${var.telegraf_total_memory_size}" - telegraf_port_stream = "${var.telegraf_port_stream}" nginx_port = "${var.nginx_port}" asapo_user = "${var.asapo_user}" scripts_dir = "${var.job_scripts_dir}" @@ -29,11 +25,7 @@ data "template_file" "nginx_template" { nginx_version = "${var.nginx_version}" nginx_port = "${var.nginx_port}" nginx_port_stream = "${var.nginx_port_stream}" - telegraf_port_stream = "${var.telegraf_port_stream}" - grafana_port = "${var.grafana_port}" - influxdb_port = "${var.influxdb_port}" asapo_user = "${var.asapo_user}" - consul_dns_port = "${var.consul_dns_port}" } } diff --git a/deploy/asapo_orchestration_docker/scripts/vars.tf b/deploy/asapo_orchestration_docker/scripts/vars.tf index 3944e8f7e..b7d432504 100644 --- a/deploy/asapo_orchestration_docker/scripts/vars.tf +++ b/deploy/asapo_orchestration_docker/scripts/vars.tf @@ -12,17 +12,12 @@ variable "service_dir" {} variable "data_dir" {} variable "grafana_total_memory_size" {} -variable "grafana_port" {} -variable "telegraf_port_stream" {} variable "telegraf_total_memory_size" {} variable "influxdb_total_memory_size" {} -variable "influxdb_port" {} variable "nginx_total_memory_size" {} variable "nginx_port" {} variable "nginx_port_stream" {} -variable "consul_dns_port" {} - -- GitLab