[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [sbws/master] Change configuration path when running supervised



commit 3d31263ba5bde4c7265b02663bfbcb08cfbfb592
Author: juga0 <juga@xxxxxxxxxx>
Date:   Wed Oct 31 19:43:40 2018 +0000

    Change configuration path when running supervised
---
 sbws/globals.py     |  2 +-
 sbws/util/config.py | 14 +++++++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/sbws/globals.py b/sbws/globals.py
index 5dd644e..cadd473 100644
--- a/sbws/globals.py
+++ b/sbws/globals.py
@@ -27,7 +27,7 @@ PKG_DIR = os.path.abspath(os.path.dirname(__file__))
 DEFAULT_CONFIG_PATH = os.path.join(PKG_DIR, 'config.default.ini')
 DEFAULT_LOG_CONFIG_PATH = os.path.join(PKG_DIR, 'config.log.default.ini')
 USER_CONFIG_PATH = os.path.join(os.path.expanduser('~'), '.sbws.ini')
-
+SUPERVISED_USER_CONFIG_PATH = "/etc/sbws/sbws.ini"
 SUPERVISED_RUN_DPATH = "/run/sbws/tor"
 
 SOCKET_TIMEOUT = 60  # seconds
diff --git a/sbws/util/config.py b/sbws/util/config.py
index 2f6fa51..0981b6d 100644
--- a/sbws/util/config.py
+++ b/sbws/util/config.py
@@ -9,7 +9,8 @@ from urllib.parse import urlparse
 from string import Template
 from tempfile import NamedTemporaryFile
 from sbws.globals import (DEFAULT_CONFIG_PATH, DEFAULT_LOG_CONFIG_PATH,
-                          USER_CONFIG_PATH, SUPERVISED_RUN_DPATH, fail_hard)
+                          USER_CONFIG_PATH, SUPERVISED_RUN_DPATH,
+                          SUPERVISED_USER_CONFIG_PATH, fail_hard)
 
 _ALPHANUM = 'abcdefghijklmnopqrstuvwxyz'
 _ALPHANUM += _ALPHANUM.upper()
@@ -47,6 +48,12 @@ def _get_default_config():
     return _extend_config(conf, DEFAULT_CONFIG_PATH)
 
 
+def _obtain_user_conf_path():
+    if os.environ.get("SUPERVISED") == "1":
+        return SUPERVISED_USER_CONFIG_PATH
+    return USER_CONFIG_PATH
+
+
 def _get_user_config(args, conf=None):
     """Get user configuration.
     Search for user configuration in the default path or the path passed as
@@ -61,8 +68,9 @@ def _get_user_config(args, conf=None):
         if not os.path.isfile(args.config):
             fail_hard('Configuration file %s not found.', args.config)
         return _extend_config(conf, args.config)
-    if os.path.isfile(USER_CONFIG_PATH):
-        return _extend_config(conf, USER_CONFIG_PATH)
+    user_config_path = _obtain_user_conf_path()
+    if os.path.isfile(user_config_path):
+        return _extend_config(conf, user_config_path)
     log.debug('No user config found.')
     return conf
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits