caco 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.travis.yml +10 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +227 -0
- data/Guardfile +42 -0
- data/LICENSE.txt +21 -0
- data/README.md +97 -0
- data/Rakefile +10 -0
- data/bin/_guard-core +29 -0
- data/bin/bundle +114 -0
- data/bin/byebug +29 -0
- data/bin/caco +29 -0
- data/bin/coderay +29 -0
- data/bin/console +20 -0
- data/bin/eyaml +29 -0
- data/bin/guard +29 -0
- data/bin/listen +29 -0
- data/bin/pry +29 -0
- data/bin/rake +29 -0
- data/bin/safe_yaml +29 -0
- data/bin/setup +8 -0
- data/bin/thor +29 -0
- data/bin/tilt +29 -0
- data/caco.gemspec +43 -0
- data/exe/caco +27 -0
- data/lib/caco.rb +115 -0
- data/lib/caco/barman.rb +10 -0
- data/lib/caco/barman/cell/global.rb +4 -0
- data/lib/caco/barman/cell/node.rb +15 -0
- data/lib/caco/barman/install.rb +25 -0
- data/lib/caco/barman/view/global.erb +7 -0
- data/lib/caco/barman/view/node.erb +8 -0
- data/lib/caco/cell.rb +8 -0
- data/lib/caco/config.rb +23 -0
- data/lib/caco/debian.rb +28 -0
- data/lib/caco/debian/add_user.rb +18 -0
- data/lib/caco/debian/apt_key_install.rb +19 -0
- data/lib/caco/debian/apt_repo_add.rb +17 -0
- data/lib/caco/debian/apt_sources_list.rb +15 -0
- data/lib/caco/debian/apt_update.rb +33 -0
- data/lib/caco/debian/cell/service.rb +19 -0
- data/lib/caco/debian/cell/sources_list.rb +7 -0
- data/lib/caco/debian/package_install.rb +21 -0
- data/lib/caco/debian/package_installed.rb +17 -0
- data/lib/caco/debian/service_enable.rb +26 -0
- data/lib/caco/debian/service_install.rb +31 -0
- data/lib/caco/debian/user_home.rb +17 -0
- data/lib/caco/debian/view/service.erb +18 -0
- data/lib/caco/debian/view/sources_list.erb +10 -0
- data/lib/caco/downloader.rb +41 -0
- data/lib/caco/executer.rb +33 -0
- data/lib/caco/facter.rb +41 -0
- data/lib/caco/file_link.rb +36 -0
- data/lib/caco/file_reader.rb +24 -0
- data/lib/caco/file_writer.rb +57 -0
- data/lib/caco/finder.rb +13 -0
- data/lib/caco/grafana.rb +6 -0
- data/lib/caco/grafana/install.rb +26 -0
- data/lib/caco/haproxy.rb +12 -0
- data/lib/caco/haproxy/cell/conf_postgres.rb +4 -0
- data/lib/caco/haproxy/cell/conf_stats.rb +4 -0
- data/lib/caco/haproxy/conf_get.rb +15 -0
- data/lib/caco/haproxy/conf_set.rb +52 -0
- data/lib/caco/haproxy/install.rb +9 -0
- data/lib/caco/haproxy/view/conf_postgres.erb +25 -0
- data/lib/caco/haproxy/view/conf_stats.erb +6 -0
- data/lib/caco/macro.rb +2 -0
- data/lib/caco/postgres.rb +44 -0
- data/lib/caco/postgres/build_augeas.rb +20 -0
- data/lib/caco/postgres/conf_get.rb +37 -0
- data/lib/caco/postgres/conf_set.rb +54 -0
- data/lib/caco/postgres/database_create.rb +28 -0
- data/lib/caco/postgres/extension_create.rb +28 -0
- data/lib/caco/postgres/hba_set.rb +65 -0
- data/lib/caco/postgres/install.rb +34 -0
- data/lib/caco/postgres/shell.rb +13 -0
- data/lib/caco/postgres/sql.rb +17 -0
- data/lib/caco/postgres/user_change_password.rb +13 -0
- data/lib/caco/postgres/user_create.rb +33 -0
- data/lib/caco/prometheus.rb +15 -0
- data/lib/caco/prometheus/adapter_install_pg.rb +107 -0
- data/lib/caco/prometheus/adapter_install_postgresql.rb +47 -0
- data/lib/caco/prometheus/cell/alertmanager_conf.rb +4 -0
- data/lib/caco/prometheus/cell/alerts.rb +4 -0
- data/lib/caco/prometheus/cell/conf.rb +7 -0
- data/lib/caco/prometheus/exporter_install.rb +35 -0
- data/lib/caco/prometheus/install.rb +50 -0
- data/lib/caco/prometheus/install_alert_manager.rb +62 -0
- data/lib/caco/prometheus/view/alertmanager_conf.erb +13 -0
- data/lib/caco/prometheus/view/alerts.erb +18 -0
- data/lib/caco/prometheus/view/conf.erb +34 -0
- data/lib/caco/rbenv.rb +8 -0
- data/lib/caco/rbenv/cell/profile.rb +4 -0
- data/lib/caco/rbenv/install.rb +56 -0
- data/lib/caco/rbenv/install_version.rb +17 -0
- data/lib/caco/rbenv/view/profile.erb +3 -0
- data/lib/caco/repmgr.rb +15 -0
- data/lib/caco/repmgr/cell/conf.rb +43 -0
- data/lib/caco/repmgr/conf.rb +25 -0
- data/lib/caco/repmgr/install.rb +25 -0
- data/lib/caco/repmgr/node_register_primary.rb +34 -0
- data/lib/caco/repmgr/node_register_standby.rb +25 -0
- data/lib/caco/repmgr/node_registered.rb +15 -0
- data/lib/caco/repmgr/node_role.rb +18 -0
- data/lib/caco/repmgr/view/conf.erb +27 -0
- data/lib/caco/settings_loader.rb +67 -0
- data/lib/caco/settings_loader_monkeypatch.rb +28 -0
- data/lib/caco/ssh.rb +6 -0
- data/lib/caco/ssh/authorized_keys_add.rb +82 -0
- data/lib/caco/sudo.rb +6 -0
- data/lib/caco/sudo/sudoers_add.rb +15 -0
- data/lib/caco/timescale.rb +6 -0
- data/lib/caco/timescale/install.rb +25 -0
- data/lib/caco/unpacker.rb +76 -0
- data/lib/caco/version.rb +3 -0
- metadata +398 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
global:
|
|
2
|
+
slack_api_url: 'https://hooks.slack.com/services/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'
|
|
3
|
+
|
|
4
|
+
route:
|
|
5
|
+
receiver: 'slack-notifications'
|
|
6
|
+
group_by: [alertname, datacenter, app]
|
|
7
|
+
|
|
8
|
+
receivers:
|
|
9
|
+
- name: 'slack-notifications'
|
|
10
|
+
slack_configs:
|
|
11
|
+
- send_resolved: true
|
|
12
|
+
- channel: '#monitoring'
|
|
13
|
+
text: 'https://internal.myorg.net/wiki/alerts/{{ .GroupLabels.app }}/{{ .GroupLabels.alertname }}'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
groups:
|
|
2
|
+
- name: alert.rules
|
|
3
|
+
rules:
|
|
4
|
+
- alert: EndpointDown
|
|
5
|
+
expr: probe_success == 0
|
|
6
|
+
for: 10s
|
|
7
|
+
labels:
|
|
8
|
+
severity: 'critical'
|
|
9
|
+
annotations:
|
|
10
|
+
summary: 'Endpoint down'
|
|
11
|
+
- alert: ExporterDown
|
|
12
|
+
expr: up == 0
|
|
13
|
+
for: 1m
|
|
14
|
+
labels:
|
|
15
|
+
severity: warning
|
|
16
|
+
annotations:
|
|
17
|
+
summary: 'Exporter down (instance {{ $labels.instance }})'
|
|
18
|
+
description: 'Prometheus exporter down\n VALUE = {{ $value }}\n LABELS: {{ $labels }}'
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
global:
|
|
2
|
+
scrape_interval: 15s
|
|
3
|
+
evaluation_interval: 15s
|
|
4
|
+
|
|
5
|
+
remote_write:
|
|
6
|
+
- url: "http://127.0.0.1:9201/write"
|
|
7
|
+
remote_read:
|
|
8
|
+
- url: "http://127.0.0.1:9201/read"
|
|
9
|
+
|
|
10
|
+
rule_files:
|
|
11
|
+
- <%= root %>/alerts.d/*.rules
|
|
12
|
+
|
|
13
|
+
alerting:
|
|
14
|
+
alertmanagers:
|
|
15
|
+
- static_configs:
|
|
16
|
+
- targets:
|
|
17
|
+
- localhost:9093
|
|
18
|
+
|
|
19
|
+
scrape_configs:
|
|
20
|
+
- job_name: prometheus
|
|
21
|
+
static_configs:
|
|
22
|
+
- targets: ['localhost:9090']
|
|
23
|
+
- job_name: postgresql
|
|
24
|
+
static_configs:
|
|
25
|
+
- targets: ['localhost:9187']
|
|
26
|
+
- job_name: postgresql_adapter
|
|
27
|
+
static_configs:
|
|
28
|
+
- targets: ['localhost:9201']
|
|
29
|
+
- job_name: node_exporter
|
|
30
|
+
scrape_interval: 1m
|
|
31
|
+
scrape_timeout: 1m
|
|
32
|
+
metrics_path: '/metrics'
|
|
33
|
+
static_configs:
|
|
34
|
+
- targets: ['localhost:9100']
|
data/lib/caco/rbenv.rb
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module Caco::Rbenv
|
|
2
|
+
class Install < Trailblazer::Operation
|
|
3
|
+
CloneRepo = Class.new(Trailblazer::Activity::Signal)
|
|
4
|
+
|
|
5
|
+
step :install_packages!
|
|
6
|
+
step :repo_exist?, Output(CloneRepo, :clone_repo) => Path(connect_to: Id(:make_src)) do
|
|
7
|
+
step :clone_repo
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
pass Subprocess(Class.new(Caco::Executer)),
|
|
11
|
+
input: ->(_ctx, **) {{
|
|
12
|
+
command: "[ ! -f /opt/rbenv/libexec/rbenv-realpath.dylib ] && cd /opt/rbenv && src/configure && make -C src; true",
|
|
13
|
+
}},
|
|
14
|
+
Output(:failure) => Track(:success),
|
|
15
|
+
id: :make_src
|
|
16
|
+
|
|
17
|
+
step ->(ctx, **) {
|
|
18
|
+
ctx[:profile_content] = Caco::Rbenv::Cell::Profile.().to_s
|
|
19
|
+
},
|
|
20
|
+
id: :build_profile_content
|
|
21
|
+
|
|
22
|
+
step Subprocess(Caco::FileWriter),
|
|
23
|
+
input: ->(_ctx, profile_content:, **) {{
|
|
24
|
+
path: "/etc/profile.d/rbenv.sh",
|
|
25
|
+
content: profile_content
|
|
26
|
+
}}
|
|
27
|
+
|
|
28
|
+
def install_packages!(ctx, **)
|
|
29
|
+
packages = []
|
|
30
|
+
if Caco::Facter.("os", "distro", "codename") == "stretch"
|
|
31
|
+
packages = %w(git autoconf bison libssl-dev libyaml-dev libreadline-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev)
|
|
32
|
+
elsif Caco::Facter.("os", "distro", "codename") == "buster"
|
|
33
|
+
packages = %w(git autoconf bison libssl-dev libyaml-dev libreadline-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
packages.each do |package|
|
|
37
|
+
result = Caco::Debian::PackageInstall.(package: package)
|
|
38
|
+
return false if result.failure?
|
|
39
|
+
end
|
|
40
|
+
true
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def repo_exist?(ctx, **)
|
|
44
|
+
self.class.repo_exist?
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.repo_exist?
|
|
48
|
+
File.exist?("/opt/rbenv") ? true : CloneRepo
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def clone_repo(ctx, **)
|
|
52
|
+
result = Caco::Executer.(command: "git clone https://github.com/rbenv/rbenv.git /opt/rbenv")
|
|
53
|
+
result.success?
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Caco::Rbenv
|
|
2
|
+
class InstallVersion < Trailblazer::Operation
|
|
3
|
+
step Subprocess(Class.new(Caco::Executer)),
|
|
4
|
+
input: ->(_ctx, version:, **) {{
|
|
5
|
+
command: ". /etc/profile && /opt/rbenv/bin/rbenv versions|egrep --color \"^..#{version}(\s|$)\"",
|
|
6
|
+
}},
|
|
7
|
+
Output(:failure) => Id(:install_version),
|
|
8
|
+
id: :install_version_checker
|
|
9
|
+
|
|
10
|
+
step Subprocess(Class.new(Caco::Executer)),
|
|
11
|
+
input: ->(_ctx, version:, **) {{
|
|
12
|
+
command: ". /etc/profile && /opt/rbenv/bin/rbenv install #{version}",
|
|
13
|
+
}},
|
|
14
|
+
id: :install_version,
|
|
15
|
+
magnetic_to: nil
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/caco/repmgr.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Caco
|
|
2
|
+
module Repmgr
|
|
3
|
+
end
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
require 'caco/repmgr/conf'
|
|
7
|
+
require 'caco/repmgr/install'
|
|
8
|
+
require 'caco/repmgr/node_registered'
|
|
9
|
+
require 'caco/repmgr/node_role'
|
|
10
|
+
|
|
11
|
+
require 'caco/repmgr/node_register_primary'
|
|
12
|
+
require 'caco/repmgr/node_register_standby'
|
|
13
|
+
|
|
14
|
+
# Templates
|
|
15
|
+
require 'caco/repmgr/cell/conf'
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module Caco::Repmgr::Cell
|
|
2
|
+
class Conf < Trailblazer::Cell
|
|
3
|
+
def node_id
|
|
4
|
+
property(:node_id)
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def node_name
|
|
8
|
+
property(:node_name)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def primary_host
|
|
12
|
+
property(:primary_host)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def primary_user
|
|
16
|
+
property(:primary_user)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def primary_database
|
|
20
|
+
property(:primary_database)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def node_initial_role
|
|
24
|
+
property(:node_initial_role)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def postgres_version
|
|
28
|
+
property(:postgres_version)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def use_barman?
|
|
32
|
+
property(:use_barman) || false
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def barman_host
|
|
36
|
+
property(:barman_host) || "barman"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def barman_server
|
|
40
|
+
property(:barman_server) || "pg"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Caco::Repmgr
|
|
2
|
+
class Conf < Trailblazer::Operation
|
|
3
|
+
step ->(ctx, **) {
|
|
4
|
+
ctx[:path] = "/etc/repmgr.conf"
|
|
5
|
+
},
|
|
6
|
+
id: :build_path
|
|
7
|
+
|
|
8
|
+
step :build_content
|
|
9
|
+
|
|
10
|
+
step Subprocess(Caco::FileWriter),
|
|
11
|
+
input: ->(_ctx, path:, content:, **) {{
|
|
12
|
+
path: path,
|
|
13
|
+
content: content
|
|
14
|
+
}},
|
|
15
|
+
output: {file_created: :created, file_changed: :changed}
|
|
16
|
+
|
|
17
|
+
def build_content(ctx, node_id:, node_name:, postgres_version:, **)
|
|
18
|
+
ctx[:content] = Caco::Repmgr::Cell::Conf.(
|
|
19
|
+
node_id: node_id,
|
|
20
|
+
node_name: node_name,
|
|
21
|
+
postgres_version: postgres_version
|
|
22
|
+
).to_s
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Caco::Repmgr
|
|
2
|
+
class Install < Trailblazer::Operation
|
|
3
|
+
class Repo < Trailblazer::Operation
|
|
4
|
+
step Subprocess(Caco::Debian::AptKeyInstall),
|
|
5
|
+
input: ->(_ctx, **) {{
|
|
6
|
+
url: 'https://dl.2ndquadrant.com/gpg-key.asc',
|
|
7
|
+
fingerprint: '8565 305C EA7D 0B66 4933 D250 9904 CD4B D6BA F0C3'
|
|
8
|
+
}}
|
|
9
|
+
step Subprocess(Caco::Debian::AptRepoAdd),
|
|
10
|
+
input: ->(_ctx, **) {{
|
|
11
|
+
name: '2ndquadrant-dl-default-release',
|
|
12
|
+
url: 'https://dl.2ndquadrant.com/default/release/apt',
|
|
13
|
+
release: "#{Caco::Facter.("os", "distro", "codename")}-2ndquadrant",
|
|
14
|
+
component: 'main'
|
|
15
|
+
}}
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
step Subprocess(Repo)
|
|
19
|
+
step Subprocess(Caco::Debian::AptUpdate)
|
|
20
|
+
step Subprocess(Caco::Debian::PackageInstall),
|
|
21
|
+
input: ->(_ctx, **) {{
|
|
22
|
+
package: 'repmgr'
|
|
23
|
+
}}
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Caco::Repmgr
|
|
2
|
+
class NodeRegisterPrimary < Trailblazer::Operation
|
|
3
|
+
step Subprocess(Caco::Repmgr::NodeRole),
|
|
4
|
+
input: ->(_ctx, node_name:, **) {{
|
|
5
|
+
node_name: node_name
|
|
6
|
+
}},
|
|
7
|
+
id: :node_role,
|
|
8
|
+
Output(:success) => Id(:check_existing_id),
|
|
9
|
+
Output(:failure) => Track(:success)
|
|
10
|
+
|
|
11
|
+
step :check_existing_id, magnetic_to: nil,
|
|
12
|
+
Output(:success) => End(:success),
|
|
13
|
+
Output(:failure) => End(:failure)
|
|
14
|
+
|
|
15
|
+
step :verify_any_primary,
|
|
16
|
+
Output(:success) => End(:failure),
|
|
17
|
+
Output(:failure) => Track(:success)
|
|
18
|
+
|
|
19
|
+
step Subprocess(Class.new(Caco::Executer)),
|
|
20
|
+
input: ->(_ctx, node_name:, **) {{
|
|
21
|
+
command: "su - postgres -c 'repmgr primary register'"
|
|
22
|
+
}},
|
|
23
|
+
id: :repmgr_register_primary
|
|
24
|
+
|
|
25
|
+
def check_existing_id(ctx, node_role:, **)
|
|
26
|
+
return true if node_role == "primary"
|
|
27
|
+
false
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def verify_any_primary(ctx, node_name:, output:, **)
|
|
31
|
+
output.match?(/^\s+[0-9]{1,}\s+\|\s(?!#{node_name})[^\s]+\s+\|\s+primary\s+\|/)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Caco::Repmgr
|
|
2
|
+
class NodeRegisterStandby < Trailblazer::Operation
|
|
3
|
+
step Subprocess(Caco::Repmgr::NodeRole),
|
|
4
|
+
input: ->(_ctx, node_name:, **) {{
|
|
5
|
+
node_name: node_name
|
|
6
|
+
}},
|
|
7
|
+
id: :node_role,
|
|
8
|
+
Output(:success) => Id(:check_existing_id),
|
|
9
|
+
Output(:failure) => Track(:success)
|
|
10
|
+
|
|
11
|
+
step ->(ctx, node_role:, **) {
|
|
12
|
+
node_role == "standby"
|
|
13
|
+
},
|
|
14
|
+
magnetic_to: nil,
|
|
15
|
+
Output(:success) => End(:success),
|
|
16
|
+
Output(:failure) => End(:failure),
|
|
17
|
+
id: :check_existing_id
|
|
18
|
+
|
|
19
|
+
step Subprocess(Class.new(Caco::Executer)),
|
|
20
|
+
input: ->(_ctx, node_name:, **) {{
|
|
21
|
+
command: "su - postgres -c 'repmgr standby register'"
|
|
22
|
+
}},
|
|
23
|
+
id: :repmgr_register_primary
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Caco::Repmgr
|
|
2
|
+
class NodeRegistered < Trailblazer::Operation
|
|
3
|
+
step Subprocess(Caco::Executer),
|
|
4
|
+
input: ->(_ctx, node_name:, **) {{
|
|
5
|
+
command: "su - postgres -c 'repmgr cluster show --compact'"
|
|
6
|
+
}},
|
|
7
|
+
id: :repmgr_cluster_show
|
|
8
|
+
|
|
9
|
+
step ->(ctx, node_name:, output:, **) {
|
|
10
|
+
# set to ctx so can be used in other operations
|
|
11
|
+
ctx[:node_registered] = output.match?(/^\s+[0-9]{1,}\s+\|\s+#{node_name}\s+\|/)
|
|
12
|
+
},
|
|
13
|
+
id: :verify_node
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Caco::Repmgr
|
|
2
|
+
class NodeRole < Trailblazer::Operation
|
|
3
|
+
step Subprocess(NodeRegistered),
|
|
4
|
+
input: ->(_ctx, node_name:, **) {{
|
|
5
|
+
node_name: node_name
|
|
6
|
+
}},
|
|
7
|
+
id: :node_registered
|
|
8
|
+
|
|
9
|
+
step :verify_role
|
|
10
|
+
|
|
11
|
+
def verify_role(ctx, node_name:, output:, **)
|
|
12
|
+
match = output.match(/^\s+[0-9]{1,}\s+\|\s+db1\s+\|\s+([^\s]+)\s+\|/)
|
|
13
|
+
return false unless match
|
|
14
|
+
|
|
15
|
+
ctx[:node_role] = match[1]
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
node_id=<%= node_id %>
|
|
2
|
+
node_name='<%= node_name %>'
|
|
3
|
+
conninfo='host=<%= primary_host %> user=<%= primary_user %> dbname=<%= primary_database %> connect_timeout=2'
|
|
4
|
+
data_directory='/var/lib/postgresql/<%= postgres_version %>/main'
|
|
5
|
+
|
|
6
|
+
use_replication_slots=yes
|
|
7
|
+
monitoring_history=yes
|
|
8
|
+
|
|
9
|
+
service_start_command = 'sudo /usr/bin/pg_ctlcluster <%= postgres_version %> main start'
|
|
10
|
+
service_stop_command = 'sudo /usr/bin/pg_ctlcluster <%= postgres_version %> main stop'
|
|
11
|
+
service_restart_command = 'sudo /usr/bin/pg_ctlcluster <%= postgres_version %> main restart'
|
|
12
|
+
service_reload_command = 'sudo /usr/bin/pg_ctlcluster <%= postgres_version %> main reload'
|
|
13
|
+
service_promote_command = 'sudo /usr/bin/pg_ctlcluster <%= postgres_version %> main promote'
|
|
14
|
+
|
|
15
|
+
promote_check_timeout = 15
|
|
16
|
+
|
|
17
|
+
failover=automatic
|
|
18
|
+
promote_command='/usr/bin/repmgr standby promote -f /etc/repmgr.conf --log-to-file'
|
|
19
|
+
follow_command='/usr/bin/repmgr standby follow -f /etc/repmgr.conf --log-to-file --upstream-node-id=%n'
|
|
20
|
+
|
|
21
|
+
log_file='/var/log/postgresql/repmgrd.log'
|
|
22
|
+
|
|
23
|
+
<% if use_barman? %>
|
|
24
|
+
barman_host='<%= barman_user %>@<%= barman_host %>'
|
|
25
|
+
barman_server='<%= barman_host %>'
|
|
26
|
+
restore_command='/usr/bin/barman-wal-restore <%= barman_host %> <%= barman_server %> %f %p'
|
|
27
|
+
<% end %>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require_relative "./settings_loader_monkeypatch"
|
|
2
|
+
|
|
3
|
+
module Caco
|
|
4
|
+
class SettingsLoader < Trailblazer::Operation
|
|
5
|
+
step :setup_validate_params
|
|
6
|
+
step :config_setup
|
|
7
|
+
step :hiera_setup_keys
|
|
8
|
+
step :set_caco_eyaml_parser
|
|
9
|
+
step :facter_needed_values
|
|
10
|
+
step :config_load
|
|
11
|
+
step :custom_config
|
|
12
|
+
|
|
13
|
+
def setup_validate_params(ctx, keys_path: nil, data_path: nil, **)
|
|
14
|
+
ctx[:keys_path] = !keys_path.nil? ? Pathname.new(keys_path) : Pathname.new(Caco.root.join("keys"))
|
|
15
|
+
ctx[:data_path] = !data_path.nil? ? Pathname.new(data_path) : Pathname.new(Caco.root.join("data"))
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def config_setup(ctx, **)
|
|
19
|
+
Config.setup do |config|
|
|
20
|
+
config.const_name = 'Settings'
|
|
21
|
+
config.use_env = true
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def hiera_setup_keys(ctx, keys_path:, **)
|
|
26
|
+
Hiera::Backend::Eyaml::Options[:pkcs7_public_key] = keys_path.join("public_key.pkcs7.pem")
|
|
27
|
+
Hiera::Backend::Eyaml::Options[:pkcs7_private_key] = keys_path.join("private_key.pkcs7.pem")
|
|
28
|
+
ctx[:parser] = Hiera::Backend::Eyaml::Parser::ParserFactory.encrypted_parser
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def set_caco_eyaml_parser(ctx, parser:, **)
|
|
32
|
+
Caco.configure do |config|
|
|
33
|
+
config.eyaml_parser = parser
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def facter_needed_values(ctx, **)
|
|
38
|
+
ctx[:facts] = {}
|
|
39
|
+
ctx[:facts][:facter_kernel] = Caco::Facter.("kernel")
|
|
40
|
+
ctx[:facts][:facter_os_name] = Caco::Facter.("os", "name")
|
|
41
|
+
ctx[:facts][:facter_distro_codename] = (ctx[:facts][:facter_kernel] == "Linux" ? Caco::Facter.("os", "distro", "codename") : nil)
|
|
42
|
+
ctx[:facts][:facter_release_full] = Caco::Facter.("os", "release", "full")
|
|
43
|
+
ctx[:facts][:facter_release_major] = Caco::Facter.("os", "release", "major")
|
|
44
|
+
ctx[:facts][:facter_release_minor] = Caco::Facter.("os", "release", "minor")
|
|
45
|
+
ctx[:facts][:facter_fqdn] = Caco::Facter.("networking", "fqdn")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def config_load(ctx, facts:, data_path:, **)
|
|
49
|
+
# From more generic to specific
|
|
50
|
+
Config.load_and_set_settings(
|
|
51
|
+
data_path.join("common.yaml"),
|
|
52
|
+
data_path.join("os", "#{facts[:facter_os_name]}.yaml"),
|
|
53
|
+
data_path.join("os", "#{facts[:facter_os_name]}", "#{facts[:facter_distro_codename]}.yaml"),
|
|
54
|
+
# maybe add some organizations here?
|
|
55
|
+
# maybe add some roles here?
|
|
56
|
+
data_path.join("nodes", "#{facts[:facter_fqdn]}"),
|
|
57
|
+
)
|
|
58
|
+
Settings.reload!
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def custom_config(ctx, **)
|
|
62
|
+
Settings.prometheus = Config::Options.new
|
|
63
|
+
Settings.prometheus.root = "/opt/prometheus"
|
|
64
|
+
Settings.prometheus.config_root = "/etc/prometheus"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|