Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Commit

Permalink
stop postgresql if receiving SIGTERM
Browse files Browse the repository at this point in the history
  • Loading branch information
Claus Riegg committed Feb 16, 2018
1 parent a0ebe86 commit d9d257a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion governor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

import sys, os, yaml, time, urllib2, atexit, ssl
import sys, os, yaml, time, urllib2, atexit, ssl, signal
import logging

from helpers.etcd import Etcd
Expand Down Expand Up @@ -28,12 +28,17 @@ def wait_for_etcd(message, etcd, postgresql):
logging.info("waiting on etcd: %s" % message)
time.sleep(5)

def signalhandler(signum, frame):
print('Received ', signum)
stop_postgresql(postgresql)

def run(config):
etcd = Etcd(config["etcd"])
postgresql = Postgresql(config["postgresql"])
ha = Ha(postgresql, etcd)

atexit.register(stop_postgresql, postgresql)
signal.signal(signal.SIGTERM, signalhandler)
logging.info("Governor Starting up")
# is data directory empty?
if postgresql.data_directory_empty():
Expand Down

0 comments on commit d9d257a

Please sign in to comment.