Skip to content

Commit

Permalink
Added ability to change location of configuration folder using TB_GW_…
Browse files Browse the repository at this point in the history
…CONFIG_DIR environmental variable
  • Loading branch information
imbeacon committed Nov 4, 2024
1 parent 6495820 commit f8ace46
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions thingsboard_gateway/tb_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from os import curdir, listdir, mkdir, path
from os import curdir, listdir, mkdir, path, environ

from thingsboard_gateway.gateway.tb_gateway_service import TBGatewayService
from thingsboard_gateway.gateway.hot_reloader import HotReloader


def main():
if "logs" not in listdir(curdir):
mkdir("logs")
Expand All @@ -30,11 +29,19 @@ def main():
if hot_reload:
HotReloader(TBGatewayService)
else:
TBGatewayService(path.dirname(path.abspath(__file__)) + '/config/tb_gateway.json'.replace('/', path.sep))
config_path = __get_config_path(path.dirname(path.abspath(__file__)) + '/config/'.replace('/', path.sep))
TBGatewayService(config_path + 'tb_gateway.json')


def daemon():
TBGatewayService("/etc/thingsboard-gateway/config/tb_gateway.json".replace('/', path.sep))
config_path = __get_config_path("/etc/thingsboard-gateway/config/".replace('/', path.sep))
TBGatewayService(config_path + "tb_gateway.json")

def __get_config_path(default_config_path):
config_path = environ.get("TB_GW_CONFIG_DIR", default_config_path)
if not config_path.endswith(path.sep):
config_path += path.sep
return config_path


if __name__ == '__main__':
Expand Down

0 comments on commit f8ace46

Please sign in to comment.