diff --git a/openshift/templates/django-postgresql.json b/openshift/templates/django-postgresql.json index c6cdacc..647f721 100644 --- a/openshift/templates/django-postgresql.json +++ b/openshift/templates/django-postgresql.json @@ -164,6 +164,22 @@ "containerPort": 8080 } ], + "readinessProbe": { + "timeoutSeconds": 3, + "initialDelaySeconds": 3, + "httpGet": { + "path": "/health", + "port": 8080 + } + }, + "livenessProbe": { + "timeoutSeconds": 3, + "initialDelaySeconds": 30, + "httpGet": { + "path": "/health", + "port": 8080 + } + }, "env": [ { "name": "DATABASE_SERVICE_NAME", @@ -195,9 +211,9 @@ } ], "resources": { - "limits": { - "memory": "${MEMORY_LIMIT}" - } + "limits": { + "memory": "${MEMORY_LIMIT}" + } } } ] @@ -294,10 +310,24 @@ "value": "${DATABASE_NAME}" } ], + "readinessProbe": { + "timeoutSeconds": 1, + "initialDelaySeconds": 5, + "exec": { + "command": [ "/bin/sh", "-i", "-c", "psql -h 127.0.0.1 -U ${POSTGRESQL_USER} -q -d ${POSTGRESQL_DATABASE} -c 'SELECT 1'"] + } + }, + "livenessProbe": { + "timeoutSeconds": 1, + "initialDelaySeconds": 30, + "tcpSocket": { + "port": 5432 + } + }, "resources": { - "limits": { - "memory": "${MEMORY_POSTGRESQL_LIMIT}" - } + "limits": { + "memory": "${MEMORY_POSTGRESQL_LIMIT}" + } } } ] diff --git a/openshift/templates/django.json b/openshift/templates/django.json index 8936091..ee94e68 100644 --- a/openshift/templates/django.json +++ b/openshift/templates/django.json @@ -164,6 +164,22 @@ "containerPort": 8080 } ], + "readinessProbe": { + "timeoutSeconds": 3, + "initialDelaySeconds": 3, + "httpGet": { + "path": "/", + "port": 8080 + } + }, + "livenessProbe": { + "timeoutSeconds": 3, + "initialDelaySeconds": 30, + "httpGet": { + "path": "/", + "port": 8080 + } + }, "env": [ { "name": "DATABASE_SERVICE_NAME", diff --git a/project/urls.py b/project/urls.py index 63a356e..75017b9 100644 --- a/project/urls.py +++ b/project/urls.py @@ -7,5 +7,6 @@ urlpatterns = [ # url(r'^blog/', include('blog.urls')), url(r'^$', 'welcome.views.index'), + url(r'^health$', 'welcome.views.health'), url(r'^admin/', include(admin.site.urls)), ] diff --git a/welcome/views.py b/welcome/views.py index 1d89a66..5ab821b 100644 --- a/welcome/views.py +++ b/welcome/views.py @@ -1,6 +1,7 @@ import os from django.shortcuts import render from django.conf import settings +from django.http import HttpResponse from . import database from .models import PageView @@ -16,3 +17,6 @@ def index(request): 'database': database.info(), 'count': PageView.objects.count() }) + +def health(request): + return HttpResponse(PageView.objects.count())