Skript run-healthcheck.sh

Automaticky generovaná dokumentace skriptu scripts/run-healthcheck.sh.

 1#!/bin/bash
 2
 3ram_limit=95
 4
 5ram_utilization=$(free | awk '/Mem/{printf("%.2f"), $3/$2*100}')
 6rounded_ram_utilization=$(printf "%.0f" "$ram_utilization")
 7
 8if [ "$rounded_ram_utilization" -lt ${ram_limit} ]; then
 9  echo "RAM utilization is lower than ${ram_limit}% ($ram_utilization%)."
10  ram_status=0
11else
12  echo "RAM utilization is higher than or equal to ${ram_limit}% ($ram_utilization%)."
13  ram_status=1
14fi
15
16status_code="$(curl -s -L -o /dev/null -w '%{http_code}'  127.0.0.1:8001/healthcheck)"
17
18echo "HTTP status code from /healthcheck endpoint is ${status_code}"
19
20if [ -f "/run/secrets/db_conf" ]; then
21    file_path="/run/secrets/db_conf"
22else
23    file_path="/code/webclient/settings/sample_secrets_db.json"
24fi
25fedora_server_hostname=$(jq -r '.FEDORA_SERVER_HOSTNAME' "$file_path")
26fedora_server_name=$(jq -r '.FEDORA_SERVER_NAME' "$file_path")
27fedora_port_number=$(jq -r '.FEDORA_PORT_NUMBER' "$file_path")
28fedora_user=$(jq -r '.FEDORA_ADMIN_USER' "$file_path")
29fedora_user_password=$(jq -r '.FEDORA_ADMIN_USER_PASSWORD' "$file_path")
30fedora_protocol=$(jq -r '.FEDORA_PROTOCOL' "$file_path")
31
32url="${fedora_protocol}://${fedora_server_hostname}:${fedora_port_number}/rest/${fedora_server_name}"
33fedora_status_code=$(curl -o /dev/null -s -w "%{http_code}" -u "${fedora_user}":"${fedora_user_password}" "$url")
34echo "HTTP status code from FEDORA is ${fedora_status_code}"
35
36
37test "${status_code}" -eq "200" && test "${fedora_status_code}" -eq "200" && python /scripts/db/db_connection_from_docker-web.py && test ${ram_status} -eq 0 && true || false
38
39exit_code="$?"
40
41
42if [ ${exit_code} -eq 0 ] ; then
43    echo "Django application is running with RAM ${rounded_ram_utilization} %."
44    exit 0
45else
46    echo "Django application is not running or RAM limit exceeded or Fedora is not running."
47    exit 1
48fi