forked from openshift-instruqt/blog-django-py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add readiness and liveness probe scripts.
- Loading branch information
1 parent
66db496
commit 620e910
Showing
6 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ dj_database_url | |
mod_wsgi | ||
Pillow | ||
psycopg2 | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
set -eo pipefail | ||
|
||
HERE=`dirname $0` | ||
|
||
ready() { | ||
echo " -----> Starting liveness script." | ||
|
||
# Check web server. | ||
|
||
echo " -----> Checking server is working." | ||
|
||
python $HERE/check-server.py | ||
|
||
# Check database. | ||
|
||
echo " -----> Checking database is working." | ||
|
||
if [ x"$DATABASE_URL" != x"" ]; then | ||
(cat - | python manage.py shell --plain) << ! | ||
import runpy | ||
_ = runpy.run_path('$HERE/check-database.py') | ||
! | ||
fi | ||
|
||
echo " -----> Stopping liveness script." | ||
} | ||
|
||
ready 2>&1 | tee -a /proc/1/fd/1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from __future__ import print_function | ||
|
||
import sys | ||
import time | ||
|
||
import django | ||
|
||
django.setup() | ||
|
||
from django.db import connection | ||
|
||
remaining = 600.0 | ||
delay = 2.0 | ||
|
||
success = False | ||
|
||
while remaining > 0.0: | ||
try: | ||
print('Check whether database is ready...') | ||
cursor = connection.cursor() | ||
with cursor: | ||
cursor.execute('SELECT 1') | ||
cursor.fetchall() | ||
|
||
success = True | ||
|
||
break | ||
|
||
except Exception: | ||
pass | ||
|
||
time.sleep(delay) | ||
|
||
if not success: | ||
print('Failed to connect to database') | ||
|
||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import os | ||
import requests | ||
|
||
hostname = os.environ['HOSTNAME'] | ||
|
||
response = requests.get('http://%s:8080/' % hostname) | ||
response.raise_for_status() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
set -eo pipefail | ||
|
||
HERE=`dirname $0` | ||
|
||
ready() { | ||
echo " -----> Starting readiness script." | ||
|
||
# Check web server. | ||
|
||
echo " -----> Checking server is working." | ||
|
||
python $HERE/check-server.py | ||
|
||
# Check database. | ||
|
||
echo " -----> Checking database is working." | ||
|
||
if [ x"$DATABASE_URL" != x"" ]; then | ||
(cat - | python manage.py shell --plain) << ! | ||
import runpy | ||
_ = runpy.run_path('$HERE/check-database.py') | ||
! | ||
fi | ||
|
||
echo " -----> Stopping readiness script." | ||
} | ||
|
||
ready 2>&1 | tee -a /proc/1/fd/1 |