Merge branch 'master' of github.com:zalando/patroni into feature/watch-leader-key

This commit is contained in:
Alexander Kukushkin
2015-09-02 13:28:14 +02:00
8 changed files with 38 additions and 26 deletions
+2 -1
View File
@@ -13,7 +13,8 @@ RUN apt-get update -y
RUN apt-get upgrade -y
ENV PGVERSION 9.4
RUN apt-get install python python-psycopg2 python-yaml python-requests python-boto postgresql-${PGVERSION} python-dnspython python-kazoo -y
RUN apt-get install python python-psycopg2 python-yaml python-requests python-boto postgresql-${PGVERSION} python-dnspython python-kazoo python-pip -y
RUN pip install python-etcd
ENV PATH /usr/lib/postgresql/${PGVERSION}/bin:$PATH
+7 -7
View File
@@ -1,6 +1,6 @@
# Patroni Dockerfile
You can run Patroni in a docker container using this Dockerfile, or by using the Docker image at
https://os-registry.stups.zalan.do/acid/patroni-1.0
https://os-registry.stups.zalan.do/acid/patroni-1.0-SNAPSHOT
This Dockerfile is meant in aiding development of Patroni and quick testing of features. It is not a production-worthy
Dockerfile
@@ -9,7 +9,7 @@ Dockerfile
## Standalone Patroni
docker run -d os-registry.stups.zalan.do/acid/patroni:1.0
docker run -d os-registry.stups.zalan.do/acid/patroni:1.0-SNAPSHOT
## Multiple Patroni's communicating with a standalone etcd inside Docker
@@ -35,12 +35,12 @@ To automate this you can run the following script:
Example session:
$ ./dev_patroni_cluster.sh --image os-registry.stups.zalan.do/acid/patroni:1.0 --members=2 --name=bravo
The etcd container is 6be871a11cb373406ca5ea1c6b39e140fdde9fb1d6177212d6ad0c0d1bd9b563, ip=172.17.1.24
$ ./dev_patroni_cluster.sh --image os-registry.stups.zalan.do/acid/patroni:1.0-SNAPSHOT --members=2 --name=bravo
The etcd container is 6be871a11cb373406ca5ea1c6b39e1.0-SNAPSHOTfdde9fb1d6177212d6ad0c0d1bd9b563, ip=172.17.1.24
Started Patroni container 67e611f2eca7c40f9e6e0e24a4a8f2cba7e3e56d22a420e15ab9240a37a9d7a4, ip=172.17.1.25
Started Patroni container 47dd12ae635ab83b039f5889e250048b606ed5e48e3650b69e365e7e1d4acbcf, ip=172.17.1.26
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
47dd12ae635a os-registry.stups.zalan.do/acid/patroni:1.0 "/bin/bash /entrypoi 10 seconds ago Up 8 seconds 4001/tcp, 5432/tcp, 2380/tcp bravo_OR64g8bx
67e611f2eca7 os-registry.stups.zalan.do/acid/patroni:1.0 "/bin/bash /entrypoi 11 seconds ago Up 10 seconds 2380/tcp, 4001/tcp, 5432/tcp bravo_si9no8iz
6be871a11cb3 os-registry.stups.zalan.do/acid/patroni:1.0 "/bin/bash /entrypoi 12 seconds ago Up 10 seconds 4001/tcp, 5432/tcp, 2380/tcp bravo_etcd
47dd12ae635a os-registry.stups.zalan.do/acid/patroni:1.0-SNAPSHOT "/bin/bash /entrypoi 10 seconds ago Up 8 seconds 4001/tcp, 5432/tcp, 2380/tcp bravo_OR64g8bx
67e611f2eca7 os-registry.stups.zalan.do/acid/patroni:1.0-SNAPSHOT "/bin/bash /entrypoi 11 seconds ago Up 10 seconds 2380/tcp, 4001/tcp, 5432/tcp bravo_si9no8iz
6be871a11cb3 os-registry.stups.zalan.do/acid/patroni:1.0-SNAPSHOT "/bin/bash /entrypoi 12 seconds ago Up 10 seconds 4001/tcp, 5432/tcp, 2380/tcp bravo_etcd
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/bash
DOCKER_IMAGE="os-registry.stups.zalan.do/acid/patroni:1.0"
DOCKER_IMAGE="os-registry.stups.zalan.do/acid/patroni:1.0-SNAPSHOT"
MEMBERS=3
+1 -1
View File
@@ -354,7 +354,7 @@ primary_conninfo = '{}'
self.query('CREATE ROLE "{0}" WITH LOGIN SUPERUSER PASSWORD %s'.format(
self.superuser['username']), self.superuser['password'])
else:
self.query('ALTER ROLE postgres WITH PASSWORD %s', self.superuser['password'])
self.query('ALTER ROLE "{0}" WITH PASSWORD %s'.format(os.environ['USER']), self.superuser['password'])
if self.admin:
self.query('CREATE ROLE "{0}" WITH LOGIN CREATEDB CREATEROLE PASSWORD %s'.format(
self.admin['username']), self.admin['password'])
+23 -14
View File
@@ -5,7 +5,8 @@ import signal
import sys
import time
received_sigchld = False
interrupted_sleep = False
reap_children = False
_DATE_TIME_RE = re.compile(r'''^
(?P<year>\d{4})\-(?P<month>\d{2})\-(?P<day>\d{2}) # date
@@ -72,30 +73,38 @@ def sigterm_handler(signo, stack_frame):
def sigchld_handler(signo, stack_frame):
global received_sigchld
received_sigchld = True
try:
while True:
ret = os.waitpid(-1, os.WNOHANG)
if ret == (0, 0):
break
except OSError:
pass
global interrupted_sleep, reap_children
reap_children = interrupted_sleep = True
def sleep(interval):
global received_sigchld
global interrupted_sleep
current_time = time.time()
end_time = current_time + interval
while current_time < end_time:
received_sigchld = False
interrupted_sleep = False
time.sleep(end_time - current_time)
if not received_sigchld: # we will ignore only sigchld
if not interrupted_sleep: # we will ignore only sigchld
break
current_time = time.time()
received_sigchld = False
interrupted_sleep = False
def setup_signal_handlers():
signal.signal(signal.SIGTERM, sigterm_handler)
signal.signal(signal.SIGCHLD, sigchld_handler)
def reap_children():
global reap_children
if reap_children:
try:
while True:
ret = os.waitpid(-1, os.WNOHANG)
print ret
if ret == (0, 0):
break
except OSError:
pass
finally:
reap_children = False
+2 -1
View File
@@ -9,7 +9,7 @@ from helpers.api import RestApiServer
from helpers.etcd import Etcd
from helpers.ha import Ha
from helpers.postgresql import Postgresql
from helpers.utils import setup_signal_handlers, sleep
from helpers.utils import setup_signal_handlers, sleep, reap_children
from helpers.zookeeper import ZooKeeper
logger = logging.getLogger(__name__)
@@ -95,6 +95,7 @@ class Patroni:
except:
logger.exception('Exception when changing replication slots')
self.schedule_next_run()
reap_children()
def main():
+1 -1
View File
@@ -46,7 +46,7 @@ postgresql:
env_dir: /home/postgres/etc/wal-e.d/env
threshold_megabytes: 10240
threshold_backup_size_percentage: 30
restore: "true"
restore: scripts/restore.py
#recovery_conf:
#restore_command: cp ../wal_archive/%f %p
parameters:
+1
View File
@@ -48,6 +48,7 @@ postgresql:
env_dir: /home/postgres/etc/wal-e.d/env
threshold_megabytes: 10240
threshold_backup_size_percentage: 30
restore: scripts/restore.py
parameters:
archive_mode: "on"
wal_level: hot_standby