-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f00f26
commit a122003
Showing
4 changed files
with
95 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Ignore everything in this directory | ||
* | ||
|
||
# Whitelist these files | ||
!healthcheck.py | ||
!__init__.py |
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env python3 | ||
import os, yaml, subprocess; | ||
from opentakserver.defaultconfig import DefaultConfig; | ||
from flask.config import Config as FlaskConfig; | ||
|
||
config_file = os.path.join( os.environ.get("DOCKER_OTS_DATA_FOLDER", "/app/ots/"), "config.yml" ); | ||
config = FlaskConfig(config_file); | ||
|
||
def save_config(config): | ||
global config_file | ||
try: | ||
with open(config_file, "w") as config_file: | ||
yaml.safe_dump(dict(config), config_file) | ||
print("Container init | Saving config file...") | ||
except BaseException as e: | ||
print("Container init | Failed to save config.yml: {}".format(e)) | ||
|
||
# Get config file, | ||
# Load config.yml if it exists | ||
if not os.path.exists(config_file) or os.environ.get("DOCKER_CONFIG_OVERWRITE", False): | ||
print("Container init | Creating config.yml") | ||
|
||
# Get default config from opentakserver | ||
config.from_object(DefaultConfig); | ||
|
||
# Override settings to make OTS work in a container | ||
config.update( | ||
OTS_LISTENER_ADDRESS = os.environ.get("DOCKER_OTS_LISTENER_ADDRESS", "0.0.0.0"), | ||
OTS_RABBITMQ_SERVER_ADDRESS = os.environ.get("DOCKER_OTS_RABBITMQ_SERVER_ADDRESS", "rabbitmq") | ||
) | ||
|
||
# Get env variables with the prefix 'DOCKER_' | ||
# Used so we can override variables from the docker-compose file | ||
config.from_prefixed_env('DOCKER'); | ||
|
||
save_config(config) | ||
else: | ||
print('Container init | Found existing config.yml') | ||
|
||
print('Container init | Checking environment variables...') | ||
init_config_file = FlaskConfig(config_file) | ||
init_config_file.from_file(config_file, load=yaml.safe_load); | ||
|
||
init_config_env = FlaskConfig(config_file) | ||
init_config_env.from_prefixed_env('DOCKER'); | ||
|
||
init_config_diff = set(init_config_file).intersection(set(init_config_env)) | ||
|
||
if bool(init_config_diff): | ||
init_config_updated = dict() | ||
for value in init_config_diff: | ||
if init_config_file[value] != init_config_env[value]: | ||
print("Container init | Found changed environment variable ['{}'] old value: '{}' new value: '{}'".format(value, init_config_file[value], init_config_env[value])) | ||
init_config_updated[value] = init_config_env[value] | ||
|
||
if bool(init_config_updated): | ||
init_config_file.update(init_config_updated) | ||
save_config(init_config_file) | ||
else: | ||
print('Container init | No changed environment variables found') | ||
|
||
# Start the OpenTAKServer app | ||
print('Container init | Starting OpenTAKServer...') | ||
ots = subprocess.Popen( ['python3', '-m', 'opentakserver.app'], start_new_session=True) | ||
ots.wait() |
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,13 @@ | ||
import requests, sys; | ||
|
||
URL = "http://localhost:8081/api/health" | ||
|
||
try: | ||
response = requests.head(URL) | ||
except Exception as e:mak | ||
sys.exit(1) | ||
else: | ||
if response.status_code == 200: | ||
sys.exit(0) | ||
else: | ||
sys.exit(1) |