-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
72 lines (58 loc) · 2.13 KB
/
Makefile
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
.PHONY: help
help:
@printf "Commands:\n"
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
repmgr: ## run repmgr commands with the form of `make repmgr CMD=""`
@NODES=$$(docker-compose ps -q); \
for node in $${NODES}; do \
name=$$(docker inspect $${node} | jq -crM '.[0] | .Id[0:12]'); \
resp=$$(docker exec -iu postgres $${node} repmgr $(CMD) 2>&1); \
if [[ "$$resp" != *"is not running"* ]]; then \
echo "------> $${name} <-------" \
&& echo "$$resp" \
&& break; \
fi; \
done
status: ## display information about each registered node in the replication cluster
@$(MAKE) repmgr CMD="cluster show"
daemon-status: ## display information about the status of repmgrd on each node in the cluster
@$(MAKE) repmgr CMD="daemon status"
crosscheck: ## cross-checks connections between each combination of nodes
@$(MAKE) repmgr CMD="cluster crosscheck"
cluster-cleanup: ## purge monitoring history
@$(MAKE) repmgr CMD="cluster cleanup"
build: ## build postgresql node image
@docker-compose build
up: ## create and start a single node (usually the first one)
@docker-compose up -d
clean: ## stop and delete all the nodes and current deploy
@docker-compose down -v -t 5 --remove-orphans
@echo -n '' > cluster_members
logs: ## tail logs of all nodes
@while true; do trap 'break' SIGINT; docker-compose logs -f; done
ssh: ## share ssh public keys between each node
@./share-keys.sh
add-node: ## add another node to the cluster
@n_nodes=$$(docker-compose ps \
| grep -E "node_[0-9]+" \
| sed -E 's/\s+/ /g' \
| cut -f1 -d' ' \
| sort -r \
| head -n 1 \
| sed -E 's/.*_//g'); \
desired_nodes=$$(($${n_nodes} + 1)); \
docker-compose up -d --scale pg-node=$${desired_nodes}
del-node: ## delete one node from the cluster
@n_nodes=$$(docker-compose ps \
| grep -E "node_[0-9]+" \
| sed -E 's/\s+/ /g' \
| cut -f1 -d' ' \
| sort -r \
| head -n 1 \
| sed -E 's/.*_//g'); \
desired_nodes=$$(($${n_nodes} - 1)); \
docker-compose up -d --scale pg-node=$${desired_nodes}; \
docker-compose exec -u postgres pg-node \
repmgr standby unregister --node-id=$${n_nodes}
%:
@: