Skip to content

Commit

Permalink
Adds pg_hba.conf template support
Browse files Browse the repository at this point in the history
  • Loading branch information
miketonks committed Jul 24, 2015
1 parent eca41f0 commit d289584
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions governor.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def shutdown():
time.sleep(5)
else:
logging.info("Governor Starting up: Existing Data Dir")
postgresql.copy_pg_hba()
postgresql.follow_no_leader()
logging.info("Governor Starting up: Starting Postgres")
postgresql.start(master=False)
Expand Down
13 changes: 11 additions & 2 deletions helpers/postgresql.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, psycopg2, re, time
import os, psycopg2, re, time, shutil
import logging

from urlparse import urlparse
Expand Down Expand Up @@ -69,7 +69,8 @@ def data_directory_empty(self):

def initialize(self):
if os.system("initdb -D %s" % self.data_dir) == 0:
self.write_pg_hba()
#self.write_pg_hba()
self.copy_pg_hba()
self.start()
self.create_replication_user()
self.stop()
Expand Down Expand Up @@ -191,6 +192,14 @@ def write_pg_hba(self):
{"username": self.replication["username"], "network": self.replication["network"]})
f.close()

def copy_pg_hba(self):
if os.path.exists('pg_hba.conf'):
logger.info("Copying pg_hba.conf file")
shutil.copy2('pg_hba.conf', self.data_dir)
else:
logger.info("No pg_hba.conf file found - skipping")


def write_recovery_conf(self, leader_hash):
f = open("%s/recovery.conf" % self.data_dir, "w")
f.write("""
Expand Down
14 changes: 14 additions & 0 deletions pg_hba.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# TYPE DATABASE USER ADDRESS METHOD

# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust

# Replication user
host replication replicator 10.0.3.1/24 md5

# Application users with md5 password
host all all 10.0.3.1/24 md5

0 comments on commit d289584

Please sign in to comment.