aboutsummaryrefslogtreecommitdiffstats
path: root/postgresql-prep/src/stage
diff options
context:
space:
mode:
Diffstat (limited to 'postgresql-prep/src/stage')
-rwxr-xr-xpostgresql-prep/src/stage/opt/app/postgresql-prep/bin/iDNS-responder.py23
-rw-r--r--postgresql-prep/src/stage/opt/app/postgresql-prep/init/pglogs.cron2
-rw-r--r--postgresql-prep/src/stage/opt/app/postgresql-prep/init/systemd-pgaas-idns.service3
-rw-r--r--postgresql-prep/src/stage/opt/app/postgresql-prep/man/iDNS-responder.swagger.json58
-rw-r--r--postgresql-prep/src/stage/opt/app/postgresql-prep/man/iDNS-responder.swagger.yaml68
5 files changed, 149 insertions, 5 deletions
diff --git a/postgresql-prep/src/stage/opt/app/postgresql-prep/bin/iDNS-responder.py b/postgresql-prep/src/stage/opt/app/postgresql-prep/bin/iDNS-responder.py
index b6c5174..14c16b3 100755
--- a/postgresql-prep/src/stage/opt/app/postgresql-prep/bin/iDNS-responder.py
+++ b/postgresql-prep/src/stage/opt/app/postgresql-prep/bin/iDNS-responder.py
@@ -445,10 +445,16 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
elif self.path == '/isrw':
isrw = readFile("/var/run/postgresql/isrw", "n/a")
- debugTrace("/rw: isrw returns %s" % isrw)
+ debugTrace("/isrw: returns %s" % isrw)
resp = 200
msg = isrw
+ elif self.path == '/healthcheck/status':
+ hs = readFile("/var/run/postgresql/check_cluster", "n/a")
+ debugTrace("/healthcheck/status: returns %s" % hs)
+ resp = 429 if hs == "n/a" else 200
+ msg = '{ "output": "' + re.sub('"', "'", re.sub("\n", " ", hs)) + '" }'
+
elif not self.checkAuth():
resp = 401
msg = "not authenticated"
@@ -471,10 +477,18 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
else:
msg = "non-secondary server"
+ elif self.path == '/ismaintenance':
+ msg = ""
+ if os.path.exists("/var/run/postgresql/inmaintenance"):
+ resp = 200
+ msg = "in maintenance mode"
+ else:
+ msg = "not in maintenance mode"
+
elif self.path == '/getpubkey':
try:
resp = 200
- msg = readFile("/home/postgres/.ssh/id_rsa.pub")
+ msg = readFile(os.path.expanduser("~postgres/.ssh/id_rsa.pub"))
except:
traceback.print_exc()
resp = 404
@@ -487,7 +501,7 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
host = re.sub("[^a-zA-Z0-9_.-]", "", host)
debugTrace("#2: /getssh/ host='%s'" % host)
if self.isValidPgHost(host):
- p = readPipe("scp -o StrictHostKeyChecking=no ~postgres/.ssh/id_rsa* " + host + ":.ssh/ 2>&1")
+ p = readPipe("scp -o StrictHostKeyChecking=no -i ~postgres/.ssh/id_rsa ~postgres/.ssh/id_rsa* postgres@" + host + ":.ssh/ 2>&1")
debugTrace("#3: /getssh/ to '%s' returns '%s'" % (host, p))
msg = "OK " + p
resp = 200
@@ -505,7 +519,7 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
host = re.sub("[^a-zA-Z0-9_.-]", "", host)
debugTrace("#2: /getcdf/ host='%s'" % host)
if self.isValidPgHost(host):
- p = readPipe("scp -o StrictHostKeyChecking=no " + fi + " " + host + ":/opt/app/cdf/lib/cdf.cfg 2>&1")
+ p = readPipe("scp -o StrictHostKeyChecking=no -i ~postgres/.ssh/id_rsa " + fi + " postgres@" + host + ":/opt/app/cdf/lib/cdf.cfg 2>&1")
debugTrace("#3: /getcdf/ to '%s' returns '%s'" % (host, p))
msg = "OK " + p
resp = 200
@@ -842,6 +856,7 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
<a href='/isrw'>isrw</a> == /var/run/postgresql/isrw
<a href='/ismaster'>ismaster</a> == is master
<a href='/issecondary'>issecondary</a> == is secondary
+ <a href='/ismaintenance'>ismaintenance</a> == is in maintenance mode
<a href='/getpubkey'>getpubkey</a> == retrieve public key
<a href='/hasrepmgr'>hasrepmgr</a> == repmgr id and database are set up
<a href='/status'>status</a> == lots of info
diff --git a/postgresql-prep/src/stage/opt/app/postgresql-prep/init/pglogs.cron b/postgresql-prep/src/stage/opt/app/postgresql-prep/init/pglogs.cron
index e905633..e08e403 100644
--- a/postgresql-prep/src/stage/opt/app/postgresql-prep/init/pglogs.cron
+++ b/postgresql-prep/src/stage/opt/app/postgresql-prep/init/pglogs.cron
@@ -1,4 +1,4 @@
30 * * * * ( date ; find /dbroot/pglogs -type f -mtime +3 -exec rm {} + ) >> /tmp/cleanpglogs.log 2>&1
50 1 * * * ( mv -f /tmp/cleanpglogs.log /tmp/cleanpglogs.log.old ) > /dev/null 2>&1
* * * * * [ -x /opt/app/pgaas/bin/update_var_run_isrw ] && /opt/app/pgaas/bin/update_var_run_isrw
-* * * * * [ -x /opt/app/pgaas/bin/check_cluster ] && /opt/app/pgaas/bin/check_cluster >> /opt/app/log/postgresql/idns/cluster.log
+* * * * * [ -x /opt/app/pgaas/bin/check_cluster ] && /opt/app/pgaas/bin/check_cluster -d /var/run/postgresql/check_cluster >> /opt/app/log/postgresql/idns/cluster.log
diff --git a/postgresql-prep/src/stage/opt/app/postgresql-prep/init/systemd-pgaas-idns.service b/postgresql-prep/src/stage/opt/app/postgresql-prep/init/systemd-pgaas-idns.service
index bbc28ea..8b9c84e 100644
--- a/postgresql-prep/src/stage/opt/app/postgresql-prep/init/systemd-pgaas-idns.service
+++ b/postgresql-prep/src/stage/opt/app/postgresql-prep/init/systemd-pgaas-idns.service
@@ -6,7 +6,10 @@
Description=PGaaS iDNS server
[Service]
+User=postgres
+Group=postgres
ExecStart= /opt/app/postgresql-prep/bin/iDNS-responder.py
+Restart=on-failure
[Install]
WantedBy=multi-user.target
diff --git a/postgresql-prep/src/stage/opt/app/postgresql-prep/man/iDNS-responder.swagger.json b/postgresql-prep/src/stage/opt/app/postgresql-prep/man/iDNS-responder.swagger.json
new file mode 100644
index 0000000..2b59cda
--- /dev/null
+++ b/postgresql-prep/src/stage/opt/app/postgresql-prep/man/iDNS-responder.swagger.json
@@ -0,0 +1,58 @@
+{
+ "swagger": "2.0",
+ "info": {
+ "version": "1.1.0",
+ "title": "PostgreSQL as a Service REST API"
+ },
+ "paths": {
+ "/rw": {
+ "get": {
+ "description": "Gets a string indicating if this is a PostgreSQL Master server\n",
+ "responses": {
+ "200": {
+ "description": "Successful response",
+ "schema": {
+ "title": "status",
+ "type": "string"
+ }
+ }
+ }
+ }
+ },
+ "/ro": {
+ "get": {
+ "description": "Gets a string indicating if this is either a PostgreSQL Master or Secondary server\n",
+ "responses": {
+ "200": {
+ "description": "Successful response",
+ "schema": {
+ "title": "status",
+ "type": "string"
+ }
+ }
+ }
+ }
+ },
+ "/healthcheck/status": {
+ "get": {
+ "description": "Gets a string indicating the status of this server\n",
+ "responses": {
+ "200": {
+ "description": "Successful response",
+ "schema": {
+ "title": "output",
+ "type": "string"
+ }
+ },
+ "429": {
+ "description": "Error response",
+ "schema": {
+ "title": "output",
+ "type": "string"
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/postgresql-prep/src/stage/opt/app/postgresql-prep/man/iDNS-responder.swagger.yaml b/postgresql-prep/src/stage/opt/app/postgresql-prep/man/iDNS-responder.swagger.yaml
new file mode 100644
index 0000000..5f3ffee
--- /dev/null
+++ b/postgresql-prep/src/stage/opt/app/postgresql-prep/man/iDNS-responder.swagger.yaml
@@ -0,0 +1,68 @@
+# Example YAML to get you started quickly.
+# Be aware that YAML has indentation based scoping.
+# Code completion support is available so start typing for available options.
+swagger: '2.0'
+
+# This is your document metadata
+info:
+ version: "1.1.0"
+ title: PostgreSQL as a Service REST API
+
+# Describe your paths here
+paths:
+ # This is a path endpoint. Change it.
+ /rw:
+ # This is a HTTP operation
+ get:
+ # Describe this verb here. Note: you can use markdown
+ description: |
+ Gets a string indicating if this is a PostgreSQL Master server
+ # Expected responses for this operation:
+ responses:
+ # Response code
+ 200:
+ description: Successful response
+ # A schema describing your response object.
+ # Use JSON Schema format
+ schema:
+ title: status
+ type: string
+ /ro:
+ # This is a HTTP operation
+ get:
+ # Describe this verb here. Note: you can use markdown
+ description: |
+ Gets a string indicating if this is either a PostgreSQL Master or Secondary server
+ # Expected responses for this operation:
+ responses:
+ # Response code
+ 200:
+ description: Successful response
+ # A schema describing your response object.
+ # Use JSON Schema format
+ schema:
+ title: status
+ type: string
+ /healthcheck/status:
+ # This is a HTTP operation
+ get:
+ # Describe this verb here. Note: you can use markdown
+ description: |
+ Gets a string indicating the status of this server
+ # Expected responses for this operation:
+ responses:
+ # Response code
+ 200:
+ description: Successful response
+ # A schema describing your response object.
+ # Use JSON Schema format
+ schema:
+ title: output
+ type: string
+ 429:
+ description: Error response
+ # A schema describing your response object.
+ # Use JSON Schema format
+ schema:
+ title: output
+ type: string