From 4a275cadbb0deeaca6abf7ff0d14725ad0c10463 Mon Sep 17 00:00:00 2001
From: David Huss <dh@atoav.com>
Date: Wed, 13 Jan 2021 11:25:26 +0100
Subject: [PATCH] Allow ENV to set config dir

---
 stechuhr-server.service   | 3 ++-
 stechuhr_server/config.py | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/stechuhr-server.service b/stechuhr-server.service
index d291875..16764ac 100644
--- a/stechuhr-server.service
+++ b/stechuhr-server.service
@@ -5,6 +5,8 @@ Before=nginx.service
 [Service]
 Type=simple
 User=wwwrun
+Environment="STECHUHR-SERVER_CONFIG_PATH=/etc/stechuhr-server/config.toml"
+WorkingDirectory=/srv/stechuhr-server
 ExecStart=/srv/stechuhr-server/env/bin/gunicorn stechuhr_server.server:app
 Restart=always
 RestartSec=30
@@ -13,7 +15,6 @@ PrivateTmp=yes
 ProtectSystem=full
 NoNewPrivileges=yes
 AmbientCapabilities=CAP_NET_BIND_SERVICE
-WorkingDirectory=/srv/stechuhr-server
 
 [Install]
 WantedBy=multi-user.target
diff --git a/stechuhr_server/config.py b/stechuhr_server/config.py
index 84a335a..27c3be3 100644
--- a/stechuhr_server/config.py
+++ b/stechuhr_server/config.py
@@ -90,6 +90,10 @@ def initialize_config(application_name: str, default_config: str, app) -> dict:
             exit(1)
         app.logger.info("Read config from: {}".format(config_path))
 
+        # Log info about environment variable if not set
+        if os.environ.get(config_path_environment_variable) is None:
+            app.logger.info("Override config path by setting the Environment variable {}=".format(config_path_environment_variable))
+
     return config
 
 def config_has_missing_keys(config, default_config, default_strconfig, app) -> bool:
-- 
GitLab