Skip to content

Commit

Permalink
Add new env vars for web api and validate minute replication files (#354
Browse files Browse the repository at this point in the history
)

* Set env vars for web container

* Update var names for rails - web container

* Update liveness for minute replication job

* Add env var for RAILS_ENV

* Add env for RAILS_LOG_LEVEL

* Add STORAGE env values for web
  • Loading branch information
Rub21 authored Jan 29, 2025
1 parent 702ddc6 commit 1f921c6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
43 changes: 39 additions & 4 deletions images/replication-job/liveness.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
#!/usr/bin/env bash
# This is a script for the complex evaluation of whether Osmosis or other processes are running in the container.
if [ $(ps -ef | grep -E 'java' | grep -v grep | wc -l) -ge 1 ]; then
# Script to check if Osmosis (Java) is running and also check how old processed_files.log is.
# If processed_files.log is older than MAX_AGE_MINUTES, then kill Osmosis.

LOG_FILE="/mnt/data/processed_files.log"
MAX_AGE_MINUTES=10

get_file_age_in_minutes() {
local file="$1"
if [ ! -f "$file" ]; then
echo 999999
return
fi
local now
local mtime
now=$(date +%s)
mtime=$(stat -c %Y "$file")
local diff=$(( (now - mtime) / 60 ))
echo "$diff"
}

# Check if Osmosis (Java) is running
OSMOSIS_COUNT=$(ps -ef | grep -E 'java.*osmosis' | grep -v grep | wc -l)

if [ "$OSMOSIS_COUNT" -ge 1 ]; then
echo "Osmosis is running."
exit 0
# Check how old the processed_files.log file is
file_age=$(get_file_age_in_minutes "$LOG_FILE")
echo "processed_files.log file age in minutes: $file_age"
if [ "$file_age" -ge "$MAX_AGE_MINUTES" ]; then
echo "processed_files.log is older than $MAX_AGE_MINUTES minutes. Attempting to kill Osmosis and restart the container..."
# Kill the Osmosis process
pkill -f "java.*osmosis" || true
echo "Osmosis is not terminating. Force-killing the container..."
echo "Container force-restart triggered."
exit 2
else
echo "processed_files.log is not too old. No action needed."
exit 0
fi
else
echo "Osmosis is not running!" 1>&2
echo "Osmosis is not running!"
exit 1
fi
14 changes: 14 additions & 0 deletions osm-seed/templates/web/web-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ spec:
# you done need to set this values.yaml in case you don't use
- name: BACKUP_FILE_URL
value: {{ .Values.web.env.BACKUP_FILE_URL | default "none" | quote }}
- name: RAILS_CREDENTIALS_YML_ENC
value: {{ .Values.web.env.RAILS_CREDENTIALS_YML_ENC | quote }}
- name: RAILS_MASTER_KEY
value: {{ .Values.web.env.RAILS_MASTER_KEY | quote }}
- name: RAILS_ENV
value: {{ .Values.web.env.RAILS_ENV | quote }}
- name: RAILS_LOG_LEVEL
value: {{ .Values.web.env.RAILS_LOG_LEVEL | default "info" | quote }}
- name: RAILS_STORAGE_SERVICE
value: {{ .Values.web.env.RAILS_STORAGE_SERVICE | default "local" | quote }}
- name: RAILS_STORAGE_REGION
value: {{ .Values.web.env.RAILS_STORAGE_REGION | quote }}
- name: RAILS_STORAGE_BUCKET
value: {{ .Values.web.env.RAILS_STORAGE_BUCKET | quote }}
volumeMounts:
- mountPath: /dev/shm
name: shared-memory
Expand Down
6 changes: 6 additions & 0 deletions osm-seed/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ web:
WEBSITE_STATUS: "online"
API_TIMEOUT: 30
WEB_TIMEOUT: 30
RAILS_MASTER_KEY: none
RAILS_CREDENTIALS_YML_ENC: none
RAILS_LOG_LEVEL: info
RAILS_STORAGE_SERVICE: local
RAILS_STORAGE_REGION: us-east-1
RAILS_STORAGE_BUCKET: osmseed-website-bucket
resources:
enabled: false
requests:
Expand Down

0 comments on commit 1f921c6

Please sign in to comment.