diff options
Diffstat (limited to 'postgresql-prep')
8 files changed, 186 insertions, 36 deletions
diff --git a/postgresql-prep/src/common/postinst b/postgresql-prep/src/common/postinst index 63a76f2..bad825b 100755 --- a/postgresql-prep/src/common/postinst +++ b/postgresql-prep/src/common/postinst @@ -37,23 +37,32 @@ id umask 022 TMP=$( mktemp /tmp/pgprep.$$.XXXXXXXXXX ) -#### TODO remove comment trap 'rm -f $TMP' 0 1 2 3 15 +trap 'rm -f $TMP' 0 1 2 3 15 if $OPENECOMP then INSTALL_ROOT= fi -if [ -f /tmp/postgres.conf ] -then +CONFDIR=/var/config/DCAE/chef +CONFCOUNT=$(ls $CONFDIR/*-postgres.conf 2>/dev/null | wc -l) +case "$CONFCOUNT" in +1 ) + # master: masternode + # master2: secondmasternode + # in DCAE, these values could be in postgres.conf or already in the environment # DRTR_NODE_KSTOREFILE: /opt/app/dcae-certificate/keystore.jks # DRTR_NODE_KSTOREPASS: "No Certificate" # DRTR_NODE_PVTKEYPASS: "No Certificate" # PG_NODES : uiopmno1qwpstg00.research.example.com|asbczw1vepstg00.dcae.simpledemo.openecomp.org # PG_JAVA_HOME : /opt/app/java/jdk/jdk170 # PG_CLUSTER : global - sed -e 's/ *: */="/' -e 's/$/"/' -e 's/=""/="/' -e 's/""$/"/' < /tmp/postgres.conf > $TMP + sed -e 's/ *: */="/' -e 's/[ ]*$/"/' -e 's/=""/="/' -e 's/""$/"/' < /tmp/postgres.conf > $TMP . $TMP -fi + ;; +0 ) ;; +* ) + die "More than one postgres.conf was found: $(ls $CONFDIR/*-postgres.conf 2>&1)" +esac [ -n "$PG_NODES" ] || die "PG_NODES is not set" [ -n "$PG_CLUSTER" ] || die "PG_CLUSTER is not set" @@ -88,7 +97,9 @@ chown -R postgres:postgres ${INSTALL_ROOT}/dbroot ${INSTALL_ROOT}/var/run/postgr chmod 711 ~postgres # fix up the CDF package so that it works -ln -sf /opt/app/cdf /opt/cdf +if [ ! -L /opt/cdf ] +then rm -f /opt/cdf; ln -sf /opt/app/cdf /opt/cdf +fi # and save some values within ( diff --git a/postgresql-prep/src/makefile b/postgresql-prep/src/makefile index 9999fa6..86831d1 100644 --- a/postgresql-prep/src/makefile +++ b/postgresql-prep/src/makefile @@ -1,7 +1,6 @@ DEVBIN=../../bin PKG=postgresql-prep -REPACKAGESWMOPTS= REPACKAGEDEBIANOPTS= INS= ../install @@ -33,13 +32,9 @@ stage: clean-stage clean-common testlock/testlock cp -p repackage.* $(INS) -debian-verify: stage - repackage -b debian $(REPACKAGEDEBIANOPTS) -d $(INS) - @echo debian verify built - debian: stage - repackage -y repackage.json -b debian -d $(INS) -u - # repackage -y repackage.json -b debian -d $(INS) -u -B LATEST + repackage -b debian -d $(INS) -u + repackage -b debian -d $(INS) -u -B LATEST @echo debian built upload-javadocs: diff --git a/postgresql-prep/src/repackage.json b/postgresql-prep/src/repackage.json index 94874ed..3b8248d 100644 --- a/postgresql-prep/src/repackage.json +++ b/postgresql-prep/src/repackage.json @@ -1,29 +1,29 @@ { - "description": " PostgreSQL as a Service main scripts ", - "fileGroup": "root", - "groupId": "org.openecomp.dcae.storage.pgaas", - "fileUser": "root", - "executionGroup": "root", - "executionUser": "root", - "internalDependencies": [], - "maintainer": "OpenECOMP <dcae@lists.openecomp.org>", - "docker": { - "tag": "latest", - "externalDependencies": [] - }, "applicationName": "postgresql-prep", "debian": { - "groupId": "org.openecomp.dcae.storage.pgaas", + "conflicts": [], "externalDependencies": [ { "cdf": ">= 1.1.0" } ], - "replaces": [], - "conflicts": [] + "groupId": "org.openecomp.dcae.storage.pgaas", + "replaces": [] }, - "version": "1.1.0", + "description": " PostgreSQL as a Service main scripts ", "directoryTreeTops": { "/opt": "/opt/app/postgresql-prep" - } -} + }, + "docker": { + "externalDependencies": [], + "tag": "latest" + }, + "executionGroup": "root", + "executionUser": "root", + "fileGroup": "root", + "fileUser": "root", + "groupId": "org.openecomp.dcae.storage.pgaas", + "internalDependencies": [], + "maintainer": "OpenECOMP <dcae@lists.openecomp.org>", + "version": "1.1.0" +}
\ No newline at end of file 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 |