Skip to content

Commit

Permalink
Move the recovery.conf based role check to a function.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyklyukin committed Apr 15, 2016
1 parent c15c138 commit a07b015
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions patroni/postgresql.py
Expand Up @@ -79,7 +79,7 @@ def __init__(self, config):

self._state = 'stopped'
self._state_lock = Lock()
self._role = 'replica' if os.path.exists(self.recovery_conf) else 'master'
self._role = self.get_postgres_role_from_data_directory()
self._role_lock = Lock()

if self.is_running():
Expand Down Expand Up @@ -124,6 +124,9 @@ def get_local_address(self):
break
return local_address + ':' + self.port

def get_postgres_role_from_data_directory(self):
return 'replica' if os.path.exists(self.recovery_conf) else 'master'

@property
def _connect_kwargs(self):
r = parseurl('postgres://{0}/postgres'.format(self.local_address))
Expand Down Expand Up @@ -347,7 +350,7 @@ def start(self, block_callbacks=False):
logger.error('Cannot start PostgreSQL because one is already running.')
return True

self.set_role('replica' if os.path.exists(self.recovery_conf) else 'master')
self.set_role(self.get_postgres_role_from_data_directory())
if os.path.exists(self.postmaster_pid):
os.remove(self.postmaster_pid)
logger.info('Removed %s', self.postmaster_pid)
Expand Down

0 comments on commit a07b015

Please sign in to comment.