Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f279dac

Browse files
committed
init.yml started, shardlord elections.
1 parent 646e440 commit f279dac

File tree

6 files changed

+53
-2
lines changed

6 files changed

+53
-2
lines changed
File renamed without changes.

ec2/init.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
### initdb and send configs
2+
3+
---
4+
- hosts: nodes
5+
6+
environment:
7+
PATH: "{{ pg_dst }}/bin:{{ ansible_env.PATH }}"
8+
9+
tasks:
10+
- name: pkill pg
11+
shell: 'pkill -9 postgres || true'
12+
13+
- name: remove datadirs on datanodes
14+
file: path={{pg_datadir}} state=absent
15+
16+
- name: create datadirs on datanodes
17+
command: "initdb {{pg_datadir}}"

ec2/inventory/ec2_elect_shardlord.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
3+
'''
4+
Run ec2.py stored in .. directory and appends ec2_shardlord ec2_workers groups
5+
to it.
6+
'''
7+
8+
import os
9+
import subprocess
10+
import json
11+
import socket
12+
13+
def ec2_elect_shardlord():
14+
script_dir = os.path.dirname(os.path.realpath(__file__))
15+
ec2_path = os.path.join(os.path.dirname(script_dir), "ec2.py")
16+
ec2_inv_txt = subprocess.check_output([ec2_path, "--list"])
17+
ec2_inv = json.loads(ec2_inv_txt)
18+
hosts = list(ec2_inv["_meta"]["hostvars"].keys())
19+
# sort to choose the same shardlord each time
20+
hosts.sort(key = socket.inet_aton)
21+
shardlord, workers = [hosts[0]], hosts[1:]
22+
ec2_inv["ec2_shardlord"] = shardlord
23+
ec2_inv["ec2_workers"] = workers
24+
print json.dumps(ec2_inv, sort_keys=True, indent=2)
25+
26+
27+
if __name__ == '__main__':
28+
# Run the script
29+
ec2_elect_shardlord()

ec2/inventory/inventory

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pg_prefix="{{ansible_env.HOME}}/pg"
1616
pg_src="{{pg_prefix}}/src"
1717
pg_dst="{{pg_prefix}}/install"
1818
pg_datadir="{{pg_prefix}}/data_{{pg_port}}"
19+
pg_logfile="{{pg_datadir}}/pg.log"
1920
pg_port=5432
2021

2122
pathman_repo=https://github.com/postgrespro/pg_pathman.git
@@ -41,4 +42,4 @@ ansible_ssh_private_key_file=~/.ssh/aws_rsa
4142

4243
# For local development
4344
[vagrant]
44-
10.42.42.10
45+
# 10.42.42.10

ec2/provision.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
### Build & install from sources PG, pg_pathman and pg_shardman
2+
13
---
24
- hosts: nodes
35

ec2/readme.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ chmod 0400 ~/.ssh/aws_rsa
33

44
install python packages for ec2.py: (venv is recommended):
55
python3 -m venv ~/venv/aws
6-
source ~/venv/aws/bin/activate
6+
As of writing this, python 3.5 has a nasty bug, so better use python 2:
7+
virtualenv -p /usr/bin/python ~/venv/aws_2.7
8+
source ~/venv/aws_2.7/bin/activate
79
pip install boto boto3 six ansible
810

911
Download and set up ec2.ini:

0 commit comments

Comments
 (0)